diff --git a/WebGames-master/WebGames-master/assets/n-gon.png b/WebGames-master/WebGames-master/assets/n-gon.png new file mode 100644 index 00000000..1597569c Binary files /dev/null and b/WebGames-master/WebGames-master/assets/n-gon.png differ diff --git a/WebGames-master/WebGames-master/n-gon-master/.gitignore b/WebGames-master/WebGames-master/n-gon-master/.gitignore new file mode 100644 index 00000000..ef23d46d --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/.gitignore @@ -0,0 +1,6 @@ + +.jsbeautifyrc +.DS_Store +.DS_Store +.DS_Store +js/workspace.code-workspace diff --git a/WebGames-master/WebGames-master/n-gon-master/LICENSE b/WebGames-master/WebGames-master/n-gon-master/LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/WebGames-master/WebGames-master/n-gon-master/README.md b/WebGames-master/WebGames-master/n-gon-master/README.md new file mode 100644 index 00000000..e2b8697c --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/README.md @@ -0,0 +1,3 @@ +2-d physics rogue-lite platformer shooter + +https://landgreen.github.io/n-gon/ diff --git a/WebGames-master/WebGames-master/n-gon-master/favicon.ico b/WebGames-master/WebGames-master/n-gon-master/favicon.ico new file mode 100644 index 00000000..ce083ff5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/favicon.ico differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/1s half-life.webp b/WebGames-master/WebGames-master/n-gon-master/img/1s half-life.webp new file mode 100644 index 00000000..e6e39192 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/1s half-life.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/1st ionization energy.webp b/WebGames-master/WebGames-master/n-gon-master/img/1st ionization energy.webp new file mode 100644 index 00000000..78906ed2 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/1st ionization energy.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/6s half-life.webp b/WebGames-master/WebGames-master/n-gon-master/img/6s half-life.webp new file mode 100644 index 00000000..5ecd2c37 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/6s half-life.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Abelian group.webp b/WebGames-master/WebGames-master/n-gon-master/img/Abelian group.webp new file mode 100644 index 00000000..916f9551 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Abelian group.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Bayesian statistics.webp b/WebGames-master/WebGames-master/n-gon-master/img/Bayesian statistics.webp new file mode 100644 index 00000000..8dd3651f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Bayesian statistics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Bessemer process.webp b/WebGames-master/WebGames-master/n-gon-master/img/Bessemer process.webp new file mode 100644 index 00000000..bca9b045 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Bessemer process.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Bitter electromagnet.webp b/WebGames-master/WebGames-master/n-gon-master/img/Bitter electromagnet.webp new file mode 100644 index 00000000..9d325d36 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Bitter electromagnet.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Born rule.webp b/WebGames-master/WebGames-master/n-gon-master/img/Born rule.webp new file mode 100644 index 00000000..dac853bf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Born rule.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/CIWS.webp b/WebGames-master/WebGames-master/n-gon-master/img/CIWS.webp new file mode 100644 index 00000000..2033c20d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/CIWS.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/CPT symmetry.webp b/WebGames-master/WebGames-master/n-gon-master/img/CPT symmetry.webp new file mode 100644 index 00000000..f28d0b17 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/CPT symmetry.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Gibbs free energy.webp b/WebGames-master/WebGames-master/n-gon-master/img/Gibbs free energy.webp new file mode 100644 index 00000000..b4b03d3d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Gibbs free energy.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Halbach array.webp b/WebGames-master/WebGames-master/n-gon-master/img/Halbach array.webp new file mode 100644 index 00000000..5d166c38 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Halbach array.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Higgs mechanism.webp b/WebGames-master/WebGames-master/n-gon-master/img/Higgs mechanism.webp new file mode 100644 index 00000000..26ede450 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Higgs mechanism.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Hilbert space.webp b/WebGames-master/WebGames-master/n-gon-master/img/Hilbert space.webp new file mode 100644 index 00000000..b772ad80 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Hilbert space.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ICBM.webp b/WebGames-master/WebGames-master/n-gon-master/img/ICBM.webp new file mode 100644 index 00000000..ac2f753e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ICBM.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/K-selection.webp b/WebGames-master/WebGames-master/n-gon-master/img/K-selection.webp new file mode 100644 index 00000000..595519aa Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/K-selection.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Lorentz transformation.webp b/WebGames-master/WebGames-master/n-gon-master/img/Lorentz transformation.webp new file mode 100644 index 00000000..c7c52e8a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Lorentz transformation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/MACHO.webp b/WebGames-master/WebGames-master/n-gon-master/img/MACHO.webp new file mode 100644 index 00000000..0875e673 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/MACHO.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/MIRV.webp b/WebGames-master/WebGames-master/n-gon-master/img/MIRV.webp new file mode 100644 index 00000000..32db2961 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/MIRV.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/MOND.webp b/WebGames-master/WebGames-master/n-gon-master/img/MOND.webp new file mode 100644 index 00000000..53a447a0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/MOND.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Maxwells demon.webp b/WebGames-master/WebGames-master/n-gon-master/img/Maxwells demon.webp new file mode 100644 index 00000000..9152cad7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Maxwells demon.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Meissner effect.webp b/WebGames-master/WebGames-master/n-gon-master/img/Meissner effect.webp new file mode 100644 index 00000000..329bc13e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Meissner effect.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Monte Carlo method.webp b/WebGames-master/WebGames-master/n-gon-master/img/Monte Carlo method.webp new file mode 100644 index 00000000..017fb090 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Monte Carlo method.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/NAND gate.webp b/WebGames-master/WebGames-master/n-gon-master/img/NAND gate.webp new file mode 100644 index 00000000..0525c8ba Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/NAND gate.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/NOR gate.webp b/WebGames-master/WebGames-master/n-gon-master/img/NOR gate.webp new file mode 100644 index 00000000..bd71ef30 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/NOR gate.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Newtons 1st law.webp b/WebGames-master/WebGames-master/n-gon-master/img/Newtons 1st law.webp new file mode 100644 index 00000000..02ac9b67 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Newtons 1st law.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Newtons 2nd law.webp b/WebGames-master/WebGames-master/n-gon-master/img/Newtons 2nd law.webp new file mode 100644 index 00000000..9e173548 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Newtons 2nd law.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Newtons 3rd law.webp b/WebGames-master/WebGames-master/n-gon-master/img/Newtons 3rd law.webp new file mode 100644 index 00000000..ad9c801c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Newtons 3rd law.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Noether violation.webp b/WebGames-master/WebGames-master/n-gon-master/img/Noether violation.webp new file mode 100644 index 00000000..b3c6797f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Noether violation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Occams razor.webp b/WebGames-master/WebGames-master/n-gon-master/img/Occams razor.webp new file mode 100644 index 00000000..cf6a4d39 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Occams razor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Pareto efficiency.webp b/WebGames-master/WebGames-master/n-gon-master/img/Pareto efficiency.webp new file mode 100644 index 00000000..e8d661dd Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Pareto efficiency.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Pauli exclusion.webp b/WebGames-master/WebGames-master/n-gon-master/img/Pauli exclusion.webp new file mode 100644 index 00000000..589abb58 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Pauli exclusion.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/UHMWPE.webp b/WebGames-master/WebGames-master/n-gon-master/img/UHMWPE.webp new file mode 100644 index 00000000..b893961f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/UHMWPE.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Verlet integration.webp b/WebGames-master/WebGames-master/n-gon-master/img/Verlet integration.webp new file mode 100644 index 00000000..733638bf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Verlet integration.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/WIMPs.webp b/WebGames-master/WebGames-master/n-gon-master/img/WIMPs.webp new file mode 100644 index 00000000..66ba2fbf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/WIMPs.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Zectron.webp b/WebGames-master/WebGames-master/n-gon-master/img/Zectron.webp new file mode 100644 index 00000000..89ebe0f0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Zectron.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Zenos paradox.webp b/WebGames-master/WebGames-master/n-gon-master/img/Zenos paradox.webp new file mode 100644 index 00000000..c3284964 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Zenos paradox.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/abiogenesis.webp b/WebGames-master/WebGames-master/n-gon-master/img/abiogenesis.webp new file mode 100644 index 00000000..082de302 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/abiogenesis.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ablative drones.webp b/WebGames-master/WebGames-master/n-gon-master/img/ablative drones.webp new file mode 100644 index 00000000..78f4c4a9 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ablative drones.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/accretion disk.webp b/WebGames-master/WebGames-master/n-gon-master/img/accretion disk.webp new file mode 100644 index 00000000..d8a6013c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/accretion disk.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/accretion.webp b/WebGames-master/WebGames-master/n-gon-master/img/accretion.webp new file mode 100644 index 00000000..6a7fc452 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/accretion.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/acetone peroxide.webp b/WebGames-master/WebGames-master/n-gon-master/img/acetone peroxide.webp new file mode 100644 index 00000000..71847e6f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/acetone peroxide.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/active cooling.webp b/WebGames-master/WebGames-master/n-gon-master/img/active cooling.webp new file mode 100644 index 00000000..a264fa1c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/active cooling.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ad hoc.webp b/WebGames-master/WebGames-master/n-gon-master/img/ad hoc.webp new file mode 100644 index 00000000..44a62e35 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ad hoc.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/additive manufacturing.webp b/WebGames-master/WebGames-master/n-gon-master/img/additive manufacturing.webp new file mode 100644 index 00000000..3a7b15a8 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/additive manufacturing.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/adiabatic healing.webp b/WebGames-master/WebGames-master/n-gon-master/img/adiabatic healing.webp new file mode 100644 index 00000000..0e253591 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/adiabatic healing.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/aerogel.webp b/WebGames-master/WebGames-master/n-gon-master/img/aerogel.webp new file mode 100644 index 00000000..597078b8 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/aerogel.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/aerostat.webp b/WebGames-master/WebGames-master/n-gon-master/img/aerostat.webp new file mode 100644 index 00000000..2e2077f9 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/aerostat.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/affine connection.webp b/WebGames-master/WebGames-master/n-gon-master/img/affine connection.webp new file mode 100644 index 00000000..fb05fd09 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/affine connection.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/alternator.webp b/WebGames-master/WebGames-master/n-gon-master/img/alternator.webp new file mode 100644 index 00000000..ef2098d0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/alternator.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ammo.webp b/WebGames-master/WebGames-master/n-gon-master/img/ammo.webp new file mode 100644 index 00000000..782d63d5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ammo.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ammonium nitrate.webp b/WebGames-master/WebGames-master/n-gon-master/img/ammonium nitrate.webp new file mode 100644 index 00000000..77f2c096 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ammonium nitrate.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/amplitude.webp b/WebGames-master/WebGames-master/n-gon-master/img/amplitude.webp new file mode 100644 index 00000000..202f93d4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/amplitude.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/annihilation.webp b/WebGames-master/WebGames-master/n-gon-master/img/annihilation.webp new file mode 100644 index 00000000..4a37c35b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/annihilation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ansatz.webp b/WebGames-master/WebGames-master/n-gon-master/img/ansatz.webp new file mode 100644 index 00000000..3b9a4d78 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ansatz.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/anthropic principle.webp b/WebGames-master/WebGames-master/n-gon-master/img/anthropic principle.webp new file mode 100644 index 00000000..28035f9a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/anthropic principle.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/anti-shear topology.webp b/WebGames-master/WebGames-master/n-gon-master/img/anti-shear topology.webp new file mode 100644 index 00000000..61dcda6e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/anti-shear topology.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/anticorrelation.webp b/WebGames-master/WebGames-master/n-gon-master/img/anticorrelation.webp new file mode 100644 index 00000000..2d6a05ed Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/anticorrelation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/antiscience.webp b/WebGames-master/WebGames-master/n-gon-master/img/antiscience.webp new file mode 100644 index 00000000..057e650a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/antiscience.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/anyon.webp b/WebGames-master/WebGames-master/n-gon-master/img/anyon.webp new file mode 100644 index 00000000..3f88a63f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/anyon.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/aperture.webp b/WebGames-master/WebGames-master/n-gon-master/img/aperture.webp new file mode 100644 index 00000000..01c9e7da Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/aperture.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/apomixis.webp b/WebGames-master/WebGames-master/n-gon-master/img/apomixis.webp new file mode 100644 index 00000000..1aa7128a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/apomixis.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/applied science.webp b/WebGames-master/WebGames-master/n-gon-master/img/applied science.webp new file mode 100644 index 00000000..aecde798 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/applied science.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/arsenal.webp b/WebGames-master/WebGames-master/n-gon-master/img/arsenal.webp new file mode 100644 index 00000000..3a22e858 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/arsenal.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/autocannon.webp b/WebGames-master/WebGames-master/n-gon-master/img/autocannon.webp new file mode 100644 index 00000000..c8823d13 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/autocannon.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/autonomous defense.webp b/WebGames-master/WebGames-master/n-gon-master/img/autonomous defense.webp new file mode 100644 index 00000000..3065ae8a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/autonomous defense.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/axial flux motor.webp b/WebGames-master/WebGames-master/n-gon-master/img/axial flux motor.webp new file mode 100644 index 00000000..a178c525 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/axial flux motor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/axion.webp b/WebGames-master/WebGames-master/n-gon-master/img/axion.webp new file mode 100644 index 00000000..3e79c125 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/axion.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/band gap.webp b/WebGames-master/WebGames-master/n-gon-master/img/band gap.webp new file mode 100644 index 00000000..0427cd4a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/band gap.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/beta radiation.webp b/WebGames-master/WebGames-master/n-gon-master/img/beta radiation.webp new file mode 100644 index 00000000..24970c63 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/beta radiation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/blast ball.webp b/WebGames-master/WebGames-master/n-gon-master/img/blast ball.webp new file mode 100644 index 00000000..b7164665 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/blast ball.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/booby trap.webp b/WebGames-master/WebGames-master/n-gon-master/img/booby trap.webp new file mode 100644 index 00000000..ea063523 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/booby trap.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/boom-bot upgrade.webp b/WebGames-master/WebGames-master/n-gon-master/img/boom-bot upgrade.webp new file mode 100644 index 00000000..127b91d5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/boom-bot upgrade.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/boom-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/boom-bot.webp new file mode 100644 index 00000000..76ee2fd3 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/boom-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/boson composite.webp b/WebGames-master/WebGames-master/n-gon-master/img/boson composite.webp new file mode 100644 index 00000000..18fb1ecf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/boson composite.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/bot fabrication.webp b/WebGames-master/WebGames-master/n-gon-master/img/bot fabrication.webp new file mode 100644 index 00000000..8e4efae0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/bot fabrication.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/bot manufacturing.webp b/WebGames-master/WebGames-master/n-gon-master/img/bot manufacturing.webp new file mode 100644 index 00000000..930875f7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/bot manufacturing.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/bot prototypes.webp b/WebGames-master/WebGames-master/n-gon-master/img/bot prototypes.webp new file mode 100644 index 00000000..431a668e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/bot prototypes.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/bound state.webp b/WebGames-master/WebGames-master/n-gon-master/img/bound state.webp new file mode 100644 index 00000000..f134f44d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/bound state.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/brainstorming.webp b/WebGames-master/WebGames-master/n-gon-master/img/brainstorming.webp new file mode 100644 index 00000000..d7d327f9 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/brainstorming.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/bremsstrahlung.webp b/WebGames-master/WebGames-master/n-gon-master/img/bremsstrahlung.webp new file mode 100644 index 00000000..d7fe0fcd Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/bremsstrahlung.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/brittle.webp b/WebGames-master/WebGames-master/n-gon-master/img/brittle.webp new file mode 100644 index 00000000..85dd2fe0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/brittle.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/brushless motor.webp b/WebGames-master/WebGames-master/n-gon-master/img/brushless motor.webp new file mode 100644 index 00000000..7ad17531 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/brushless motor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/bubble fusion.webp b/WebGames-master/WebGames-master/n-gon-master/img/bubble fusion.webp new file mode 100644 index 00000000..c45a1798 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/bubble fusion.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/buckling.webp b/WebGames-master/WebGames-master/n-gon-master/img/buckling.webp new file mode 100644 index 00000000..17f10fe1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/buckling.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cache.webp b/WebGames-master/WebGames-master/n-gon-master/img/cache.webp new file mode 100644 index 00000000..d0dcbdcf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cache.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/capacitor bank.webp b/WebGames-master/WebGames-master/n-gon-master/img/capacitor bank.webp new file mode 100644 index 00000000..2f631d63 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/capacitor bank.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cascading failure.webp b/WebGames-master/WebGames-master/n-gon-master/img/cascading failure.webp new file mode 100644 index 00000000..443206ed Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cascading failure.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/catabolism.webp b/WebGames-master/WebGames-master/n-gon-master/img/catabolism.webp new file mode 100644 index 00000000..3fbfea31 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/catabolism.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/causality bombs.webp b/WebGames-master/WebGames-master/n-gon-master/img/causality bombs.webp new file mode 100644 index 00000000..2b789961 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/causality bombs.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/causality bots.webp b/WebGames-master/WebGames-master/n-gon-master/img/causality bots.webp new file mode 100644 index 00000000..333ece1f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/causality bots.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cavitation.webp b/WebGames-master/WebGames-master/n-gon-master/img/cavitation.webp new file mode 100644 index 00000000..332ec5a4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cavitation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ceramics.webp b/WebGames-master/WebGames-master/n-gon-master/img/ceramics.webp new file mode 100644 index 00000000..ca6c1770 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ceramics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/chain reaction.webp b/WebGames-master/WebGames-master/n-gon-master/img/chain reaction.webp new file mode 100644 index 00000000..d2a54486 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/chain reaction.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cherenkov radiation.webp b/WebGames-master/WebGames-master/n-gon-master/img/cherenkov radiation.webp new file mode 100644 index 00000000..23c62968 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cherenkov radiation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/clock gating.webp b/WebGames-master/WebGames-master/n-gon-master/img/clock gating.webp new file mode 100644 index 00000000..03bdc913 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/clock gating.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/coherence.webp b/WebGames-master/WebGames-master/n-gon-master/img/coherence.webp new file mode 100644 index 00000000..c433b176 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/coherence.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/collider.webp b/WebGames-master/WebGames-master/n-gon-master/img/collider.webp new file mode 100644 index 00000000..ef6c55f0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/collider.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/colony.webp b/WebGames-master/WebGames-master/n-gon-master/img/colony.webp new file mode 100644 index 00000000..c572b6e7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/colony.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/combinatorial optimization.webp b/WebGames-master/WebGames-master/n-gon-master/img/combinatorial optimization.webp new file mode 100644 index 00000000..dc22e75b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/combinatorial optimization.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/commodities exchange.webp b/WebGames-master/WebGames-master/n-gon-master/img/commodities exchange.webp new file mode 100644 index 00000000..edad9af5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/commodities exchange.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/compound lens.webp b/WebGames-master/WebGames-master/n-gon-master/img/compound lens.webp new file mode 100644 index 00000000..1357aefc Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/compound lens.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/control theory.webp b/WebGames-master/WebGames-master/n-gon-master/img/control theory.webp new file mode 100644 index 00000000..2843288c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/control theory.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cordyceps.webp b/WebGames-master/WebGames-master/n-gon-master/img/cordyceps.webp new file mode 100644 index 00000000..14497808 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cordyceps.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/corona discharge.webp b/WebGames-master/WebGames-master/n-gon-master/img/corona discharge.webp new file mode 100644 index 00000000..4c3bb589 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/corona discharge.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/correlated damage.webp b/WebGames-master/WebGames-master/n-gon-master/img/correlated damage.webp new file mode 100644 index 00000000..cd93b2cd Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/correlated damage.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cosmic string.webp b/WebGames-master/WebGames-master/n-gon-master/img/cosmic string.webp new file mode 100644 index 00000000..51338ebf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cosmic string.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cross-disciplinary.webp b/WebGames-master/WebGames-master/n-gon-master/img/cross-disciplinary.webp new file mode 100644 index 00000000..31c94f40 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cross-disciplinary.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cruise missile.webp b/WebGames-master/WebGames-master/n-gon-master/img/cruise missile.webp new file mode 100644 index 00000000..d1e9e449 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cruise missile.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/cryodesiccation.webp b/WebGames-master/WebGames-master/n-gon-master/img/cryodesiccation.webp new file mode 100644 index 00000000..f36e2726 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/cryodesiccation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/crystallizer.webp b/WebGames-master/WebGames-master/n-gon-master/img/crystallizer.webp new file mode 100644 index 00000000..8539db92 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/crystallizer.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dark energy.webp b/WebGames-master/WebGames-master/n-gon-master/img/dark energy.webp new file mode 100644 index 00000000..faca967e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dark energy.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dark matter.webp b/WebGames-master/WebGames-master/n-gon-master/img/dark matter.webp new file mode 100644 index 00000000..8570ee05 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dark matter.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dark patterns.webp b/WebGames-master/WebGames-master/n-gon-master/img/dark patterns.webp new file mode 100644 index 00000000..f147c9ed Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dark patterns.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dark star.webp b/WebGames-master/WebGames-master/n-gon-master/img/dark star.webp new file mode 100644 index 00000000..ca23c349 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dark star.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dazzler.webp b/WebGames-master/WebGames-master/n-gon-master/img/dazzler.webp new file mode 100644 index 00000000..2cdb34fd Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dazzler.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dead reckoning.webp b/WebGames-master/WebGames-master/n-gon-master/img/dead reckoning.webp new file mode 100644 index 00000000..05e9abff Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dead reckoning.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/decoherence.webp b/WebGames-master/WebGames-master/n-gon-master/img/decoherence.webp new file mode 100644 index 00000000..82b46502 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/decoherence.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/decorrelation.webp b/WebGames-master/WebGames-master/n-gon-master/img/decorrelation.webp new file mode 100644 index 00000000..8abd9424 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/decorrelation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/decoupling.webp b/WebGames-master/WebGames-master/n-gon-master/img/decoupling.webp new file mode 100644 index 00000000..6776cc33 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/decoupling.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/degenerate matter.webp b/WebGames-master/WebGames-master/n-gon-master/img/degenerate matter.webp new file mode 100644 index 00000000..de582167 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/degenerate matter.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/delayed-choice.webp b/WebGames-master/WebGames-master/n-gon-master/img/delayed-choice.webp new file mode 100644 index 00000000..8f98107e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/delayed-choice.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/delivery drone.webp b/WebGames-master/WebGames-master/n-gon-master/img/delivery drone.webp new file mode 100644 index 00000000..91c74779 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/delivery drone.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/depolarization.webp b/WebGames-master/WebGames-master/n-gon-master/img/depolarization.webp new file mode 100644 index 00000000..1ff8484a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/depolarization.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/deprecated.webp b/WebGames-master/WebGames-master/n-gon-master/img/deprecated.webp new file mode 100644 index 00000000..8ef13875 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/deprecated.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/desublimated ammunition.webp b/WebGames-master/WebGames-master/n-gon-master/img/desublimated ammunition.webp new file mode 100644 index 00000000..541e2a1d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/desublimated ammunition.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/determinism.webp b/WebGames-master/WebGames-master/n-gon-master/img/determinism.webp new file mode 100644 index 00000000..02b07fb4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/determinism.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/diaphragm.webp b/WebGames-master/WebGames-master/n-gon-master/img/diaphragm.webp new file mode 100644 index 00000000..10a8bc21 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/diaphragm.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/diffraction grating.webp b/WebGames-master/WebGames-master/n-gon-master/img/diffraction grating.webp new file mode 100644 index 00000000..53fed27a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/diffraction grating.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/diffuse beam.webp b/WebGames-master/WebGames-master/n-gon-master/img/diffuse beam.webp new file mode 100644 index 00000000..54027930 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/diffuse beam.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/drone repair.webp b/WebGames-master/WebGames-master/n-gon-master/img/drone repair.webp new file mode 100644 index 00000000..bc4ee461 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/drone repair.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dye laser.webp b/WebGames-master/WebGames-master/n-gon-master/img/dye laser.webp new file mode 100644 index 00000000..3a9cf69d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dye laser.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dynamic equilibrium.webp b/WebGames-master/WebGames-master/n-gon-master/img/dynamic equilibrium.webp new file mode 100644 index 00000000..c26522bd Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dynamic equilibrium.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dynamical systems.webp b/WebGames-master/WebGames-master/n-gon-master/img/dynamical systems.webp new file mode 100644 index 00000000..141e818b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dynamical systems.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dynamo-bot upgrade.webp b/WebGames-master/WebGames-master/n-gon-master/img/dynamo-bot upgrade.webp new file mode 100644 index 00000000..15b3d618 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dynamo-bot upgrade.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/dynamo-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/dynamo-bot.webp new file mode 100644 index 00000000..71f5d05f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/dynamo-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/eddy current brake.webp b/WebGames-master/WebGames-master/n-gon-master/img/eddy current brake.webp new file mode 100644 index 00000000..9d95e5ad Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/eddy current brake.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/electric armor.webp b/WebGames-master/WebGames-master/n-gon-master/img/electric armor.webp new file mode 100644 index 00000000..2ee7dc0b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/electric armor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/electric generator.webp b/WebGames-master/WebGames-master/n-gon-master/img/electric generator.webp new file mode 100644 index 00000000..9c23ad3f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/electric generator.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/electronegativity.webp b/WebGames-master/WebGames-master/n-gon-master/img/electronegativity.webp new file mode 100644 index 00000000..4df69cd6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/electronegativity.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/electrostatic induction.webp b/WebGames-master/WebGames-master/n-gon-master/img/electrostatic induction.webp new file mode 100644 index 00000000..3cc3bf38 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/electrostatic induction.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/elephants toothpaste.webp b/WebGames-master/WebGames-master/n-gon-master/img/elephants toothpaste.webp new file mode 100644 index 00000000..3e945973 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/elephants toothpaste.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/emergence.webp b/WebGames-master/WebGames-master/n-gon-master/img/emergence.webp new file mode 100644 index 00000000..f7d87e08 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/emergence.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/energy conservation.webp b/WebGames-master/WebGames-master/n-gon-master/img/energy conservation.webp new file mode 100644 index 00000000..e825adb7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/energy conservation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/enthalpy.webp b/WebGames-master/WebGames-master/n-gon-master/img/enthalpy.webp new file mode 100644 index 00000000..761e8f8f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/enthalpy.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/entropic gravity.webp b/WebGames-master/WebGames-master/n-gon-master/img/entropic gravity.webp new file mode 100644 index 00000000..339af23d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/entropic gravity.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ergodicity.webp b/WebGames-master/WebGames-master/n-gon-master/img/ergodicity.webp new file mode 100644 index 00000000..969e577d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ergodicity.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ersatz bots.webp b/WebGames-master/WebGames-master/n-gon-master/img/ersatz bots.webp new file mode 100644 index 00000000..3074c078 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ersatz bots.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/eternalism.webp b/WebGames-master/WebGames-master/n-gon-master/img/eternalism.webp new file mode 100644 index 00000000..08df1eaa Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/eternalism.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/exchange symmetry.webp b/WebGames-master/WebGames-master/n-gon-master/img/exchange symmetry.webp new file mode 100644 index 00000000..15a2c097 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/exchange symmetry.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/exciton.webp b/WebGames-master/WebGames-master/n-gon-master/img/exciton.webp new file mode 100644 index 00000000..d6a99ba2 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/exciton.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/exothermic process.webp b/WebGames-master/WebGames-master/n-gon-master/img/exothermic process.webp new file mode 100644 index 00000000..3d790088 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/exothermic process.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/expansion.webp b/WebGames-master/WebGames-master/n-gon-master/img/expansion.webp new file mode 100644 index 00000000..0a0bf977 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/expansion.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/extended magazine.webp b/WebGames-master/WebGames-master/n-gon-master/img/extended magazine.webp new file mode 100644 index 00000000..f3507c3f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/extended magazine.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/externality.webp b/WebGames-master/WebGames-master/n-gon-master/img/externality.webp new file mode 100644 index 00000000..69fda3a5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/externality.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/extruder.webp b/WebGames-master/WebGames-master/n-gon-master/img/extruder.webp new file mode 100644 index 00000000..52021429 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/extruder.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/fault tolerance.webp b/WebGames-master/WebGames-master/n-gon-master/img/fault tolerance.webp new file mode 100644 index 00000000..359b3920 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/fault tolerance.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/fermion.webp b/WebGames-master/WebGames-master/n-gon-master/img/fermion.webp new file mode 100644 index 00000000..0de0dab6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/fermion.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field coupling.webp b/WebGames-master/WebGames-master/n-gon-master/img/field coupling.webp new file mode 100644 index 00000000..06376a91 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field coupling.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter0.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter0.webp new file mode 100644 index 00000000..d6a9f989 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter0.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter1.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter1.webp new file mode 100644 index 00000000..8451986c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter1.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter10.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter10.webp new file mode 100644 index 00000000..46bdc8d3 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter10.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter11.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter11.webp new file mode 100644 index 00000000..d5f4beda Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter11.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter12.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter12.webp new file mode 100644 index 00000000..4452eb32 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter12.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter13.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter13.webp new file mode 100644 index 00000000..cea1f4f8 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter13.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter14.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter14.webp new file mode 100644 index 00000000..20dde97d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter14.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter15.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter15.webp new file mode 100644 index 00000000..10e73064 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter15.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter16.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter16.webp new file mode 100644 index 00000000..21912d14 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter16.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter17.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter17.webp new file mode 100644 index 00000000..96d8dc41 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter17.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter18.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter18.webp new file mode 100644 index 00000000..532b8edf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter18.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter19.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter19.webp new file mode 100644 index 00000000..98206f53 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter19.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter2.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter2.webp new file mode 100644 index 00000000..e6ac3509 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter2.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter20.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter20.webp new file mode 100644 index 00000000..58e0cd77 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter20.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter21.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter21.webp new file mode 100644 index 00000000..2c1ba1da Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter21.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter22.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter22.webp new file mode 100644 index 00000000..9c0e8a1f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter22.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter23.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter23.webp new file mode 100644 index 00000000..72adb696 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter23.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter24.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter24.webp new file mode 100644 index 00000000..9634dcba Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter24.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter25.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter25.webp new file mode 100644 index 00000000..aa48cdd5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter25.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter3.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter3.webp new file mode 100644 index 00000000..6d38a825 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter3.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter4.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter4.webp new file mode 100644 index 00000000..8bff0164 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter4.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter5.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter5.webp new file mode 100644 index 00000000..5f40e76a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter5.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter6.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter6.webp new file mode 100644 index 00000000..c251cff6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter6.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter7.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter7.webp new file mode 100644 index 00000000..baad4a32 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter7.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter8.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter8.webp new file mode 100644 index 00000000..4ed2781e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter8.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter9.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter9.webp new file mode 100644 index 00000000..7b9a8471 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/field emitter9.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/grappling hook.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/grappling hook.webp new file mode 100644 index 00000000..1b138264 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/grappling hook.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/metamaterial cloaking.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/metamaterial cloaking.webp new file mode 100644 index 00000000..08d39e04 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/metamaterial cloaking.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/molecular assembler.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/molecular assembler.webp new file mode 100644 index 00000000..89a2ab22 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/molecular assembler.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/negative mass.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/negative mass.webp new file mode 100644 index 00000000..f6f94dd2 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/negative mass.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/perfect diamagnetism.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/perfect diamagnetism.webp new file mode 100644 index 00000000..82a5f1fc Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/perfect diamagnetism.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/pilot wave.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/pilot wave.webp new file mode 100644 index 00000000..d6b52813 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/pilot wave.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/plasma torch.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/plasma torch.webp new file mode 100644 index 00000000..95cbaef3 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/plasma torch.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/standing wave.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/standing wave.webp new file mode 100644 index 00000000..7b130a78 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/standing wave.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/time dilation.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/time dilation.webp new file mode 100644 index 00000000..e7c0cc14 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/time dilation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/field/wormhole.webp b/WebGames-master/WebGames-master/n-gon-master/img/field/wormhole.webp new file mode 100644 index 00000000..ec2fab4a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/field/wormhole.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/fine-structure constant.webp b/WebGames-master/WebGames-master/n-gon-master/img/fine-structure constant.webp new file mode 100644 index 00000000..d070faa1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/fine-structure constant.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/fireworks.webp b/WebGames-master/WebGames-master/n-gon-master/img/fireworks.webp new file mode 100644 index 00000000..27fad969 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/fireworks.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/first derivative.webp b/WebGames-master/WebGames-master/n-gon-master/img/first derivative.webp new file mode 100644 index 00000000..f32d1bdc Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/first derivative.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/flagella.webp b/WebGames-master/WebGames-master/n-gon-master/img/flagella.webp new file mode 100644 index 00000000..130ca508 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/flagella.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/flame test.webp b/WebGames-master/WebGames-master/n-gon-master/img/flame test.webp new file mode 100644 index 00000000..50c30904 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/flame test.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/flash freeze.webp b/WebGames-master/WebGames-master/n-gon-master/img/flash freeze.webp new file mode 100644 index 00000000..bb5d0a07 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/flash freeze.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/flip-flop.webp b/WebGames-master/WebGames-master/n-gon-master/img/flip-flop.webp new file mode 100644 index 00000000..5c6b8be8 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/flip-flop.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/fluoroantimonic acid.webp b/WebGames-master/WebGames-master/n-gon-master/img/fluoroantimonic acid.webp new file mode 100644 index 00000000..99a37443 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/fluoroantimonic acid.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/flux pinning.webp b/WebGames-master/WebGames-master/n-gon-master/img/flux pinning.webp new file mode 100644 index 00000000..aa2baa04 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/flux pinning.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/flywheel.webp b/WebGames-master/WebGames-master/n-gon-master/img/flywheel.webp new file mode 100644 index 00000000..953e9f24 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/flywheel.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/foam fractionation.webp b/WebGames-master/WebGames-master/n-gon-master/img/foam fractionation.webp new file mode 100644 index 00000000..811a613d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/foam fractionation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/foam-bot upgrade.webp b/WebGames-master/WebGames-master/n-gon-master/img/foam-bot upgrade.webp new file mode 100644 index 00000000..f64ec65e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/foam-bot upgrade.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/foam-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/foam-bot.webp new file mode 100644 index 00000000..7c9fe501 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/foam-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/foam-shot.webp b/WebGames-master/WebGames-master/n-gon-master/img/foam-shot.webp new file mode 100644 index 00000000..73a53a7c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/foam-shot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/fracture analysis.webp b/WebGames-master/WebGames-master/n-gon-master/img/fracture analysis.webp new file mode 100644 index 00000000..16007711 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/fracture analysis.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/fragmentation.webp b/WebGames-master/WebGames-master/n-gon-master/img/fragmentation.webp new file mode 100644 index 00000000..ea6c04b9 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/fragmentation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/frame-dragging.webp b/WebGames-master/WebGames-master/n-gon-master/img/frame-dragging.webp new file mode 100644 index 00000000..09b90ba5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/frame-dragging.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/free-electron laser.webp b/WebGames-master/WebGames-master/n-gon-master/img/free-electron laser.webp new file mode 100644 index 00000000..236492f4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/free-electron laser.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/freezer burn.webp b/WebGames-master/WebGames-master/n-gon-master/img/freezer burn.webp new file mode 100644 index 00000000..57750a4b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/freezer burn.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/frequency.webp b/WebGames-master/WebGames-master/n-gon-master/img/frequency.webp new file mode 100644 index 00000000..b8b26a25 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/frequency.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/futures exchange.webp b/WebGames-master/WebGames-master/n-gon-master/img/futures exchange.webp new file mode 100644 index 00000000..561c99f3 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/futures exchange.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gauge.webp b/WebGames-master/WebGames-master/n-gon-master/img/gauge.webp new file mode 100644 index 00000000..a4f5231a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gauge.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/generalist.webp b/WebGames-master/WebGames-master/n-gon-master/img/generalist.webp new file mode 100644 index 00000000..802cbb21 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/generalist.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/geodesics.webp b/WebGames-master/WebGames-master/n-gon-master/img/geodesics.webp new file mode 100644 index 00000000..4cb475b5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/geodesics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ground state.webp b/WebGames-master/WebGames-master/n-gon-master/img/ground state.webp new file mode 100644 index 00000000..5e6ba803 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ground state.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun turret.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun turret.webp new file mode 100644 index 00000000..ca8bc6c9 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun turret.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/drones.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/drones.webp new file mode 100644 index 00000000..a91022d7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/drones.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/foam.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/foam.webp new file mode 100644 index 00000000..f70c3182 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/foam.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/grenades.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/grenades.webp new file mode 100644 index 00000000..6a6c048a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/grenades.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/harpoon.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/harpoon.webp new file mode 100644 index 00000000..fb158cf1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/harpoon.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/laser.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/laser.webp new file mode 100644 index 00000000..de8624e5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/laser.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/mine.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/mine.webp new file mode 100644 index 00000000..4a2304ed Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/mine.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/missiles.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/missiles.webp new file mode 100644 index 00000000..2e822b59 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/missiles.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/nail gun.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/nail gun.webp new file mode 100644 index 00000000..66ac2017 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/nail gun.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/shotgun.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/shotgun.webp new file mode 100644 index 00000000..436490af Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/shotgun.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/spores.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/spores.webp new file mode 100644 index 00000000..d8fca1fe Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/spores.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/super balls.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/super balls.webp new file mode 100644 index 00000000..3e0c03c0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/super balls.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/gun/wave.webp b/WebGames-master/WebGames-master/n-gon-master/img/gun/wave.webp new file mode 100644 index 00000000..b769112d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/gun/wave.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/heals.webp b/WebGames-master/WebGames-master/n-gon-master/img/heals.webp new file mode 100644 index 00000000..d92dcd9c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/heals.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/heat engine.webp b/WebGames-master/WebGames-master/n-gon-master/img/heat engine.webp new file mode 100644 index 00000000..df299f82 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/heat engine.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/heuristics.webp b/WebGames-master/WebGames-master/n-gon-master/img/heuristics.webp new file mode 100644 index 00000000..8b8c0abb Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/heuristics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/hidden-variable theory.webp b/WebGames-master/WebGames-master/n-gon-master/img/hidden-variable theory.webp new file mode 100644 index 00000000..1db74f5d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/hidden-variable theory.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/holographic principle.webp b/WebGames-master/WebGames-master/n-gon-master/img/holographic principle.webp new file mode 100644 index 00000000..79b6d26f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/holographic principle.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/homeostasis.webp b/WebGames-master/WebGames-master/n-gon-master/img/homeostasis.webp new file mode 100644 index 00000000..862ae53f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/homeostasis.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ice crystal nucleation.webp b/WebGames-master/WebGames-master/n-gon-master/img/ice crystal nucleation.webp new file mode 100644 index 00000000..160876b1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ice crystal nucleation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ice-shot.webp b/WebGames-master/WebGames-master/n-gon-master/img/ice-shot.webp new file mode 100644 index 00000000..4f3169ed Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ice-shot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ideal gas law.webp b/WebGames-master/WebGames-master/n-gon-master/img/ideal gas law.webp new file mode 100644 index 00000000..c2097ef0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ideal gas law.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/incendiary ammunition.webp b/WebGames-master/WebGames-master/n-gon-master/img/incendiary ammunition.webp new file mode 100644 index 00000000..643248d7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/incendiary ammunition.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/induction brake.webp b/WebGames-master/WebGames-master/n-gon-master/img/induction brake.webp new file mode 100644 index 00000000..fbb44244 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/induction brake.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/induction furnace.webp b/WebGames-master/WebGames-master/n-gon-master/img/induction furnace.webp new file mode 100644 index 00000000..af1aac85 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/induction furnace.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/inductive charging.webp b/WebGames-master/WebGames-master/n-gon-master/img/inductive charging.webp new file mode 100644 index 00000000..55643bdf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/inductive charging.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/inertial confinement.webp b/WebGames-master/WebGames-master/n-gon-master/img/inertial confinement.webp new file mode 100644 index 00000000..068f0c08 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/inertial confinement.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/inertial mass.webp b/WebGames-master/WebGames-master/n-gon-master/img/inertial mass.webp new file mode 100644 index 00000000..06309001 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/inertial mass.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/inflation.webp b/WebGames-master/WebGames-master/n-gon-master/img/inflation.webp new file mode 100644 index 00000000..1f4374ee Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/inflation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/infrared diode.webp b/WebGames-master/WebGames-master/n-gon-master/img/infrared diode.webp new file mode 100644 index 00000000..e6a0d5a0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/infrared diode.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/instability.webp b/WebGames-master/WebGames-master/n-gon-master/img/instability.webp new file mode 100644 index 00000000..fdcbf8f4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/instability.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/integrated armament.webp b/WebGames-master/WebGames-master/n-gon-master/img/integrated armament.webp new file mode 100644 index 00000000..53dbad21 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/integrated armament.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/integrated circuit.webp b/WebGames-master/WebGames-master/n-gon-master/img/integrated circuit.webp new file mode 100644 index 00000000..3feb4a4c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/integrated circuit.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/interest.webp b/WebGames-master/WebGames-master/n-gon-master/img/interest.webp new file mode 100644 index 00000000..51efb085 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/interest.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/invariant.webp b/WebGames-master/WebGames-master/n-gon-master/img/invariant.webp new file mode 100644 index 00000000..9092bed6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/invariant.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/iridescence.webp b/WebGames-master/WebGames-master/n-gon-master/img/iridescence.webp new file mode 100644 index 00000000..4bdb1e1d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/iridescence.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/iridium-192.webp b/WebGames-master/WebGames-master/n-gon-master/img/iridium-192.webp new file mode 100644 index 00000000..bd589490 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/iridium-192.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/irradiated drones.webp b/WebGames-master/WebGames-master/n-gon-master/img/irradiated drones.webp new file mode 100644 index 00000000..d3f2db5d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/irradiated drones.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/irradiated nails.webp b/WebGames-master/WebGames-master/n-gon-master/img/irradiated nails.webp new file mode 100644 index 00000000..7ce6e2c6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/irradiated nails.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/isotropic.webp b/WebGames-master/WebGames-master/n-gon-master/img/isotropic.webp new file mode 100644 index 00000000..ef8984b2 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/isotropic.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/junk DNA.webp b/WebGames-master/WebGames-master/n-gon-master/img/junk DNA.webp new file mode 100644 index 00000000..c8029c66 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/junk DNA.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/junk.webp b/WebGames-master/WebGames-master/n-gon-master/img/junk.webp new file mode 100644 index 00000000..af38107c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/junk.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/kinetic bombardment.webp b/WebGames-master/WebGames-master/n-gon-master/img/kinetic bombardment.webp new file mode 100644 index 00000000..f7cd8b50 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/kinetic bombardment.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/laser-bot upgrade.webp b/WebGames-master/WebGames-master/n-gon-master/img/laser-bot upgrade.webp new file mode 100644 index 00000000..6df8d4eb Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/laser-bot upgrade.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/laser-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/laser-bot.webp new file mode 100644 index 00000000..1e82e9ad Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/laser-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/laser-mines.webp b/WebGames-master/WebGames-master/n-gon-master/img/laser-mines.webp new file mode 100644 index 00000000..639f6cac Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/laser-mines.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/launch system.webp b/WebGames-master/WebGames-master/n-gon-master/img/launch system.webp new file mode 100644 index 00000000..8c10eaba Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/launch system.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/lens.webp b/WebGames-master/WebGames-master/n-gon-master/img/lens.webp new file mode 100644 index 00000000..1ad4e50a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/lens.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/lithium-ion.webp b/WebGames-master/WebGames-master/n-gon-master/img/lithium-ion.webp new file mode 100644 index 00000000..73ae0e78 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/lithium-ion.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/logistics.webp b/WebGames-master/WebGames-master/n-gon-master/img/logistics.webp new file mode 100644 index 00000000..1b31696f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/logistics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/maintenance.webp b/WebGames-master/WebGames-master/n-gon-master/img/maintenance.webp new file mode 100644 index 00000000..ea53c8a7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/maintenance.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/many-worlds.webp b/WebGames-master/WebGames-master/n-gon-master/img/many-worlds.webp new file mode 100644 index 00000000..186e8746 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/many-worlds.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/marginal utility.webp b/WebGames-master/WebGames-master/n-gon-master/img/marginal utility.webp new file mode 100644 index 00000000..92e54bd4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/marginal utility.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/martingale.webp b/WebGames-master/WebGames-master/n-gon-master/img/martingale.webp new file mode 100644 index 00000000..8f1e712c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/martingale.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/mass driver.webp b/WebGames-master/WebGames-master/n-gon-master/img/mass driver.webp new file mode 100644 index 00000000..fe943e31 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/mass driver.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/mass production.webp b/WebGames-master/WebGames-master/n-gon-master/img/mass production.webp new file mode 100644 index 00000000..b8cf5f89 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/mass production.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/mass-energy equivalence.webp b/WebGames-master/WebGames-master/n-gon-master/img/mass-energy equivalence.webp new file mode 100644 index 00000000..95a6a2b1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/mass-energy equivalence.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/mechanical resonance.webp b/WebGames-master/WebGames-master/n-gon-master/img/mechanical resonance.webp new file mode 100644 index 00000000..c6092319 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/mechanical resonance.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/mechatronics.webp b/WebGames-master/WebGames-master/n-gon-master/img/mechatronics.webp new file mode 100644 index 00000000..37d69f45 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/mechatronics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/meta-analysis.webp b/WebGames-master/WebGames-master/n-gon-master/img/meta-analysis.webp new file mode 100644 index 00000000..3fe80d82 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/meta-analysis.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/metamaterial absorber.webp b/WebGames-master/WebGames-master/n-gon-master/img/metamaterial absorber.webp new file mode 100644 index 00000000..42bb32b3 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/metamaterial absorber.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/metastability.webp b/WebGames-master/WebGames-master/n-gon-master/img/metastability.webp new file mode 100644 index 00000000..6c80be4b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/metastability.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/microstates.webp b/WebGames-master/WebGames-master/n-gon-master/img/microstates.webp new file mode 100644 index 00000000..df7f9787 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/microstates.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/missile-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/missile-bot.webp new file mode 100644 index 00000000..d465f098 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/missile-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/mutualism.webp b/WebGames-master/WebGames-master/n-gon-master/img/mutualism.webp new file mode 100644 index 00000000..5b0252eb Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/mutualism.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/mycelial fragmentation.webp b/WebGames-master/WebGames-master/n-gon-master/img/mycelial fragmentation.webp new file mode 100644 index 00000000..5035c1b6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/mycelial fragmentation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/nail-bot upgrade.webp b/WebGames-master/WebGames-master/n-gon-master/img/nail-bot upgrade.webp new file mode 100644 index 00000000..832ff436 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/nail-bot upgrade.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/nail-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/nail-bot.webp new file mode 100644 index 00000000..9b9c3a73 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/nail-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/nail-shot.webp b/WebGames-master/WebGames-master/n-gon-master/img/nail-shot.webp new file mode 100644 index 00000000..eb412f03 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/nail-shot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/nanowires.webp b/WebGames-master/WebGames-master/n-gon-master/img/nanowires.webp new file mode 100644 index 00000000..e7c6b614 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/nanowires.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/necrophage.webp b/WebGames-master/WebGames-master/n-gon-master/img/necrophage.webp new file mode 100644 index 00000000..47f7fae0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/necrophage.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/needle gun.webp b/WebGames-master/WebGames-master/n-gon-master/img/needle gun.webp new file mode 100644 index 00000000..129df9ad Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/needle gun.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/needle ice.webp b/WebGames-master/WebGames-master/n-gon-master/img/needle ice.webp new file mode 100644 index 00000000..42356953 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/needle ice.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/negative feedback.webp b/WebGames-master/WebGames-master/n-gon-master/img/negative feedback.webp new file mode 100644 index 00000000..68611ba4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/negative feedback.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/nematodes.webp b/WebGames-master/WebGames-master/n-gon-master/img/nematodes.webp new file mode 100644 index 00000000..637b19ea Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/nematodes.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/network effect.webp b/WebGames-master/WebGames-master/n-gon-master/img/network effect.webp new file mode 100644 index 00000000..1084a7e7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/network effect.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/neutron bomb.webp b/WebGames-master/WebGames-master/n-gon-master/img/neutron bomb.webp new file mode 100644 index 00000000..e5ea20fa Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/neutron bomb.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/neutronium.webp b/WebGames-master/WebGames-master/n-gon-master/img/neutronium.webp new file mode 100644 index 00000000..fce6535d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/neutronium.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/nitinol.webp b/WebGames-master/WebGames-master/n-gon-master/img/nitinol.webp new file mode 100644 index 00000000..5c7290e9 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/nitinol.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/nitroglycerin.webp b/WebGames-master/WebGames-master/n-gon-master/img/nitroglycerin.webp new file mode 100644 index 00000000..55f5f2e5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/nitroglycerin.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/no-cloning theorem.webp b/WebGames-master/WebGames-master/n-gon-master/img/no-cloning theorem.webp new file mode 100644 index 00000000..cd6cdee5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/no-cloning theorem.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/non-Newtonian armor.webp b/WebGames-master/WebGames-master/n-gon-master/img/non-Newtonian armor.webp new file mode 100644 index 00000000..f7e3823b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/non-Newtonian armor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/non-renewables.webp b/WebGames-master/WebGames-master/n-gon-master/img/non-renewables.webp new file mode 100644 index 00000000..6fa89593 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/non-renewables.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/nuclear transmutation.webp b/WebGames-master/WebGames-master/n-gon-master/img/nuclear transmutation.webp new file mode 100644 index 00000000..ba6b3f92 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/nuclear transmutation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/null hypothesis.webp b/WebGames-master/WebGames-master/n-gon-master/img/null hypothesis.webp new file mode 100644 index 00000000..f7ca944b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/null hypothesis.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/open-source.webp b/WebGames-master/WebGames-master/n-gon-master/img/open-source.webp new file mode 100644 index 00000000..44b6a233 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/open-source.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/optical amplifier.webp b/WebGames-master/WebGames-master/n-gon-master/img/optical amplifier.webp new file mode 100644 index 00000000..7fa80514 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/optical amplifier.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/options exchange.webp b/WebGames-master/WebGames-master/n-gon-master/img/options exchange.webp new file mode 100644 index 00000000..a805ffce Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/options exchange.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/orbital-bot upgrade.webp b/WebGames-master/WebGames-master/n-gon-master/img/orbital-bot upgrade.webp new file mode 100644 index 00000000..46ff5385 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/orbital-bot upgrade.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/orbital-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/orbital-bot.webp new file mode 100644 index 00000000..1ab8298f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/orbital-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ordnance.webp b/WebGames-master/WebGames-master/n-gon-master/img/ordnance.webp new file mode 100644 index 00000000..f28c241b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ordnance.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/orthocyclic winding.webp b/WebGames-master/WebGames-master/n-gon-master/img/orthocyclic winding.webp new file mode 100644 index 00000000..770461b5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/orthocyclic winding.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/output coupler.webp b/WebGames-master/WebGames-master/n-gon-master/img/output coupler.webp new file mode 100644 index 00000000..61670f8a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/output coupler.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/overcharge.webp b/WebGames-master/WebGames-master/n-gon-master/img/overcharge.webp new file mode 100644 index 00000000..7c20edb4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/overcharge.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/pair production.webp b/WebGames-master/WebGames-master/n-gon-master/img/pair production.webp new file mode 100644 index 00000000..6e6d6343 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/pair production.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/paradigm shift.webp b/WebGames-master/WebGames-master/n-gon-master/img/paradigm shift.webp new file mode 100644 index 00000000..49553951 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/paradigm shift.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/parasitism.webp b/WebGames-master/WebGames-master/n-gon-master/img/parasitism.webp new file mode 100644 index 00000000..3db9826d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/parasitism.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/parthenogenesis.webp b/WebGames-master/WebGames-master/n-gon-master/img/parthenogenesis.webp new file mode 100644 index 00000000..e74f1c5c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/parthenogenesis.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/patch.webp b/WebGames-master/WebGames-master/n-gon-master/img/patch.webp new file mode 100644 index 00000000..2e65da5c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/patch.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/path integral.webp b/WebGames-master/WebGames-master/n-gon-master/img/path integral.webp new file mode 100644 index 00000000..a81389bd Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/path integral.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/path integration.webp b/WebGames-master/WebGames-master/n-gon-master/img/path integration.webp new file mode 100644 index 00000000..9427793c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/path integration.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/peer review.webp b/WebGames-master/WebGames-master/n-gon-master/img/peer review.webp new file mode 100644 index 00000000..0a91809a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/peer review.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/perimeter defense.webp b/WebGames-master/WebGames-master/n-gon-master/img/perimeter defense.webp new file mode 100644 index 00000000..071ecc59 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/perimeter defense.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/perturbation theory.webp b/WebGames-master/WebGames-master/n-gon-master/img/perturbation theory.webp new file mode 100644 index 00000000..ffff9b8e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/perturbation theory.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/phase velocity.webp b/WebGames-master/WebGames-master/n-gon-master/img/phase velocity.webp new file mode 100644 index 00000000..35875c2d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/phase velocity.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/phonon.webp b/WebGames-master/WebGames-master/n-gon-master/img/phonon.webp new file mode 100644 index 00000000..53f7afe1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/phonon.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/piezoelectricity.webp b/WebGames-master/WebGames-master/n-gon-master/img/piezoelectricity.webp new file mode 100644 index 00000000..455fd7c3 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/piezoelectricity.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/pigeonhole principle.webp b/WebGames-master/WebGames-master/n-gon-master/img/pigeonhole principle.webp new file mode 100644 index 00000000..9475d19c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/pigeonhole principle.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/planned obsolescence.webp b/WebGames-master/WebGames-master/n-gon-master/img/planned obsolescence.webp new file mode 100644 index 00000000..b47d9284 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/planned obsolescence.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/plasma ball.webp b/WebGames-master/WebGames-master/n-gon-master/img/plasma ball.webp new file mode 100644 index 00000000..a2a692f0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/plasma ball.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/plasma jet.webp b/WebGames-master/WebGames-master/n-gon-master/img/plasma jet.webp new file mode 100644 index 00000000..e6142696 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/plasma jet.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/plasma-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/plasma-bot.webp new file mode 100644 index 00000000..9d71d506 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/plasma-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/pneumatic actuator.webp b/WebGames-master/WebGames-master/n-gon-master/img/pneumatic actuator.webp new file mode 100644 index 00000000..9bb5a7f0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/pneumatic actuator.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/polariton.webp b/WebGames-master/WebGames-master/n-gon-master/img/polariton.webp new file mode 100644 index 00000000..b512f02d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/polariton.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/polyurethane foam.webp b/WebGames-master/WebGames-master/n-gon-master/img/polyurethane foam.webp new file mode 100644 index 00000000..d5745625 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/polyurethane foam.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/pressure vessel.webp b/WebGames-master/WebGames-master/n-gon-master/img/pressure vessel.webp new file mode 100644 index 00000000..a4e27dee Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/pressure vessel.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/propagation.webp b/WebGames-master/WebGames-master/n-gon-master/img/propagation.webp new file mode 100644 index 00000000..c47af7fb Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/propagation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/pseudoscience.webp b/WebGames-master/WebGames-master/n-gon-master/img/pseudoscience.webp new file mode 100644 index 00000000..fdee13b9 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/pseudoscience.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/pulse.webp b/WebGames-master/WebGames-master/n-gon-master/img/pulse.webp new file mode 100644 index 00000000..6225cde0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/pulse.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/pyrotechnics.webp b/WebGames-master/WebGames-master/n-gon-master/img/pyrotechnics.webp new file mode 100644 index 00000000..8ab09211 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/pyrotechnics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/quantum immortality.webp b/WebGames-master/WebGames-master/n-gon-master/img/quantum immortality.webp new file mode 100644 index 00000000..028c9f7a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/quantum immortality.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/quasiparticles.webp b/WebGames-master/WebGames-master/n-gon-master/img/quasiparticles.webp new file mode 100644 index 00000000..18d3bad1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/quasiparticles.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/quenching.webp b/WebGames-master/WebGames-master/n-gon-master/img/quenching.webp new file mode 100644 index 00000000..ecf7887e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/quenching.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/quintessence.webp b/WebGames-master/WebGames-master/n-gon-master/img/quintessence.webp new file mode 100644 index 00000000..617bb16c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/quintessence.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/radiative equilibrium.webp b/WebGames-master/WebGames-master/n-gon-master/img/radiative equilibrium.webp new file mode 100644 index 00000000..6fd3b3d2 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/radiative equilibrium.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/radioactive contamination.webp b/WebGames-master/WebGames-master/n-gon-master/img/radioactive contamination.webp new file mode 100644 index 00000000..347dab41 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/radioactive contamination.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/railgun.webp b/WebGames-master/WebGames-master/n-gon-master/img/railgun.webp new file mode 100644 index 00000000..d80883f6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/railgun.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/reaction inhibitor.webp b/WebGames-master/WebGames-master/n-gon-master/img/reaction inhibitor.webp new file mode 100644 index 00000000..de5a4404 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/reaction inhibitor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/rebound.webp b/WebGames-master/WebGames-master/n-gon-master/img/rebound.webp new file mode 100644 index 00000000..01e098c3 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/rebound.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/recycling.webp b/WebGames-master/WebGames-master/n-gon-master/img/recycling.webp new file mode 100644 index 00000000..775edc5d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/recycling.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/reduced tolerances.webp b/WebGames-master/WebGames-master/n-gon-master/img/reduced tolerances.webp new file mode 100644 index 00000000..35b4ee8d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/reduced tolerances.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/reel.webp b/WebGames-master/WebGames-master/n-gon-master/img/reel.webp new file mode 100644 index 00000000..af2baa09 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/reel.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/refraction.webp b/WebGames-master/WebGames-master/n-gon-master/img/refraction.webp new file mode 100644 index 00000000..4901c68c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/refraction.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/refractory metal.webp b/WebGames-master/WebGames-master/n-gon-master/img/refractory metal.webp new file mode 100644 index 00000000..c44f3e24 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/refractory metal.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/refrigerant.webp b/WebGames-master/WebGames-master/n-gon-master/img/refrigerant.webp new file mode 100644 index 00000000..d8f27c32 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/refrigerant.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/regression.webp b/WebGames-master/WebGames-master/n-gon-master/img/regression.webp new file mode 100644 index 00000000..da119ef6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/regression.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/reinforcement learning.webp b/WebGames-master/WebGames-master/n-gon-master/img/reinforcement learning.webp new file mode 100644 index 00000000..77118538 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/reinforcement learning.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/relativistic momentum.webp b/WebGames-master/WebGames-master/n-gon-master/img/relativistic momentum.webp new file mode 100644 index 00000000..55422658 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/relativistic momentum.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/relay switch.webp b/WebGames-master/WebGames-master/n-gon-master/img/relay switch.webp new file mode 100644 index 00000000..d6707f91 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/relay switch.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/renormalization.webp b/WebGames-master/WebGames-master/n-gon-master/img/renormalization.webp new file mode 100644 index 00000000..6b0391bf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/renormalization.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/repeater.webp b/WebGames-master/WebGames-master/n-gon-master/img/repeater.webp new file mode 100644 index 00000000..1be7058f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/repeater.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/replication.webp b/WebGames-master/WebGames-master/n-gon-master/img/replication.webp new file mode 100644 index 00000000..8dfb21cf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/replication.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/repolarization.webp b/WebGames-master/WebGames-master/n-gon-master/img/repolarization.webp new file mode 100644 index 00000000..29326078 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/repolarization.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/research.webp b/WebGames-master/WebGames-master/n-gon-master/img/research.webp new file mode 100644 index 00000000..99ac3962 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/research.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/residual dipolar coupling.webp b/WebGames-master/WebGames-master/n-gon-master/img/residual dipolar coupling.webp new file mode 100644 index 00000000..5fcb9722 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/residual dipolar coupling.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/restitution.webp b/WebGames-master/WebGames-master/n-gon-master/img/restitution.webp new file mode 100644 index 00000000..3ec9f61d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/restitution.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/retrocausality.webp b/WebGames-master/WebGames-master/n-gon-master/img/retrocausality.webp new file mode 100644 index 00000000..17997c76 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/retrocausality.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ricochet.webp b/WebGames-master/WebGames-master/n-gon-master/img/ricochet.webp new file mode 100644 index 00000000..5863d225 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ricochet.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/rivet gun.webp b/WebGames-master/WebGames-master/n-gon-master/img/rivet gun.webp new file mode 100644 index 00000000..a94f4f68 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/rivet gun.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/robotics.webp b/WebGames-master/WebGames-master/n-gon-master/img/robotics.webp new file mode 100644 index 00000000..feba476d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/robotics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/rocket-propelled grenade.webp b/WebGames-master/WebGames-master/n-gon-master/img/rocket-propelled grenade.webp new file mode 100644 index 00000000..efe978b0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/rocket-propelled grenade.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/rotary cannon.webp b/WebGames-master/WebGames-master/n-gon-master/img/rotary cannon.webp new file mode 100644 index 00000000..69df5fca Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/rotary cannon.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/scrap bots.webp b/WebGames-master/WebGames-master/n-gon-master/img/scrap bots.webp new file mode 100644 index 00000000..9482b30f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/scrap bots.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/scrap refit.webp b/WebGames-master/WebGames-master/n-gon-master/img/scrap refit.webp new file mode 100644 index 00000000..243fcc7a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/scrap refit.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/self-assembly.webp b/WebGames-master/WebGames-master/n-gon-master/img/self-assembly.webp new file mode 100644 index 00000000..3cb0fe2d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/self-assembly.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/sentry.webp b/WebGames-master/WebGames-master/n-gon-master/img/sentry.webp new file mode 100644 index 00000000..a9cfb29c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/sentry.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/shape-memory alloy.webp b/WebGames-master/WebGames-master/n-gon-master/img/shape-memory alloy.webp new file mode 100644 index 00000000..fc76420e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/shape-memory alloy.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/shaped charge.webp b/WebGames-master/WebGames-master/n-gon-master/img/shaped charge.webp new file mode 100644 index 00000000..70b7a7c8 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/shaped charge.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/shear stress.webp b/WebGames-master/WebGames-master/n-gon-master/img/shear stress.webp new file mode 100644 index 00000000..211b5a94 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/shear stress.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/shock wave.webp b/WebGames-master/WebGames-master/n-gon-master/img/shock wave.webp new file mode 100644 index 00000000..ff4d9459 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/shock wave.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/simulated annealing.webp b/WebGames-master/WebGames-master/n-gon-master/img/simulated annealing.webp new file mode 100644 index 00000000..bfc1ef43 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/simulated annealing.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/siphonaptera.webp b/WebGames-master/WebGames-master/n-gon-master/img/siphonaptera.webp new file mode 100644 index 00000000..1b55f51c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/siphonaptera.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/smelting.webp b/WebGames-master/WebGames-master/n-gon-master/img/smelting.webp new file mode 100644 index 00000000..783d4df7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/smelting.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/sound-bot upgrade.webp b/WebGames-master/WebGames-master/n-gon-master/img/sound-bot upgrade.webp new file mode 100644 index 00000000..119cbfa1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/sound-bot upgrade.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/sound-bot.webp b/WebGames-master/WebGames-master/n-gon-master/img/sound-bot.webp new file mode 100644 index 00000000..85b39b8a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/sound-bot.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/specular reflection.webp b/WebGames-master/WebGames-master/n-gon-master/img/specular reflection.webp new file mode 100644 index 00000000..3218665e Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/specular reflection.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/spherical harmonics.webp b/WebGames-master/WebGames-master/n-gon-master/img/spherical harmonics.webp new file mode 100644 index 00000000..1aedfd1d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/spherical harmonics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/spin-statistics theorem.webp b/WebGames-master/WebGames-master/n-gon-master/img/spin-statistics theorem.webp new file mode 100644 index 00000000..297a2db1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/spin-statistics theorem.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/spin-statistics.webp b/WebGames-master/WebGames-master/n-gon-master/img/spin-statistics.webp new file mode 100644 index 00000000..2f2b4700 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/spin-statistics.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/stability.webp b/WebGames-master/WebGames-master/n-gon-master/img/stability.webp new file mode 100644 index 00000000..f9a7dab2 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/stability.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/stellarator.webp b/WebGames-master/WebGames-master/n-gon-master/img/stellarator.webp new file mode 100644 index 00000000..49fe2efa Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/stellarator.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/stimulated emission.webp b/WebGames-master/WebGames-master/n-gon-master/img/stimulated emission.webp new file mode 100644 index 00000000..ce9a1ccf Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/stimulated emission.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/strange attractor.webp b/WebGames-master/WebGames-master/n-gon-master/img/strange attractor.webp new file mode 100644 index 00000000..983778f7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/strange attractor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/strange loop.webp b/WebGames-master/WebGames-master/n-gon-master/img/strange loop.webp new file mode 100644 index 00000000..ed374c33 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/strange loop.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/stress concentration.webp b/WebGames-master/WebGames-master/n-gon-master/img/stress concentration.webp new file mode 100644 index 00000000..92b1806c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/stress concentration.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/strong anthropic principle.webp b/WebGames-master/WebGames-master/n-gon-master/img/strong anthropic principle.webp new file mode 100644 index 00000000..ffbfd315 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/strong anthropic principle.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/super ball.webp b/WebGames-master/WebGames-master/n-gon-master/img/super ball.webp new file mode 100644 index 00000000..9c7f945a Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/super ball.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/super duper.webp b/WebGames-master/WebGames-master/n-gon-master/img/super duper.webp new file mode 100644 index 00000000..d5e1f2a6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/super duper.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/supercritical fission.webp b/WebGames-master/WebGames-master/n-gon-master/img/supercritical fission.webp new file mode 100644 index 00000000..4e9c3c07 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/supercritical fission.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/superdeterminism.webp b/WebGames-master/WebGames-master/n-gon-master/img/superdeterminism.webp new file mode 100644 index 00000000..d07b9b01 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/superdeterminism.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/superfluidity.webp b/WebGames-master/WebGames-master/n-gon-master/img/superfluidity.webp new file mode 100644 index 00000000..7f0bc3dd Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/superfluidity.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/supply chain.webp b/WebGames-master/WebGames-master/n-gon-master/img/supply chain.webp new file mode 100644 index 00000000..29814efc Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/supply chain.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/surface plasmons.webp b/WebGames-master/WebGames-master/n-gon-master/img/surface plasmons.webp new file mode 100644 index 00000000..a78ba3a8 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/surface plasmons.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/surface tension.webp b/WebGames-master/WebGames-master/n-gon-master/img/surface tension.webp new file mode 100644 index 00000000..469fe59f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/surface tension.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/surfactant.webp b/WebGames-master/WebGames-master/n-gon-master/img/surfactant.webp new file mode 100644 index 00000000..291fd6c1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/surfactant.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/swarf.webp b/WebGames-master/WebGames-master/n-gon-master/img/swarf.webp new file mode 100644 index 00000000..8c77f01b Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/swarf.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/symbiosis.webp b/WebGames-master/WebGames-master/n-gon-master/img/symbiosis.webp new file mode 100644 index 00000000..61c253e7 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/symbiosis.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/sympathetic resonance.webp b/WebGames-master/WebGames-master/n-gon-master/img/sympathetic resonance.webp new file mode 100644 index 00000000..5f0a77dd Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/sympathetic resonance.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/technical debt.webp b/WebGames-master/WebGames-master/n-gon-master/img/technical debt.webp new file mode 100644 index 00000000..7f5facb0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/technical debt.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/ternary.webp b/WebGames-master/WebGames-master/n-gon-master/img/ternary.webp new file mode 100644 index 00000000..e39b90c5 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/ternary.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/tessellation.webp b/WebGames-master/WebGames-master/n-gon-master/img/tessellation.webp new file mode 100644 index 00000000..4992624f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/tessellation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/thermal runaway.webp b/WebGames-master/WebGames-master/n-gon-master/img/thermal runaway.webp new file mode 100644 index 00000000..a7c59932 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/thermal runaway.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/thermocouple.webp b/WebGames-master/WebGames-master/n-gon-master/img/thermocouple.webp new file mode 100644 index 00000000..d669ea57 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/thermocouple.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/thermoelectric effect.webp b/WebGames-master/WebGames-master/n-gon-master/img/thermoelectric effect.webp new file mode 100644 index 00000000..bc91ec21 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/thermoelectric effect.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/time crystals.webp b/WebGames-master/WebGames-master/n-gon-master/img/time crystals.webp new file mode 100644 index 00000000..5b06557f Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/time crystals.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/tokamak.webp b/WebGames-master/WebGames-master/n-gon-master/img/tokamak.webp new file mode 100644 index 00000000..4a37b667 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/tokamak.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/topological defect.webp b/WebGames-master/WebGames-master/n-gon-master/img/topological defect.webp new file mode 100644 index 00000000..a4be7c93 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/topological defect.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/torpor.webp b/WebGames-master/WebGames-master/n-gon-master/img/torpor.webp new file mode 100644 index 00000000..cc1165fc Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/torpor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/transdimensional worms.webp b/WebGames-master/WebGames-master/n-gon-master/img/transdimensional worms.webp new file mode 100644 index 00000000..e01c7807 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/transdimensional worms.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/transistor.webp b/WebGames-master/WebGames-master/n-gon-master/img/transistor.webp new file mode 100644 index 00000000..f62e0c34 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/transistor.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/triple point.webp b/WebGames-master/WebGames-master/n-gon-master/img/triple point.webp new file mode 100644 index 00000000..260cba62 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/triple point.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/tungsten carbide.webp b/WebGames-master/WebGames-master/n-gon-master/img/tungsten carbide.webp new file mode 100644 index 00000000..3fc90ed4 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/tungsten carbide.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/uncertainty principle.webp b/WebGames-master/WebGames-master/n-gon-master/img/uncertainty principle.webp new file mode 100644 index 00000000..892fcde0 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/uncertainty principle.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/unified field theory.webp b/WebGames-master/WebGames-master/n-gon-master/img/unified field theory.webp new file mode 100644 index 00000000..43230ce3 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/unified field theory.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/vacuum bomb.webp b/WebGames-master/WebGames-master/n-gon-master/img/vacuum bomb.webp new file mode 100644 index 00000000..88011ca1 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/vacuum bomb.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/vacuum fluctuation.webp b/WebGames-master/WebGames-master/n-gon-master/img/vacuum fluctuation.webp new file mode 100644 index 00000000..c7126526 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/vacuum fluctuation.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/vacuum permittivity.webp b/WebGames-master/WebGames-master/n-gon-master/img/vacuum permittivity.webp new file mode 100644 index 00000000..f81f9009 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/vacuum permittivity.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/virtual particles.webp b/WebGames-master/WebGames-master/n-gon-master/img/virtual particles.webp new file mode 100644 index 00000000..a02e99c6 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/virtual particles.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/von Neumann probe.webp b/WebGames-master/WebGames-master/n-gon-master/img/von Neumann probe.webp new file mode 100644 index 00000000..7addbb36 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/von Neumann probe.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/waste heat recovery.webp b/WebGames-master/WebGames-master/n-gon-master/img/waste heat recovery.webp new file mode 100644 index 00000000..e291aba9 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/waste heat recovery.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/water shielding.webp b/WebGames-master/WebGames-master/n-gon-master/img/water shielding.webp new file mode 100644 index 00000000..3dc396eb Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/water shielding.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/weak anthropic principle.webp b/WebGames-master/WebGames-master/n-gon-master/img/weak anthropic principle.webp new file mode 100644 index 00000000..c0ed499c Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/weak anthropic principle.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/working mass.webp b/WebGames-master/WebGames-master/n-gon-master/img/working mass.webp new file mode 100644 index 00000000..d98237bc Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/working mass.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/zero point energy.webp b/WebGames-master/WebGames-master/n-gon-master/img/zero point energy.webp new file mode 100644 index 00000000..21c7d162 Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/zero point energy.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/zoospore vector.webp b/WebGames-master/WebGames-master/n-gon-master/img/zoospore vector.webp new file mode 100644 index 00000000..305d241d Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/zoospore vector.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/img/Ψ(t) collapse.webp b/WebGames-master/WebGames-master/n-gon-master/img/Ψ(t) collapse.webp new file mode 100644 index 00000000..b703bebc Binary files /dev/null and b/WebGames-master/WebGames-master/n-gon-master/img/Ψ(t) collapse.webp differ diff --git a/WebGames-master/WebGames-master/n-gon-master/index.html b/WebGames-master/WebGames-master/n-gon-master/index.html new file mode 100644 index 00000000..099c0762 --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/index.html @@ -0,0 +1,316 @@ + + + + + + + + + + + + + + + n-gon + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + start + + + training + + + experiment + + + +
+
+
+ settings +
+ + +
+ + +
+ + +
+
+ + +
+ + +
+ + +
+
+
+
+
+
+ controls +
+ To change controls click a box +
and press an unused key. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FIREFMouseLeft
FIELDSPACEMouseRight
JUMPWArrowUp
CROUCHSArrowDown
LEFTAArrowLeft
RIGHTDArrowRight
GUN →QMouseWheel
GUN ←EMouseWheel
GUN #Num
PAUSEP
TESTINGT
+
to default keys +
+
+
+
+
+ updates +
+
+
+
+
+ about +
+ + + + + + + + + + + + + + +

+ I wrote n-gon in JavaScript, CSS, and HTML using the matter.js 2-D physics library. + The code is free and open source on Github. + This is just my hobby project, but I try to fix bugs when reported. +

+ + + + +
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Q + W + E + A + S + D + + + + + + + + + + + switch + guns + move + fire + field + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/bullet.js b/WebGames-master/WebGames-master/n-gon-master/js/bullet.js new file mode 100644 index 00000000..dcca903b --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/bullet.js @@ -0,0 +1,7535 @@ +let bullet = []; + +const b = { + // dmgScale: null, //scales all damage, but not raw .dmg + gravity: 0.0006, //most other bodies have gravity = 0.001 + activeGun: null, //current gun in use by player + inventoryGun: 0, + inventory: [], //list of what guns player has // 0 starts with basic gun + setFireMethod() { + if (tech.isFireMoveLock) { + b.fire = b.fireFloat + // } else if (tech.isFireNotMove) { + // if (tech.isAlwaysFire) { + // b.fire = b.fireAlwaysFire + // } else { + // b.fire = b.fireNotMove + // } + } else if (tech.isAlwaysFire) { + b.fire = b.fireAlwaysFire + } else { + b.fire = b.fireNormal + } + }, + fire() { }, + fireNormal() { + if (b.inventory.length && (b.activeGun !== null && b.activeGun !== undefined)) { + if (input.fire && m.fireCDcycle < m.cycle && (!input.field || m.fieldFire)) { + if (b.guns[b.activeGun].ammo > 0) { + b.fireWithAmmo() + } else { + b.outOfAmmo() + } + if (m.holdingTarget) m.drop(); + } + b.guns[b.activeGun].do(); + } + }, + fireNotMove() { //added && player.speed < 0.5 && m.onGround + if (b.inventory.length && (b.activeGun !== null && b.activeGun !== undefined)) { + if (input.fire && m.fireCDcycle < m.cycle && (!input.field || m.fieldFire) && player.speed < 2.5 && m.onGround && Math.abs(m.yOff - m.yOffGoal) < 1) { + if (b.guns[b.activeGun].ammo > 0) { + b.fireWithAmmo() + } else { + b.outOfAmmo() + } + if (m.holdingTarget) m.drop(); + } + b.guns[b.activeGun].do(); + } + }, + fireAlwaysFire() { //added && player.speed < 0.5 && m.onGround //removed input.fire && (!input.field || m.fieldFire) + if (b.inventory.length && (b.activeGun !== null && b.activeGun !== undefined)) { + if (m.fireCDcycle < m.cycle && player.speed < 0.5 && m.onGround && Math.abs(m.yOff - m.yOffGoal) < 1) { + if (b.guns[b.activeGun].ammo > 0) { + b.fireWithAmmo() + } + if (m.holdingTarget) m.drop(); + } + b.guns[b.activeGun].do(); + } + }, + fireFloat() { //added && player.speed < 0.5 && m.onGround + if (b.inventory.length && (b.activeGun !== null && b.activeGun !== undefined)) { + if (input.fire && (!input.field || m.fieldFire)) { + if (m.fireCDcycle < m.cycle) { + if (b.guns[b.activeGun].ammo > 0) { + b.fireWithAmmo() + } else { + b.outOfAmmo() + } + if (m.holdingTarget) m.drop(); + } + Matter.Body.setVelocity(player, { + x: 0, + y: -55 * player.mass * simulation.g //undo gravity before it is added + }); + player.force.x = 0 + player.force.y = 0 + } + b.guns[b.activeGun].do(); + } + }, + fireWithAmmo() { //triggers after firing when you have ammo + b.guns[b.activeGun].fire(); + if (tech.crouchAmmoCount && m.crouch) { + if (tech.crouchAmmoCount % 2) { + b.guns[b.activeGun].ammo--; + if (level.is2xAmmo && b.guns[b.activeGun].ammo > 0) b.guns[b.activeGun].ammo--; + simulation.updateGunHUD(); + } + tech.crouchAmmoCount++ //makes the no ammo toggle off and on + } else { + b.guns[b.activeGun].ammo--; + if (level.is2xAmmo && b.guns[b.activeGun].ammo > 0) b.guns[b.activeGun].ammo--; + simulation.updateGunHUD(); + } + }, + outOfAmmo() { //triggers after firing when you have NO ammo + simulation.inGameConsole(`${b.guns[b.activeGun].name}.ammo: 0`); + m.fireCDcycle = m.cycle + 30; //fire cooldown + if (tech.isAmmoFromHealth) { + const amount = 0.02 + if (tech.isEnergyHealth) { + if (m.maxEnergy > amount * 2) { + tech.healMaxEnergyBonus -= amount * 2 + m.setMaxEnergy(); + for (let i = 0; i < 4; i++) powerUps.spawn(m.pos.x + 50 * (Math.random() - 0.5), m.pos.y + 50 * (Math.random() - 0.5), "ammo"); + } + } else { + if (m.health > amount) { + tech.extraMaxHealth -= amount //decrease max health + m.setMaxHealth(); + for (let i = 0; i < 4; i++) powerUps.spawn(m.pos.x + 50 * (Math.random() - 0.5), m.pos.y + 50 * (Math.random() - 0.5), "ammo"); + } + } + } + }, + refundAmmo() { //triggers after firing when you removed ammo for a gun, but didn't need to + if (tech.crouchAmmoCount && m.crouch && (b.activeGun !== null && b.activeGun !== undefined)) { + tech.crouchAmmoCount-- + if ((tech.crouchAmmoCount) % 2) { + b.guns[b.activeGun].ammo++; + simulation.updateGunHUD(); + } + } else { + b.guns[b.activeGun].ammo++; + simulation.updateGunHUD(); + } + }, + // returnGunAmmo(name) { + // for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + // if (b.guns[i].name === name) return b.guns[i].ammo + // } + // }, + giveGuns(gun = "random", ammoPacks = 22) { + if (tech.ammoCap) ammoPacks = tech.ammoCap + if (tech.isOneGun) b.resetAllGuns(); + if (gun === "random") { + //find what guns player doesn't have + options = [] + for (let i = 0, len = b.guns.length; i < len; i++) { + if (!b.guns[i].have) options.push(i) + } + if (options.length === 0) return + //randomly pick from list of possible guns + gun = options[Math.floor(Math.random() * options.length)] + } + if (gun === "all") { + for (let i = 0; i < b.guns.length; i++) { + b.inventory[i] = i; + b.guns[i].have = true; + if (b.guns[i].ammo !== Infinity) b.guns[i].ammo = Math.ceil(b.guns[i].ammoPack * ammoPacks); + } + b.inventoryGun = 0; + b.activeGun = b.inventory[0]; + } else { + if (isNaN(gun)) { //find gun by name + let found = false; + for (let i = 0; i < b.guns.length; i++) { + if (gun === b.guns[i].name) { + gun = i + found = true; + break + } + } + if (!found) return //if no gun found don't give a gun + } + if (!b.guns[gun].have) b.inventory.push(gun); + b.guns[gun].have = true; + if (b.guns[gun].ammo !== Infinity) b.guns[gun].ammo = Math.ceil(b.guns[gun].ammoPack * ammoPacks); + if (b.activeGun === null) { + b.inventoryGun = 0; + b.activeGun = b.inventory[0] //if no active gun switch to new gun + if (b.guns[b.activeGun].charge) b.guns[b.activeGun].charge = 0; //set foam charge to zero if foam is a new gun + } + } + simulation.makeGunHUD(); + simulation.switchGun(); + b.setFireCD(); + if (tech.isOneGun && b.inventory > 0) { + //count how many gun tech you have and remove them + let gunTechCount = 0 //2 bonus gun tech + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isGunTech && tech.tech[i].count > 0 && !tech.tech[i].isInstant && !tech.tech[i].isRemoveGun) { + const remove = tech.removeTech(i) + gunTechCount += remove + } + } + + //get a random gun tech for your gun + for (let i = 0; i < gunTechCount; i++) { + const gunTechPool = [] + for (let j = 0, len = tech.tech.length; j < len; j++) { + if (tech.tech[j].isGunTech && tech.tech[j].allowed() && !tech.tech[i].isRemoveGun && !tech.tech[j].isJunk && !tech.tech[j].isBadRandomOption && tech.tech[j].count < tech.tech[j].maxCount) { + const regex = tech.tech[j].requires.search(b.guns[b.activeGun].name) //get string index of gun name + const not = tech.tech[j].requires.search(' not ') //get string index of ' not ' + //look for the gun name in the requirements, but the gun name needs to show up before the word ' not ' + if (regex !== -1 && (not === -1 || not > regex)) gunTechPool.push(j) + } + } + if (gunTechPool.length) { + const index = Math.floor(Math.random() * gunTechPool.length) + simulation.inGameConsole(`tech.giveTech("${tech.tech[gunTechPool[index]].name}")`) + tech.giveTech(gunTechPool[index]) // choose from the gun pool + } else { + tech.giveTech() //get normal tech if you can't find any gun tech + } + } + + } + }, + removeGun(gunName) { + for (let i = 0; i < b.guns.length; i++) { + if (b.guns[i].name === gunName && b.guns[i].have) { + b.guns[i].have = false + for (let j = 0; j < b.inventory.length; j++) { + if (b.inventory[j] === i) { + b.inventory.splice(j, 1) + break + } + } + if (b.inventory.length > 0) { + b.activeGun = b.inventory[0]; + } else { + b.activeGun = null; + } + b.inventoryGun = 0; + simulation.makeGunHUD(); + break + } + } + b.setFireCD(); + }, + resetAllGuns() { + b.inventory = []; //removes guns and ammo + for (let i = 0, len = b.guns.length; i < len; ++i) { + b.guns[i].count = 0; + b.guns[i].have = false; + b.guns[i].ammoPack = b.guns[i].defaultAmmoPack; + if (b.guns[i].ammo != Infinity) b.guns[i].ammo = 0; + } + tech.buffedGun = 0 + b.activeGun = null; + b.inventoryGun = 0; + simulation.drawCursor = simulation.drawCursorBasic //set cross hairs + }, + bulletRemove() { //run in main loop + //remove bullet if at end cycle for that bullet + let i = bullet.length; + while (i--) { + if (bullet[i].endCycle < simulation.cycle) { + bullet[i].onEnd(i); //some bullets do stuff on end + if (bullet[i]) { + Matter.Composite.remove(engine.world, bullet[i]); + bullet.splice(i, 1); + } else { + break; //if bullet[i] doesn't exist don't complete the for loop, because the game probably reset + } + } + } + }, + bulletDraw() { + ctx.beginPath(); + for (let i = 0, len = bullet.length; i < len; i++) { + let vertices = bullet[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j += 1) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + } + ctx.fillStyle = color.bullet; + ctx.fill(); + }, + bulletDo() { + for (let i = 0, len = bullet.length; i < len; i++) { + bullet[i].do(); + } + }, + fireProps(cd, speed, dir, me) { + m.fireCDcycle = m.cycle + Math.floor(cd * b.fireCDscale); // cool down + Matter.Body.setVelocity(bullet[me], { + x: 0.5 * player.velocity.x + speed * Math.cos(dir), + y: 0.5 * player.velocity.y + speed * Math.sin(dir) + }); + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + fireCDscale: 1, + setFireCD() { + b.fireCDscale = tech.fireRate * tech.slowFire * tech.researchHaste * tech.aimDamage + if (m.fieldMode === 6) b.fireCDscale *= 0.8 + if (tech.isFastTime) b.fireCDscale *= 0.666 + if (tech.isFireRateForGuns) b.fireCDscale *= Math.pow(0.76923, Math.max(0, b.inventory.length - 1)) + if (tech.isFireMoveLock) b.fireCDscale *= 0.25 + }, + fireAttributes(dir, rotate = true) { + if (rotate) { + return { + // density: 0.0015, //frictionAir: 0.01, //restitution: 0, + angle: dir, + friction: 0.5, + frictionAir: 0, + dmg: 0, //damage done in addition to the damage from momentum + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield + }, + minDmgSpeed: 10, + beforeDmg() { }, //this.endCycle = 0 //triggers despawn + onEnd() { } + }; + } else { + return { + // density: 0.0015, //frictionAir: 0.01, //restitution: 0, + inertia: Infinity, //prevents rotation + angle: dir, + friction: 0.5, + frictionAir: 0, + dmg: 0, //damage done in addition to the damage from momentum + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield + }, + minDmgSpeed: 10, + beforeDmg() { }, //this.endCycle = 0 //triggers despawn + onEnd() { } + }; + } + }, + muzzleFlash(radius = 30) { + // ctx.fillStyle = "#fb0"; + // ctx.beginPath(); + // ctx.arc(m.pos.x + 35 * Math.cos(m.angle), m.pos.y + 35 * Math.sin(m.angle), radius, 0, 2 * Math.PI); + // ctx.fill(); + + simulation.drawList.push({ //add dmg to draw queue + x: m.pos.x + 20 * Math.cos(m.angle), + y: m.pos.y + 20 * Math.sin(m.angle), + radius: radius, + color: "#fb0", + time: 1 + }); + }, + removeConsBB(me) { + for (let i = 0, len = consBB.length; i < len; ++i) { + if (consBB[i].bodyA === me) { + consBB[i].bodyA = consBB[i].bodyB; + consBB.splice(i, 1); + break; + } else if (consBB[i].bodyB === me) { + consBB[i].bodyB = consBB[i].bodyA; + consBB.splice(i, 1); + break; + } + } + }, + onCollision(event) { + const pairs = event.pairs; + for (let i = 0, j = pairs.length; i != j; i++) { + //map + bullet collisions + if (pairs[i].bodyA.collisionFilter.category === cat.map && pairs[i].bodyB.collisionFilter.category === cat.bullet) { + collideBulletStatic(pairs[i].bodyB) + } else if (pairs[i].bodyB.collisionFilter.category === cat.map && pairs[i].bodyA.collisionFilter.category === cat.bullet) { + collideBulletStatic(pairs[i].bodyA) + } + + function collideBulletStatic(obj) { + if (obj.onWallHit) obj.onWallHit(); + } + } + }, + explosionRange() { + return tech.explosiveRadius * (tech.isExplosionHarm ? 1.7 : 1) * (tech.isSmallExplosion ? 0.7 : 1) * (tech.isExplodeRadio ? 1.25 : 1) + }, + explosion(where, radius, color = "rgba(255,25,0,0.6)", reducedKnock = 1) { // typically explode is used for some bullets with .onEnd + radius *= tech.explosiveRadius + + let knock; + let dmg = radius * 0.019 + if (tech.isExplosionHarm) radius *= 1.7 // 1/sqrt(2) radius -> area + if (tech.isSmallExplosion) { + // color = "rgba(255,0,30,0.7)" + radius *= 0.7 + dmg *= 1.7 + } + let sub = Vector.sub(where, player.position); + let dist = Vector.magnitude(sub); + if (tech.isSmartRadius && radius > dist - 50) radius = Math.max(dist - 50, 1) + + if (tech.isExplodeRadio) { //radiation explosion + radius *= 1.25; //alert range + // if (tech.isSmartRadius) radius = Math.max(Math.min(radius, Vector.magnitude(Vector.sub(where, player.position)) - 25), 1) + color = "rgba(25,139,170,0.25)" + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: radius, + color: color, + time: simulation.drawTime * 2 + }); + + //player damage + if (Vector.magnitude(Vector.sub(where, player.position)) < radius) { + const DRAIN = (tech.isExplosionHarm ? 0.6 : 0.45) * (tech.isRadioactiveResistance ? 0.2 : 1) + if (m.immuneCycle < m.cycle) m.energy -= DRAIN + if (m.energy < 0) { + m.energy = 0 + if (simulation.dmgScale) m.damage(tech.radioactiveDamage * 0.03 * (tech.isRadioactiveResistance ? 0.2 : 1)); + } + } + + //mob damage and knock back with alert + let damageScale = 1.5; // reduce dmg for each new target to limit total AOE damage + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && !mob[i].isShielded) { + sub = Vector.sub(where, mob[i].position); + dist = Vector.magnitude(sub) - mob[i].radius; + if (dist < radius) { + if (mob[i].shield) dmg *= 2.5 //balancing explosion dmg to shields + if (Matter.Query.ray(map, mob[i].position, where).length > 0) dmg *= 0.5 //reduce damage if a wall is in the way + mobs.statusDoT(mob[i], dmg * damageScale * 0.25, 240) //apply radiation damage status effect on direct hits + if (tech.isStun) mobs.statusStun(mob[i], 30) + mob[i].locatePlayer(); + damageScale *= 0.87 //reduced damage for each additional explosion target + } + } + } + } else { //normal explosions + // if (tech.isSmartRadius) radius = Math.max(Math.min(radius, Vector.magnitude(Vector.sub(where, player.position)) - 25), 1) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: radius, + color: color, + time: simulation.drawTime + }); + const alertRange = 100 + radius * 2; //alert range + simulation.drawList.push({ //add alert to draw queue + x: where.x, + y: where.y, + radius: alertRange, + color: "rgba(100,20,0,0.03)", + time: simulation.drawTime + }); + + //player damage and knock back + if (m.immuneCycle < m.cycle) { + if (dist < radius) { + if (simulation.dmgScale) { + const harm = tech.isExplosionHarm ? 0.067 : 0.05 + if (tech.isImmuneExplosion && m.energy > 0.25) { + // const mitigate = Math.min(1, Math.max(1 - m.energy * 0.5, 0)) + m.energy -= 0.25 + // m.damage(0.01 * harm); //remove 99% of the damage 1-0.99 + knock = Vector.mult(Vector.normalise(sub), -0.6 * player.mass * Math.max(0, Math.min(0.15 - 0.002 * player.speed, 0.15))); + player.force.x = knock.x; // not += so crazy forces can't build up with MIRV + player.force.y = knock.y - 0.3; //some extra vertical kick + } else { + if (simulation.dmgScale) m.damage(harm); + knock = Vector.mult(Vector.normalise(sub), -Math.sqrt(dmg) * player.mass * 0.013); + player.force.x += knock.x; + player.force.y += knock.y; + } + } + } else if (dist < alertRange) { + knock = Vector.mult(Vector.normalise(sub), -Math.sqrt(dmg) * player.mass * 0.005); + player.force.x += knock.x; + player.force.y += knock.y; + } + } + + //body knock backs + for (let i = body.length - 1; i > -1; i--) { + if (!body[i].isNotHoldable) { + sub = Vector.sub(where, body[i].position); + dist = Vector.magnitude(sub); + if (dist < radius) { + knock = Vector.mult(Vector.normalise(sub), -Math.sqrt(dmg) * body[i].mass * 0.022); + body[i].force.x += knock.x; + body[i].force.y += knock.y; + if (tech.isBlockExplode) { + if (body[i] === m.holdingTarget) m.drop() + const size = 20 + 300 * Math.pow(body[i].mass, 0.25) + const where = body[i].position + const onLevel = level.onLevel //prevent explosions in the next level + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + setTimeout(() => { + if (onLevel === level.onLevel) b.explosion(where, size); //makes bullet do explosive damage at end + }, 250 + 300 * Math.random()); + } + } else if (dist < alertRange) { + knock = Vector.mult(Vector.normalise(sub), -Math.sqrt(dmg) * body[i].mass * 0.011); + body[i].force.x += knock.x; + body[i].force.y += knock.y; + } + } + } + + //power up knock backs + for (let i = 0, len = powerUp.length; i < len; ++i) { + sub = Vector.sub(where, powerUp[i].position); + dist = Vector.magnitude(sub); + if (dist < radius) { + knock = Vector.mult(Vector.normalise(sub), -Math.sqrt(dmg) * powerUp[i].mass * 0.013); + powerUp[i].force.x += knock.x; + powerUp[i].force.y += knock.y; + } else if (dist < alertRange) { + knock = Vector.mult(Vector.normalise(sub), -Math.sqrt(dmg) * powerUp[i].mass * 0.007); + powerUp[i].force.x += knock.x; + powerUp[i].force.y += knock.y; + } + } + + //mob damage and knock back with alert + let damageScale = 1.5; // reduce dmg for each new target to limit total AOE damage + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && !mob[i].isShielded) { + sub = Vector.sub(where, mob[i].position); + dist = Vector.magnitude(sub) - mob[i].radius; + if (dist < radius) { + if (mob[i].shield) dmg *= 2.5 //balancing explosion dmg to shields + if (Matter.Query.ray(map, mob[i].position, where).length > 0) dmg *= 0.5 //reduce damage if a wall is in the way + mob[i].damage(dmg * damageScale * m.dmgScale); + mob[i].locatePlayer(); + knock = Vector.mult(Vector.normalise(sub), -Math.sqrt(dmg * damageScale) * mob[i].mass * (mob[i].isBoss ? 0.003 : 0.01) * reducedKnock); + if (tech.isStun) { + mobs.statusStun(mob[i], 30) + } else if (!mob[i].isInvulnerable) { + mob[i].force.x += knock.x; + mob[i].force.y += knock.y; + } + radius *= 0.95 //reduced range for each additional explosion target + damageScale *= 0.87 //reduced damage for each additional explosion target + } else if (!mob[i].seePlayer.recall && dist < alertRange) { + mob[i].locatePlayer(); + knock = Vector.mult(Vector.normalise(sub), -Math.sqrt(dmg * damageScale) * mob[i].mass * (mob[i].isBoss ? 0 : 0.006 * reducedKnock)); + if (tech.isStun) { + mobs.statusStun(mob[i], 30) + } else if (!mob[i].isInvulnerable) { + mob[i].force.x += knock.x; + mob[i].force.y += knock.y; + } + } + } + } + } + }, + pulse(charge, angle = m.angle, where = m.pos) { + let best; + let explosionRadius = 5.5 * charge + let range = 5000 + const path = [{ + x: where.x + 20 * Math.cos(angle), + y: where.y + 20 * Math.sin(angle) + }, + { + x: where.x + range * Math.cos(angle), + y: where.y + range * Math.sin(angle) + } + ]; + //check for collisions + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + if (!best.who) { + best = vertexCollision(path[0], path[1], [mob, map, body]); + if (best.dist2 != Infinity) { //if hitting something + path[path.length - 1] = { + x: best.x, + y: best.y + }; + } + } + if (best.who) { + b.explosion(path[1], explosionRadius) + const off = explosionRadius * 1.2 + b.explosion({ + x: path[1].x + off * (Math.random() - 0.5), + y: path[1].y + off * (Math.random() - 0.5) + }, explosionRadius) + b.explosion({ + x: path[1].x + off * (Math.random() - 0.5), + y: path[1].y + off * (Math.random() - 0.5) + }, explosionRadius) + } + //draw laser beam + ctx.beginPath(); + ctx.moveTo(path[0].x, path[0].y); + ctx.lineTo(path[1].x, path[1].y); + if (charge > 50) { + ctx.strokeStyle = "rgba(255,0,0,0.10)" + ctx.lineWidth = 70 + ctx.stroke(); + } + ctx.strokeStyle = "rgba(255,0,0,0.25)" + ctx.lineWidth = 20 + ctx.stroke(); + ctx.strokeStyle = "#f00"; + ctx.lineWidth = 4 + ctx.stroke(); + + //draw little dots along the laser path + const sub = Vector.sub(path[1], path[0]) + const mag = Vector.magnitude(sub) + for (let i = 0, len = Math.floor(mag * 0.0005 * charge); i < len; i++) { + const dist = Math.random() + simulation.drawList.push({ + x: path[0].x + sub.x * dist + 10 * (Math.random() - 0.5), + y: path[0].y + sub.y * dist + 10 * (Math.random() - 0.5), + radius: 1.5 + 5 * Math.random(), + color: "rgba(255,0,0,0.5)", + time: Math.floor(9 + 25 * Math.random() * Math.random()) + }); + } + }, + clusterExplode(where, size) { //can occur after grenades detonate + const cycle = () => { + if (m.alive) { + if (simulation.paused || m.isTimeDilated) { + requestAnimationFrame(cycle) + } else { + count++ + if (count < 84) requestAnimationFrame(cycle); + if (!(count % 7)) { + const unit = Vector.rotate({ x: 1, y: 0 }, 6.28 * Math.random()) + b.explosion(Vector.add(where, Vector.mult(unit, size * (count * 0.01 + 0.03 * Math.random()))), size * (0.4 + Math.random() * 0.35), `hsla(${360 * Math.random()},100%,66%,0.6)`, 0.2); //makes bullet do explosive damage at end + } + } + } + } + let count = 7 + requestAnimationFrame(cycle); + }, + starburst(where, size) { //can occur after grenades detonate + const color = `hsla(${360 * Math.random()},100%,66%,0.6)` + const cycle = () => { + if (m.alive) { + if (simulation.paused || m.isTimeDilated) { + requestAnimationFrame(cycle) + } else { + count++ + if (count < 21) requestAnimationFrame(cycle); + if (count % 2) { + const unit = Vector.rotate({ + x: 1, + y: 0 + }, curl * 6.28 * count / 18 + off) + b.explosion(Vector.add(where, Vector.mult(unit, size * 0.75)), size * 0.7, color, 0.5); //makes bullet do explosive damage at end + } + } + } + } + const off = 6 * Math.random() + const curl = Math.random() < 0.5 ? -1 : 1; + let count = 0 + requestAnimationFrame(cycle); + }, + fireFlower(where, size) { //can occur after grenades detonate + // size *= b.explosionRange() + const range = size * Math.sqrt(b.explosionRange()) + const cycle = () => { + if (m.alive) { + if (simulation.paused || m.isTimeDilated) { + requestAnimationFrame(cycle) + } else { + if (count < 30 && m.alive) requestAnimationFrame(cycle); + if (count === 0) { + const color = `hsla(${360 * Math.random()},100%,66%,0.6)` + b.explosion(where, size * 0.8, color, 0.5); + } + if (count === 8) { + const color = `hsla(${360 * Math.random()},100%,66%,0.6)` + for (let i = 0, len = 6; i < len; i++) { + const unit = Vector.rotate({ + x: 1, + y: 0 + }, 6.28 * i / len) + b.explosion(Vector.add(where, Vector.mult(unit, 1.1 * range)), size * 0.6, color, 0.5); //makes bullet do explosive damage at end + } + } + if (count === 16) { + const color = `hsla(${360 * Math.random()},100%,66%,0.6)` + for (let i = 0, len = 10; i < len; i++) { + const unit = Vector.rotate({ + x: 1, + y: 0 + }, 6.28 * i / len) + b.explosion(Vector.add(where, Vector.mult(unit, 1.4 * range)), size * 0.45, color, 0.5); //makes bullet do explosive damage at end + } + } + count++ + } + } + } + let count = 0 + requestAnimationFrame(cycle); + }, + grenadeEnd() { + if (tech.isCircleExplode) { + b.starburst(this.position, this.explodeRad) + } else if (tech.isPetalsExplode) { + b.fireFlower(this.position, this.explodeRad) + } else if (tech.isClusterExplode) { + b.clusterExplode(this.position, this.explodeRad) + } else { + b.explosion(this.position, this.explodeRad); //makes bullet do explosive damage at end + } + if (tech.fragments) b.targetedNail(this.position, tech.fragments * Math.floor(2 + 1.5 * Math.random())) + }, + grenade() { + + }, + setGrenadeMode() { + grenadeDefault = function (where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }, angle = m.angle, size = 1) { + const me = bullet.length; + bullet[me] = Bodies.circle(where.x, where.y, 15, b.fireAttributes(angle, false)); + Matter.Body.setDensity(bullet[me], 0.0003); + bullet[me].explodeRad = 300 * size + 100 * tech.isBlockExplode; + bullet[me].onEnd = b.grenadeEnd + bullet[me].minDmgSpeed = 1; + bullet[me].beforeDmg = function () { + this.endCycle = 0; //bullet ends cycle after doing damage //this also triggers explosion + }; + speed = m.crouch ? 43 : 32 + Matter.Body.setVelocity(bullet[me], { + x: 0.5 * player.velocity.x + speed * Math.cos(angle), + y: 0.5 * player.velocity.y + speed * Math.sin(angle) + }); + bullet[me].endCycle = simulation.cycle + Math.floor(m.crouch ? 120 : 80) * tech.bulletsLastLonger; + bullet[me].restitution = 0.4; + bullet[me].do = function () { + this.force.y += this.mass * 0.0025; //extra gravity for harder arcs + }; + Composite.add(engine.world, bullet[me]); //add bullet to world + } + grenadeRPG = function (where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }, angle = m.angle, size = 1) { + const me = bullet.length; + bullet[me] = Bodies.circle(where.x, where.y, 15, b.fireAttributes(angle, false)); + Matter.Body.setDensity(bullet[me], 0.0003); + bullet[me].explodeRad = 300 * size + 100 * tech.isBlockExplode; + bullet[me].onEnd = b.grenadeEnd + bullet[me].minDmgSpeed = 1; + bullet[me].beforeDmg = function () { + this.endCycle = 0; //bullet ends cycle after doing damage //this also triggers explosion + }; + speed = m.crouch ? 46 : 32 + Matter.Body.setVelocity(bullet[me], { + x: 0.8 * player.velocity.x + speed * Math.cos(angle), + y: 0.5 * player.velocity.y + speed * Math.sin(angle) + }); + Composite.add(engine.world, bullet[me]); //add bullet to world + + bullet[me].endCycle = simulation.cycle + 70 * tech.bulletsLastLonger; + bullet[me].frictionAir = 0.07; + const MAG = 0.015 + bullet[me].thrust = { + x: bullet[me].mass * MAG * Math.cos(angle), + y: bullet[me].mass * MAG * Math.sin(angle) + } + bullet[me].do = function () { + this.force.x += this.thrust.x; + this.force.y += this.thrust.y; + if (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length) { + this.endCycle = 0; //explode if touching map or blocks + } + }; + } + grenadeRPGVacuum = function (where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }, angle = m.angle, size = 1) { + const me = bullet.length; + bullet[me] = Bodies.circle(where.x, where.y, 15, b.fireAttributes(angle, false)); + Matter.Body.setDensity(bullet[me], 0.0003); + bullet[me].explodeRad = 350 * size + Math.floor(Math.random() * 50) + tech.isBlockExplode * 100 + bullet[me].onEnd = b.grenadeEnd + bullet[me].minDmgSpeed = 1; + bullet[me].beforeDmg = function () { + this.endCycle = 0; //bullet ends cycle after doing damage //this also triggers explosion + }; + speed = m.crouch ? 46 : 32 + Matter.Body.setVelocity(bullet[me], { + x: 0.8 * player.velocity.x + speed * Math.cos(angle), + y: 0.5 * player.velocity.y + speed * Math.sin(angle) + }); + Composite.add(engine.world, bullet[me]); //add bullet to world + bullet[me].endCycle = simulation.cycle + 70 * tech.bulletsLastLonger; + bullet[me].frictionAir = 0.07; + bullet[me].suckCycles = 40 + const MAG = 0.015 + bullet[me].thrust = { + x: bullet[me].mass * MAG * Math.cos(angle), + y: bullet[me].mass * MAG * Math.sin(angle) + } + bullet[me].suck = function () { + const suck = (who, radius = this.explodeRad * 3.2) => { + for (i = 0, len = who.length; i < len; i++) { + const sub = Vector.sub(this.position, who[i].position); + const dist = Vector.magnitude(sub); + if (dist < radius && dist > 150 && !who.isInvulnerable && who[i] !== this) { + knock = Vector.mult(Vector.normalise(sub), mag * who[i].mass / Math.sqrt(dist)); + who[i].force.x += knock.x; + who[i].force.y += knock.y; + } + } + } + let mag = 0.1 + if (simulation.cycle > this.endCycle - 5) { + mag = -0.22 + suck(mob, this.explodeRad * 3) + suck(body, this.explodeRad * 2) + suck(powerUp, this.explodeRad * 1.5) + suck(bullet, this.explodeRad * 1.5) + suck([player], this.explodeRad * 1.3) + } else { + mag = 0.11 + suck(mob, this.explodeRad * 3) + suck(body, this.explodeRad * 2) + suck(powerUp, this.explodeRad * 1.5) + suck(bullet, this.explodeRad * 1.5) + suck([player], this.explodeRad * 1.3) + } + + Matter.Body.setVelocity(this, { x: 0, y: 0 }); //keep bomb in place + //draw suck + const radius = 2.75 * this.explodeRad * (this.endCycle - simulation.cycle) / this.suckCycles + ctx.fillStyle = "rgba(0,0,0,0.1)"; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, radius, 0, 2 * Math.PI); + ctx.fill(); + } + bullet[me].do = function () { + if (simulation.cycle > this.endCycle - this.suckCycles) { //suck + this.do = this.suck + } else if (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length) { + Matter.Body.setPosition(this, Vector.sub(this.position, this.velocity)) //undo last movement + this.do = this.suck + } else { + this.force.x += this.thrust.x; + this.force.y += this.thrust.y; + } + }; + } + grenadeVacuum = function (where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }, angle = m.angle, size = 1) { + const me = bullet.length; + bullet[me] = Bodies.circle(where.x, where.y, 20, b.fireAttributes(angle, false)); + Matter.Body.setDensity(bullet[me], 0.0002); + bullet[me].explodeRad = 350 * size + Math.floor(Math.random() * 50) + tech.isBlockExplode * 100 + bullet[me].onEnd = b.grenadeEnd + bullet[me].beforeDmg = function () { + this.endCycle = 0; //bullet ends cycle after doing damage //this also triggers explosion + }; + bullet[me].restitution = 0.4; + bullet[me].do = function () { + this.force.y += this.mass * 0.0025; //extra gravity for harder arcs + + const suckCycles = 40 + if (simulation.cycle > this.endCycle - suckCycles) { //suck + const that = this + + function suck(who, radius = that.explodeRad * 3.2) { + for (i = 0, len = who.length; i < len; i++) { + const sub = Vector.sub(that.position, who[i].position); + const dist = Vector.magnitude(sub); + if (dist < radius && dist > 150 && !who.isInvulnerable) { + knock = Vector.mult(Vector.normalise(sub), mag * who[i].mass / Math.sqrt(dist)); + who[i].force.x += knock.x; + who[i].force.y += knock.y; + } + } + } + let mag = 0.1 + if (simulation.cycle > this.endCycle - 5) { + mag = -0.22 + suck(mob, this.explodeRad * 3) + suck(body, this.explodeRad * 2) + suck(powerUp, this.explodeRad * 1.5) + suck(bullet, this.explodeRad * 1.5) + suck([player], this.explodeRad * 1.3) + } else { + mag = 0.11 + suck(mob, this.explodeRad * 3) + suck(body, this.explodeRad * 2) + suck(powerUp, this.explodeRad * 1.5) + suck(bullet, this.explodeRad * 1.5) + suck([player], this.explodeRad * 1.3) + } + //keep bomb in place + Matter.Body.setVelocity(this, { + x: 0, + y: 0 + }); + //draw suck + const radius = 2.75 * this.explodeRad * (this.endCycle - simulation.cycle) / suckCycles + ctx.fillStyle = "rgba(0,0,0,0.1)"; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, radius, 0, 2 * Math.PI); + ctx.fill(); + } + }; + speed = 35 + // speed = m.crouch ? 43 : 32 + + bullet[me].endCycle = simulation.cycle + 70 * tech.bulletsLastLonger; + if (m.crouch) { + speed += 9 + bullet[me].endCycle += 20; + } + Matter.Body.setVelocity(bullet[me], { + x: 0.5 * player.velocity.x + speed * Math.cos(angle), + y: 0.5 * player.velocity.y + speed * Math.sin(angle) + }); + Composite.add(engine.world, bullet[me]); //add bullet to world + } + + grenadeNeutron = function (where = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) }, angle = m.angle, size = 1) { + const me = bullet.length; + bullet[me] = Bodies.polygon(where.x, where.y, 10, 4, b.fireAttributes(angle, false)); + b.fireProps((m.crouch ? 45 : 25) / Math.pow(0.92, tech.missileCount), m.crouch ? 35 : 20, angle, me); //cd , speed + Matter.Body.setDensity(bullet[me], 0.000001); + bullet[me].endCycle = 500 + simulation.cycle; + bullet[me].frictionAir = 0; + bullet[me].friction = 1; + bullet[me].frictionStatic = 1; + bullet[me].restitution = 0; + bullet[me].minDmgSpeed = 0; + bullet[me].damageRadius = 100; + bullet[me].maxDamageRadius = 450 * size + 130 * tech.isNeutronSlow //+ 150 * Math.random() + bullet[me].radiusDecay = (0.81 + 0.15 * tech.isNeutronSlow) / tech.bulletsLastLonger + bullet[me].stuckTo = null; + bullet[me].stuckToRelativePosition = null; + if (tech.isRPG) { + const SCALE = 2 + Matter.Body.scale(bullet[me], SCALE, SCALE); + speed = m.crouch ? 25 : 15 + // speed = m.crouch ? 43 : 32 + Matter.Body.setVelocity(bullet[me], { x: 0.5 * player.velocity.x + speed * Math.cos(angle), y: 0.5 * player.velocity.y + speed * Math.sin(angle) }); + const MAG = 0.005 + bullet[me].thrust = { x: bullet[me].mass * MAG * Math.cos(angle), y: bullet[me].mass * MAG * Math.sin(angle) } + } + + bullet[me].beforeDmg = function () { }; + bullet[me].stuck = function () { }; + bullet[me].do = function () { + const onCollide = () => { + this.collisionFilter.mask = 0; //non collide with everything + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + if (tech.isRPG) this.thrust = { x: 0, y: 0 } + this.do = this.radiationMode; + } + const mobCollisions = Matter.Query.collides(this, mob) + if (mobCollisions.length) { + onCollide() + this.stuckTo = mobCollisions[0].bodyA + mobs.statusDoT(this.stuckTo, 0.6, 360) //apply radiation damage status effect on direct hits + if (this.stuckTo.isVerticesChange) { + this.stuckToRelativePosition = { x: 0, y: 0 } + } else { + //find the relative position for when the mob is at angle zero by undoing the mobs rotation + this.stuckToRelativePosition = Vector.rotate(Vector.sub(this.position, this.stuckTo.position), -this.stuckTo.angle) + } + this.stuck = function () { + if (this.stuckTo && this.stuckTo.alive) { + const rotate = Vector.rotate(this.stuckToRelativePosition, this.stuckTo.angle) //add in the mob's new angle to the relative position vector + Matter.Body.setPosition(this, Vector.add(Vector.add(rotate, this.stuckTo.velocity), this.stuckTo.position)) + Matter.Body.setVelocity(this, this.stuckTo.velocity); //so that it will move properly if it gets unstuck + } else { + this.collisionFilter.mask = cat.map | cat.body | cat.player | cat.mob; //non collide with everything but map + this.stuck = function () { + this.force.y += this.mass * 0.001; + } + } + } + } else { + const bodyCollisions = Matter.Query.collides(this, body) + if (bodyCollisions.length) { + if (!bodyCollisions[0].bodyA.isNotHoldable) { + onCollide() + this.stuckTo = bodyCollisions[0].bodyA + //find the relative position for when the mob is at angle zero by undoing the mobs rotation + this.stuckToRelativePosition = Vector.rotate(Vector.sub(this.position, this.stuckTo.position), -this.stuckTo.angle) + } else { + this.do = this.radiationMode; + } + this.stuck = function () { + if (this.stuckTo) { + const rotate = Vector.rotate(this.stuckToRelativePosition, this.stuckTo.angle) //add in the mob's new angle to the relative position vector + Matter.Body.setPosition(this, Vector.add(Vector.add(rotate, this.stuckTo.velocity), this.stuckTo.position)) + // Matter.Body.setVelocity(this, this.stuckTo.velocity); //so that it will move properly if it gets unstuck + } else { + this.force.y += this.mass * 0.001; + } + } + } else { + if (Matter.Query.collides(this, map).length) { + onCollide() + } else if (tech.isRPG) { //if colliding with nothing + this.force.x += this.thrust.x; + this.force.y += this.thrust.y; + } else { + this.force.y += this.mass * 0.001; + } + } + } + } + bullet[me].radiationMode = function () { //the do code after the bullet is stuck on something, projects a damaging radiation field + this.stuck(); //runs different code based on what the bullet is stuck to + this.damageRadius = this.damageRadius * 0.85 + 0.15 * this.maxDamageRadius //smooth radius towards max + this.maxDamageRadius -= this.radiusDecay + if (this.damageRadius < 15) { + this.endCycle = 0; + } else { + //aoe damage to player + if (Vector.magnitude(Vector.sub(player.position, this.position)) < this.damageRadius) { + const DRAIN = (tech.isRadioactiveResistance ? 0.0025 * 0.2 : 0.0025) + if (m.energy > DRAIN) { + if (m.immuneCycle < m.cycle) m.energy -= DRAIN + } else { + m.energy = 0; + if (simulation.dmgScale) m.damage((tech.isRadioactiveResistance ? 0.00016 * 0.2 : 0.00016) * tech.radioactiveDamage) //0.00015 + } + } + //aoe damage to mobs + let dmg = m.dmgScale * 0.15 * tech.radioactiveDamage + for (let i = 0, len = mob.length; i < len; i++) { + if (Vector.magnitude(Vector.sub(mob[i].position, this.position)) < this.damageRadius + mob[i].radius) { + if (Matter.Query.ray(map, mob[i].position, this.position).length > 0) dmg *= 0.2 //reduce damage if a wall is in the way + mob[i].damage(mob[i].shield ? dmg * 3 : dmg); + mob[i].locatePlayer(); + if (tech.isNeutronSlow && mob[i].speed > 4) { + Matter.Body.setVelocity(mob[i], { x: mob[i].velocity.x * 0.97, y: mob[i].velocity.y * 0.97 }); + } + } + } + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.damageRadius, 0, 2 * Math.PI); + ctx.globalCompositeOperation = "lighter" + ctx.fillStyle = `rgba(25,139,170,${0.2 + 0.06 * Math.random()})`; + ctx.fill(); + ctx.globalCompositeOperation = "source-over" + if (tech.isNeutronSlow) { + let slow = (who, radius = this.explodeRad * 3.2) => { + for (i = 0, len = who.length; i < len; i++) { + const sub = Vector.sub(this.position, who[i].position); + const dist = Vector.magnitude(sub); + if (dist < radius) { + Matter.Body.setVelocity(who[i], { x: who[i].velocity.x * 0.975, y: who[i].velocity.y * 0.975 }); + } + } + } + slow(body, this.damageRadius) + slow([player], this.damageRadius) + } + } + } + } + + if (tech.isNeutronBomb) { + b.grenade = grenadeNeutron + if (tech.isRPG) { + b.guns[5].do = function () { } + } else { + b.guns[5].do = function () { + if (!input.field && m.crouch) { + const cycles = 80 + const speed = m.crouch ? 35 : 20 //m.crouch ? 43 : 32 + const g = m.crouch ? 0.137 : 0.135 + const v = { + x: speed * Math.cos(m.angle), + y: speed * Math.sin(m.angle) + } + ctx.strokeStyle = "rgba(68, 68, 68, 0.2)" //color.map + ctx.lineWidth = 2 + ctx.beginPath() + for (let i = 1, len = 19; i < len + 1; i++) { + const time = cycles * i / len + ctx.lineTo(m.pos.x + time * v.x, m.pos.y + time * v.y + g * time * time) + } + ctx.stroke() + } + } + } + } else if (tech.isRPG) { + b.guns[5].do = function () { } + if (tech.isVacuumBomb) { + b.grenade = grenadeRPGVacuum + } else { + b.grenade = grenadeRPG + } + } else if (tech.isVacuumBomb) { + b.grenade = grenadeVacuum + b.guns[5].do = function () { + if (!input.field && m.crouch) { + const cycles = Math.floor(m.crouch ? 50 : 30) //30 + const speed = m.crouch ? 44 : 35 + const v = { x: speed * Math.cos(m.angle), y: speed * Math.sin(m.angle) } + ctx.strokeStyle = "rgba(68, 68, 68, 0.2)" //color.map + ctx.lineWidth = 2 + ctx.beginPath() + for (let i = 1.6, len = 19; i < len + 1; i++) { + const time = cycles * i / len + ctx.lineTo(m.pos.x + time * v.x, m.pos.y + time * v.y + 0.34 * time * time) + } + ctx.stroke() + } + } + } else { + b.grenade = grenadeDefault + b.guns[5].do = function () { + if (!input.field && m.crouch) { + const cycles = Math.floor(m.crouch ? 120 : 80) //30 + const speed = m.crouch ? 43 : 32 + const v = { x: speed * Math.cos(m.angle), y: speed * Math.sin(m.angle) } //m.Vy / 2 + removed to make the path less jerky + ctx.strokeStyle = "rgba(68, 68, 68, 0.2)" //color.map + ctx.lineWidth = 2 + ctx.beginPath() + for (let i = 0.5, len = 19; i < len + 1; i++) { + const time = cycles * i / len + ctx.lineTo(m.pos.x + time * v.x, m.pos.y + time * v.y + 0.34 * time * time) + } + ctx.stroke() + } + } + } + }, + grapple(where, angle = m.angle) { + const me = bullet.length; + const returnRadius = 100 + bullet[me] = Bodies.fromVertices(where.x, where.y, [{ + x: -40, + y: 2, + index: 0, + isInternal: false + }, { + x: -40, + y: -2, + index: 1, + isInternal: false + }, { + x: 37, + y: -2, + index: 2, + isInternal: false + }, { + x: 40, + y: -1, + index: 3, + isInternal: false + }, { + x: 37, + y: 3, + index: 4, + isInternal: false + }], + { + angle: angle, + friction: 1, + frictionAir: 0.4, + thrustMag: 0.13, + dmg: 8, //damage done in addition to the damage from momentum + classType: "bullet", + endCycle: simulation.cycle + 70, + isSlowPull: false, + drawStringControlMagnitude: 1000 + 1000 * Math.random(), + drawStringFlip: (Math.round(Math.random()) ? 1 : -1), + attached: false, + glowColor: tech.hookNails ? "rgba(200,0,0,0.07)" : tech.isHarmReduce ? "rgba(50,100,255,0.1)" : "rgba(0,200,255,0.07)", + collisionFilter: { + category: cat.bullet, + mask: tech.isShieldPierce ? cat.body | cat.mob | cat.mobBullet : cat.body | cat.mob | cat.mobBullet | cat.mobShield, + }, + minDmgSpeed: 4, + // lookFrequency: Math.floor(7 + Math.random() * 3), + density: 0.004, //0.001 is normal for blocks, 0.004 is normal for harpoon + drain: 0.001, + powerUpDamage: tech.isHarpoonPowerUp && simulation.cycle - 480 < tech.harpoonPowerUpCycle, + draw() { + // draw rope + const where = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) } + const sub = Vector.sub(where, this.vertices[0]) + ctx.strokeStyle = "#000" // "#0ce" + ctx.lineWidth = 0.5 + ctx.beginPath(); + ctx.moveTo(where.x, where.y); + if (this.attached) { + const controlPoint = Vector.add(where, Vector.mult(sub, -0.5)) + ctx.quadraticCurveTo(controlPoint.x, controlPoint.y, this.vertices[0].x, this.vertices[0].y) + } else { + const long = Math.max(Vector.magnitude(sub), 60) + const perpendicular = Vector.mult(Vector.normalise(Vector.perp(sub)), this.drawStringFlip * Math.min(0.7 * long, 10 + this.drawStringControlMagnitude / (10 + Vector.magnitude(sub)))) + const controlPoint = Vector.add(Vector.add(where, Vector.mult(sub, -0.5)), perpendicular) + ctx.quadraticCurveTo(controlPoint.x, controlPoint.y, this.vertices[0].x, this.vertices[0].y) + } + // ctx.lineTo(this.vertices[0].x, this.vertices[0].y); + // ctx.stroke(); + ctx.strokeStyle = this.glowColor // "#0ce" + ctx.lineWidth = 10 + ctx.stroke(); + ctx.strokeStyle = "#000" // "#0ce" + ctx.lineWidth = 0.5 + ctx.stroke(); + + if (this.powerUpDamage) { + ctx.beginPath(); + ctx.moveTo(this.vertices[0].x, this.vertices[0].y); + ctx.lineTo(this.vertices[1].x, this.vertices[1].y); + ctx.lineTo(this.vertices[2].x, this.vertices[2].y); + ctx.lineTo(this.vertices[3].x, this.vertices[3].y); + ctx.lineTo(this.vertices[4].x, this.vertices[4].y); + ctx.lineJoin = "miter" + ctx.miterLimit = 30; + ctx.lineWidth = 25; + ctx.strokeStyle = "rgba(0,255,255,0.4)"; + ctx.stroke(); + ctx.lineWidth = 8; + ctx.strokeStyle = "rgb(0,255,255)"; + ctx.stroke(); + ctx.lineJoin = "round" + ctx.miterLimit = 5 + ctx.fillStyle = "#000" + ctx.fill(); + } + //draw hook + ctx.beginPath(); + ctx.lineTo(this.vertices[0].x, this.vertices[0].y); + const spike = Vector.add(this.vertices[3], Vector.mult(Vector.sub(this.vertices[3], this.vertices[2]), 2)) + ctx.moveTo(this.vertices[2].x, this.vertices[2].y); + ctx.lineTo(spike.x, spike.y); + ctx.lineTo(this.vertices[1].x, this.vertices[1].y); + ctx.fillStyle = '#000' + ctx.fill(); + }, + beforeDmg(who) { + if (tech.isShieldPierce && who.isShielded) { //disable shields + who.isShielded = false + requestAnimationFrame(() => { who.isShielded = true }); + } + if (m.fieldCDcycle < m.cycle + 40) m.fieldCDcycle = m.cycle + 40 //extra long cooldown on hitting mobs + if (tech.hookNails) { + // if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + 5; //player is immune to damage for 5 cycles + // b.explosion(this.position, 300 + 150 * Math.random()); //makes bullet do explosive damage at end + b.targetedNail(this.position, tech.hookNails) + const ANGLE = 2 * Math.PI * Math.random() //make a few random ones + for (let i = 0; i < 4; i++) b.nail(this.position, { x: 10.5 * Math.cos(ANGLE), y: 10.5 * Math.sin(ANGLE) }, 1.2) + } + // if (this.powerUpDamage) this.density = 2 * 0.004 //double damage after pick up power up for 8 seconds + + + if (tech.isHarpoonPowerUp && simulation.cycle - 480 < tech.harpoonPowerUpCycle) { + Matter.Body.setDensity(this, 1.8 * 0.004); //+90% damage after pick up power up for 8 seconds + } else if (tech.isHarpoonFullHealth && who.health === 1) { + Matter.Body.setDensity(this, 2.11 * 0.004); //+90% damage if mob has full health do + simulation.ephemera.push({ + name: "grapple outline", + count: 3, //cycles before it self removes + vertices: this.vertices, + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + + ctx.beginPath(); + ctx.moveTo(this.vertices[0].x, this.vertices[0].y); + for (let j = 1, len = this.vertices.length; j < len; j += 1) ctx.lineTo(this.vertices[j].x, this.vertices[j].y); + ctx.lineTo(this.vertices[0].x, this.vertices[0].y); + ctx.lineJoin = "miter" + ctx.miterLimit = 20; + ctx.lineWidth = 40; + ctx.strokeStyle = "rgba(255,0,100,0.35)"; + ctx.stroke(); + ctx.lineWidth = 10; + ctx.strokeStyle = `#f07`; + ctx.stroke(); + ctx.lineJoin = "round" + ctx.miterLimit = 5 + ctx.fillStyle = "#000" + ctx.fill(); + }, + }) + } + + + this.retract() + }, + caughtPowerUp: null, + dropCaughtPowerUp() { + if (this.caughtPowerUp) { + this.caughtPowerUp.collisionFilter.category = cat.powerUp + this.caughtPowerUp.collisionFilter.mask = cat.map | cat.powerUp + this.caughtPowerUp = null + } + }, + onEnd() { + if (this.caughtPowerUp && !simulation.isChoosing && (this.caughtPowerUp.name !== "heal" || m.health !== m.maxHealth || tech.isOverHeal)) { + let index = null //find index + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (powerUp[i] === this.caughtPowerUp) index = i + } + if (index !== null) { + powerUps.onPickUp(this.caughtPowerUp); + this.caughtPowerUp.effect(); + Matter.Composite.remove(engine.world, this.caughtPowerUp); + powerUp.splice(index, 1); + if (tech.isHarpoonPowerUp) tech.harpoonPowerUpCycle = simulation.cycle + } else { + this.dropCaughtPowerUp() + } + } else { + this.dropCaughtPowerUp() + } + }, + retract() { + this.attached = false + this.do = this.returnToPlayer + this.endCycle = simulation.cycle + 60 + Matter.Body.setDensity(this, 0.0005); //reduce density on return + if (this.angularSpeed < 0.5) this.torque += this.inertia * 0.001 * (Math.random() - 0.5) //(Math.round(Math.random()) ? 1 : -1) + this.collisionFilter.mask = 0//cat.map | cat.mob | cat.mobBullet | cat.mobShield // | cat.body + //recoil on pulling grapple back + // if (this.pickUpTarget.mass) console.log(this.pickUpTarget.mass) + const mag = this.pickUpTarget ? Math.min(5, Math.max(this.pickUpTarget.mass, 0.5)) : 0.5 + const unit = Vector.normalise(Vector.sub(this.position, m.pos)) + const momentum = Vector.mult(unit, mag * (m.crouch ? 0.1 : 0.2)) + player.force.x += momentum.x + player.force.y += momentum.y + }, + returnToPlayer() { + if (m.fieldCDcycle < m.cycle + 5) m.fieldCDcycle = m.cycle + 5 + if (Vector.magnitude(Vector.sub(this.position, m.pos)) < returnRadius) { //near player + this.endCycle = 0; + //recoil on catching grapple + // const momentum = Vector.mult(Vector.sub(this.velocity, player.velocity), (m.crouch ? 0.0001 : 0.0002)) + const unit = Vector.normalise(Vector.sub(this.velocity, player.velocity)) + const momentum = Vector.mult(unit, (m.crouch ? 0.0001 : 0.0002)) + player.force.x += momentum.x + player.force.y += momentum.y + if (this.pickUpTarget) { + if (tech.isReel && this.blockDist > 150) { + // console.log(0.0003 * Math.min(this.blockDist, 1000)) + m.energy += 0.00113 * Math.min(this.blockDist, 800) * level.isReducedRegen //max 0.352 energy + simulation.drawList.push({ //add dmg to draw queue + x: m.pos.x, + y: m.pos.y, + radius: 10, + color: m.fieldMeterColor, + time: simulation.drawTime + }); + } + m.holdingTarget = this.pickUpTarget + // give block to player after it returns + m.isHolding = true; + //conserve momentum when player mass changes + const blockMass = Math.min(5, this.pickUpTarget.mass) + const grappleMomentum = Vector.mult(Vector.normalise(this.velocity), 15 * blockMass) + const playerMomentum = Vector.mult(player.velocity, player.mass) + totalMomentum = Vector.add(playerMomentum, grappleMomentum) + Matter.Body.setVelocity(player, Vector.mult(totalMomentum, 1 / (m.defaultMass + blockMass))); + + m.definePlayerMass(m.defaultMass + this.pickUpTarget.mass * m.holdingMassScale) + //make block collide with nothing + m.holdingTarget.collisionFilter.category = 0; + m.holdingTarget.collisionFilter.mask = 0; + this.pickUpTarget = null + } + } else { + if (m.energy > this.drain) m.energy -= this.drain + const sub = Vector.sub(this.position, m.pos) + const rangeScale = 1 + 0.000003 * Vector.magnitude(sub) //return faster when far from player + const returnForce = Vector.mult(Vector.normalise(sub), rangeScale * this.thrustMag * this.mass) + this.force.x -= returnForce.x + this.force.y -= returnForce.y + this.grabPowerUp() + this.grabBlocks() + } + this.draw(); + }, + destroyBlocks() {//not used? + const blocks = Matter.Query.collides(this, body) + if (blocks.length && !blocks[0].bodyA.isNotHoldable) { + if (blocks[0].bodyA.mass > 2.5) this.retract() + const block = blocks[0].bodyA.vertices + Composite.remove(engine.world, blocks[0].bodyA) + body.splice(body.indexOf(blocks[0].bodyA), 1) + //animate the block fading away + simulation.ephemera.push({ + name: "blockFadeOut", + count: 25, //cycles before it self removes + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + ctx.beginPath(); + ctx.moveTo(block[0].x, block[0].y); + for (let j = 1; j < block.length; j++) ctx.lineTo(block[j].x, block[j].y); + ctx.lineTo(block[0].x, block[0].y); + ctx.lineWidth = 2; + ctx.strokeStyle = `rgba(0,0,0,${this.count / 25})` + ctx.stroke(); + }, + }) + } + }, + pickUpTarget: null, + grabBlocks() { + if (this.pickUpTarget) { //if always attached to a block + //position block on hook + Matter.Body.setPosition(this.pickUpTarget, Vector.add(this.vertices[2], this.velocity)) + Matter.Body.setVelocity(this.pickUpTarget, { x: 0, y: 0 }) + } else { + const blocks = Matter.Query.collides(this, body) + if (blocks.length) { + for (let i = 0; i < blocks.length; i++) { + if (blocks[i].bodyA.classType === "body" && !blocks[i].bodyA.isNotHoldable && blocks[0].bodyA.mass < 40) { + this.retract() + if (tech.hookNails) { + b.targetedNail(this.position, 3 * tech.hookNails) + const ANGLE = 2 * Math.PI * Math.random() //make a few random ones + for (let i = 0; i < 13; i++) b.nail(this.position, { x: 10.5 * Math.cos(ANGLE), y: 10.5 * Math.sin(ANGLE) }, 1.2) + + const blockVertices = blocks[i].bodyA.vertices + Composite.remove(engine.world, blocks[i].bodyA) + body.splice(body.indexOf(blocks[i].bodyA), 1) + //animate the block fading away + simulation.ephemera.push({ + name: "blockFadeOut", + count: 25, //cycles before it self removes + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + ctx.beginPath(); + ctx.moveTo(blockVertices[0].x, blockVertices[0].y); + for (let j = 1; j < blockVertices.length; j++) ctx.lineTo(blockVertices[j].x, blockVertices[j].y); + ctx.lineTo(blockVertices[0].x, blockVertices[0].y); + ctx.lineWidth = 2; + ctx.strokeStyle = `rgba(0,0,0,${this.count / 25})` + ctx.stroke(); + }, + }) + } else { + this.pickUpTarget = blocks[i].bodyA + this.blockDist = Vector.magnitude(Vector.sub(this.pickUpTarget.position, m.pos)) + } + } + } + } + } + }, + grabPowerUp() { //grab power ups near the tip of the harpoon + if (this.caughtPowerUp) { + Matter.Body.setPosition(this.caughtPowerUp, Vector.add(this.vertices[2], this.velocity)) + Matter.Body.setVelocity(this.caughtPowerUp, { x: 0, y: 0 }) + } else { + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (tech.isEnergyNoAmmo && powerUp[i].name === "ammo") continue + const radius = powerUp[i].circleRadius + 50 + if (Vector.magnitudeSquared(Vector.sub(this.vertices[2], powerUp[i].position)) < radius * radius) { + if (powerUp[i].name !== "heal" || m.health !== m.maxHealth || tech.isOverHeal) { + this.caughtPowerUp = powerUp[i] + Matter.Body.setVelocity(powerUp[i], { x: 0, y: 0 }) + Matter.Body.setPosition(powerUp[i], this.vertices[2]) + powerUp[i].collisionFilter.category = 0 + powerUp[i].collisionFilter.mask = 0 + this.thrustMag *= 0.6 + this.endCycle += 0.5 //it pulls back slower, so this prevents it from ending early + // this.retract() + break //just pull 1 power up if possible + } + } + } + } + m.grabPowerUp(); + }, + do() { + if (m.fieldCDcycle < m.cycle + 5) m.fieldCDcycle = m.cycle + 5 + if (input.field) { + this.grabBlocks() + this.grabPowerUp() + } else { + this.retract() + } + //grappling hook + if (input.field && Matter.Query.collides(this, map).length) { + Matter.Body.setPosition(this, Vector.add(this.position, { x: -20 * Math.cos(this.angle), y: -20 * Math.sin(this.angle) })) + if (Matter.Query.collides(this, map).length) { + if (tech.hookNails) { + b.targetedNail(this.position, tech.hookNails) + const ANGLE = 2 * Math.PI * Math.random() //make a few random ones + for (let i = 0; i < 4; i++) b.nail(this.position, { x: 10.5 * Math.cos(ANGLE), y: 10.5 * Math.sin(ANGLE) }, 1.2) + + } + this.attached = true + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + Matter.Sleeping.set(this, true) + this.endCycle = simulation.cycle + 5 + this.do = () => { + if (m.fieldCDcycle < m.cycle + 5) m.fieldCDcycle = m.cycle + 5 + this.grabPowerUp() + + //between player nose and the grapple + const sub = Vector.sub(this.vertices[0], { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) }) + let dist = Vector.magnitude(sub) + if (input.field) { + this.endCycle = simulation.cycle + 10 + if (input.down) { //down + this.isSlowPull = true + dist = 0 + player.force.y += 3 * player.mass * simulation.g; //adjust this to control fall rate while hooked and pressing down + } else if (input.up) { + this.isSlowPull = false + player.force.y -= player.mass * simulation.g; //adjust this to control fall rate while hooked and pressing down + } + if (m.energy < this.drain) this.isSlowPull = true + + // pulling friction that allowed a slight swinging, but has high linear pull at short dist + const drag = 1 - 30 / Math.min(Math.max(100, dist), 700) - 0.1 * (player.speed > 66) + Matter.Body.setVelocity(player, { x: player.velocity.x * drag, y: player.velocity.y * drag }); + const pull = Vector.mult(Vector.normalise(sub), 0.0004 * Math.min(Math.max(15, dist), this.isSlowPull ? 70 : 200)) + //original pulling force with high friction and very linear pull + // Matter.Body.setVelocity(player, { x: player.velocity.x * 0.85, y: player.velocity.y * 0.85 }); + // const pull = Vector.mult(Vector.normalise(sub), 0.0008 * Math.min(Math.max(15, dist), this.isSlowPull ? 100 : 200)) + + player.force.x += pull.x + player.force.y += pull.y + if (dist > 500) m.energy -= this.drain + } else { + Matter.Sleeping.set(this, false) + this.retract() + } + this.draw(); + } + } + } + this.force.x += this.thrustMag * this.mass * Math.cos(this.angle); + this.force.y += this.thrustMag * this.mass * Math.sin(this.angle); + this.draw() + }, + }); + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + harpoon(where, target, angle = m.angle, harpoonSize = 1, isReturn = false, totalCycles = 35, isReturnAmmo = true, thrust = 0.1) { + const me = bullet.length; + const returnRadius = 100 * Math.sqrt(harpoonSize) + bullet[me] = Bodies.fromVertices(where.x, where.y, [{ + x: -40 * harpoonSize, + y: 2 * harpoonSize, + index: 0, + isInternal: false + }, { + x: -40 * harpoonSize, + y: -2 * harpoonSize, + index: 1, + isInternal: false + }, { + x: 50 * harpoonSize, + y: -3 * harpoonSize, + index: 3, + isInternal: false + }, { + x: 30 * harpoonSize, + y: 2 * harpoonSize, + index: 4, + isInternal: false + }], { + cycle: 0, + angle: angle, + friction: 1, + frictionAir: 0.4, + // thrustMag: 0.1, + drain: tech.isRailEnergy ? 0.0002 : 0.006, + turnRate: isReturn ? 0.1 : 0.03, //0.015 + drawStringControlMagnitude: 3000 + 5000 * Math.random(), + drawStringFlip: (Math.round(Math.random()) ? 1 : -1), + dmg: 6, //damage done in addition to the damage from momentum + classType: "bullet", + endCycle: simulation.cycle + totalCycles * 2.5 + 40, + collisionFilter: { + category: cat.bullet, + mask: tech.isShieldPierce ? cat.map | cat.body | cat.mob | cat.mobBullet : cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield, + }, + minDmgSpeed: 4, + lookFrequency: Math.floor(7 + Math.random() * 3), + density: tech.harpoonDensity, //0.001 is normal for blocks, 0.004 is normal for harpoon, 0.004*6 when buffed + foamSpawned: 0, + beforeDmg(who) { + if (tech.isShieldPierce && who.isShielded) { //disable shields + who.isShielded = false + requestAnimationFrame(() => { + who.isShielded = true + }); + } + if (tech.fragments) { + b.targetedNail(this.vertices[2], tech.fragments * Math.floor(2 + Math.random())) + if (!isReturn) this.endCycle = 0; + } + if (!who.isBadTarget) { + if (isReturn) { + this.do = this.returnToPlayer + } else { + this.frictionAir = 0.01 + this.do = () => { + this.force.y += this.mass * 0.003; //gravity + this.draw(); + } + } + } + if (tech.isFoamBall && this.foamSpawned < 55) { + for (let i = 0, len = Math.min(30, 2 + 3 * Math.sqrt(this.mass)); i < len; i++) { + const radius = 5 + 9 * Math.random() + const velocity = { x: Math.max(0.5, 2 - radius * 0.1), y: 0 } + b.foam(this.position, Vector.rotate(velocity, 6.28 * Math.random()), radius) + this.foamSpawned++ + } + } + if (tech.isHarpoonPowerUp && simulation.cycle - 480 < tech.harpoonPowerUpCycle) { + Matter.Body.setDensity(this, 1.8 * tech.harpoonDensity); //+90% damage after pick up power up for 8 seconds + } else if (tech.isHarpoonFullHealth && who.health === 1) { + Matter.Body.setDensity(this, 2.2 * tech.harpoonDensity); //+90% damage if mob has full health do + simulation.ephemera.push({ + name: "harpoon outline", + count: 2, //cycles before it self removes + vertices: this.vertices, + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + + ctx.beginPath(); + ctx.moveTo(this.vertices[0].x, this.vertices[0].y); + for (let j = 1, len = this.vertices.length; j < len; j += 1) ctx.lineTo(this.vertices[j].x, this.vertices[j].y); + ctx.lineTo(this.vertices[0].x, this.vertices[0].y); + ctx.lineJoin = "miter" + ctx.miterLimit = 20; + ctx.lineWidth = 40; + ctx.strokeStyle = "rgba(255,0,100,0.35)"; + ctx.stroke(); + ctx.lineWidth = 10; + ctx.strokeStyle = `#f07`; + ctx.stroke(); + ctx.lineJoin = "round" + ctx.miterLimit = 5 + ctx.fillStyle = "#000" + ctx.fill(); + }, + }) + } + }, + caughtPowerUp: null, + dropCaughtPowerUp() { + if (this.caughtPowerUp) { + this.caughtPowerUp.collisionFilter.category = cat.powerUp + this.caughtPowerUp.collisionFilter.mask = cat.map | cat.powerUp + this.caughtPowerUp = null + } + }, + onEnd() { + if (this.caughtPowerUp && !simulation.isChoosing && (this.caughtPowerUp.name !== "heal" || m.health !== m.maxHealth || tech.isOverHeal)) { + let index = null //find index + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (powerUp[i] === this.caughtPowerUp) index = i + } + if (index !== null) { + powerUps.onPickUp(this.caughtPowerUp); + this.caughtPowerUp.effect(); + Matter.Composite.remove(engine.world, this.caughtPowerUp); + powerUp.splice(index, 1); + if (tech.isHarpoonPowerUp) tech.harpoonPowerUpCycle = simulation.cycle + } else { + this.dropCaughtPowerUp() + } + } else { + this.dropCaughtPowerUp() + } + }, + drawDamageAura() { + ctx.beginPath(); + ctx.moveTo(this.vertices[0].x, this.vertices[0].y); + for (let j = 1, len = this.vertices.length; j < len; j += 1) ctx.lineTo(this.vertices[j].x, this.vertices[j].y); + ctx.lineTo(this.vertices[0].x, this.vertices[0].y); + ctx.lineJoin = "miter" + ctx.miterLimit = 20; + ctx.lineWidth = 15; + ctx.strokeStyle = "rgba(255,0,100,0.25)"; + ctx.stroke(); + ctx.lineWidth = 4; + ctx.strokeStyle = `#f07`; + ctx.stroke(); + ctx.lineJoin = "round" + ctx.miterLimit = 5 + ctx.fillStyle = "#000" + ctx.fill(); + }, + drawString() { + const where = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) } + const sub = Vector.sub(where, this.vertices[0]) + const perpendicular = Vector.mult(Vector.normalise(Vector.perp(sub)), this.drawStringFlip * Math.min(80, 10 + this.drawStringControlMagnitude / (10 + Vector.magnitude(sub)))) + const controlPoint = Vector.add(Vector.add(where, Vector.mult(sub, -0.5)), perpendicular) + ctx.strokeStyle = "#000" // "#0ce" + ctx.lineWidth = 0.5 + ctx.beginPath(); + ctx.moveTo(where.x, where.y); + ctx.quadraticCurveTo(controlPoint.x, controlPoint.y, this.vertices[0].x, this.vertices[0].y) + // ctx.lineTo(this.vertices[0].x, this.vertices[0].y); + ctx.stroke(); + }, + draw() { }, + returnToPlayer() { + if (Vector.magnitude(Vector.sub(this.position, m.pos)) < returnRadius) { //near player + this.endCycle = 0; + // if (m.energy < 0.05) { + // m.fireCDcycle = m.cycle + 80 * b.fireCDscale; //fire cooldown is much longer when out of energy + // } else if (m.cycle + 20 * b.fireCDscale < m.fireCDcycle) { + // if (m.energy > 0.05) m.fireCDcycle = m.cycle + 20 * b.fireCDscale //lower cd to 25 if it is above 25 + // } + //recoil on catching + const momentum = Vector.mult(Vector.sub(this.velocity, player.velocity), (m.crouch ? 0.0001 : 0.0002)) + player.force.x += momentum.x + player.force.y += momentum.y + // refund ammo + if (isReturnAmmo) { + b.guns[9].ammo++; + if (level.is2xAmmo) b.guns[9].ammo++; + simulation.updateGunHUD(); + // for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + // if (b.guns[i].name === "harpoon") { + // break; + // } + // } + } + } else { + const sub = Vector.sub(this.position, m.pos) + const rangeScale = 1 + 0.000001 * Vector.magnitude(sub) * Vector.magnitude(sub) //return faster when far from player + const returnForce = Vector.mult(Vector.normalise(sub), rangeScale * thrust * this.mass) + if (m.energy > this.drain) m.energy -= this.drain + if (m.energy < 0.05) { + this.force.x -= returnForce.x * 0.15 + this.force.y -= returnForce.y * 0.15 + } else { //if (m.cycle + 20 * b.fireCDscale < m.fireCDcycle) + this.force.x -= returnForce.x + this.force.y -= returnForce.y + } + this.grabPowerUp() + } + this.draw(); + }, + grabPowerUp() { //grab power ups near the tip of the harpoon + if (this.caughtPowerUp) { + Matter.Body.setPosition(this.caughtPowerUp, Vector.add(this.vertices[2], this.velocity)) + Matter.Body.setVelocity(this.caughtPowerUp, { x: 0, y: 0 }) + } else { //&& simulation.cycle % 2 + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (tech.isEnergyNoAmmo && powerUp[i].name === "ammo") continue + const radius = powerUp[i].circleRadius + 50 + if (Vector.magnitudeSquared(Vector.sub(this.vertices[2], powerUp[i].position)) < radius * radius && !powerUp[i].isGrabbed) { + if (powerUp[i].name !== "heal" || m.health !== m.maxHealth || tech.isOverHeal) { + powerUp[i].isGrabbed = true + this.caughtPowerUp = powerUp[i] + Matter.Body.setVelocity(powerUp[i], { x: 0, y: 0 }) + Matter.Body.setPosition(powerUp[i], this.vertices[2]) + powerUp[i].collisionFilter.category = 0 + powerUp[i].collisionFilter.mask = 0 + thrust *= 0.6 + this.endCycle += 0.5 //it pulls back slower, so this prevents it from ending early + break //just pull 1 power up if possible + } + } + } + } + }, + do() { + this.cycle++ + if (isReturn || target) { + if (isReturn) { + if (this.cycle > totalCycles) { //return to player //|| !input.fire + this.do = this.returnToPlayer + if (this.angularSpeed < 0.5) this.torque += this.inertia * 0.001 * (Math.random() - 0.5) //(Math.round(Math.random()) ? 1 : -1) + Matter.Sleeping.set(this, false) + this.endCycle = simulation.cycle + 240 + const momentum = Vector.mult(Vector.sub(this.velocity, player.velocity), (m.crouch ? 0.00015 : 0.0003)) //recoil on jerking line + player.force.x += momentum.x + player.force.y += momentum.y + requestAnimationFrame(() => { //delay this for 1 cycle to get the proper hit graphics + this.collisionFilter.category = 0 + this.collisionFilter.mask = 0 + }); + } else { + this.grabPowerUp() + } + } + if (target) { //rotate towards the target + const face = { + x: Math.cos(this.angle), + y: Math.sin(this.angle) + }; + const vectorGoal = Vector.normalise(Vector.sub(this.position, target.position)); + if (Vector.cross(vectorGoal, face) > 0) { + Matter.Body.rotate(this, this.turnRate); + } else { + Matter.Body.rotate(this, -this.turnRate); + } + } + this.force.x += thrust * this.mass * Math.cos(this.angle); + this.force.y += thrust * this.mass * Math.sin(this.angle); + } + this.draw() + }, + }); + if (!isReturn && !target) { + Matter.Body.setVelocity(bullet[me], { + x: 0.7 * player.velocity.x + 600 * thrust * Math.cos(bullet[me].angle), + y: 0.5 * player.velocity.x + 600 * thrust * Math.sin(bullet[me].angle) + }); + bullet[me].frictionAir = 0.002 + bullet[me].do = function () { + if (this.speed < 20) this.force.y += 0.0005 * this.mass; + this.draw(); + } + } + if (tech.isHarpoonPowerUp && simulation.cycle - 480 < tech.harpoonPowerUpCycle) { //8 seconds + if (isReturn) { + bullet[me].draw = function () { + this.drawDamageAura() + this.drawString() + } + } else { + bullet[me].draw = function () { + this.drawDamageAura() + } + } + } else if (isReturn) { + bullet[me].draw = function () { + this.drawString() + } + } + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + missile(where, angle, speed, size = 1) { + if (tech.isMissileBig) { + size *= 1.55 + if (tech.isMissileBiggest) { + size *= 1.55 + + } + } + const me = bullet.length; + bullet[me] = Bodies.rectangle(where.x, where.y, 30 * size, 4 * size, { + angle: angle, + friction: 0.5, + frictionAir: 0.045, + dmg: 0, //damage done in addition to the damage from momentum + classType: "bullet", + endCycle: simulation.cycle + Math.floor((230 + 40 * Math.random()) * tech.bulletsLastLonger + 120 * tech.isMissileBiggest + 60 * tech.isMissileBig), + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield + }, + minDmgSpeed: 10, + lookFrequency: Math.floor(10 + Math.random() * 3), + explodeRad: (tech.isMissileBig ? 230 : 180) + 60 * Math.random(), + density: 0.02, //0.001 is normal + beforeDmg() { + Matter.Body.setDensity(this, 0.0001); //reduce density to normal + this.tryToLockOn(); + this.endCycle = 0; //bullet ends cycle after doing damage // also triggers explosion + }, + onEnd() { + b.explosion(this.position, this.explodeRad * size); //makes bullet do explosive damage at end + if (tech.fragments) b.targetedNail(this.position, tech.fragments * Math.floor(2 + 1.5 * Math.random())) + }, + lockedOn: null, + tryToLockOn() { + let closeDist = Infinity; + const futurePos = Vector.add(this.position, Vector.mult(this.velocity, 30)) //look for closest target to where the missile will be in 30 cycles + this.lockedOn = null; + // const futurePos = this.lockedOn ? :Vector.add(this.position, Vector.mult(this.velocity, 50)) + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + mob[i].alive && !mob[i].isBadTarget && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + const futureDist = Vector.magnitude(Vector.sub(futurePos, mob[i].position)); + if (futureDist < closeDist) { + closeDist = futureDist; + this.lockedOn = mob[i]; + // this.frictionAir = 0.04; //extra friction once a target it locked + } + if (Vector.magnitude(Vector.sub(this.position, mob[i].position) < this.explodeRad)) { + this.endCycle = 0; //bullet ends cycle after doing damage //also triggers explosion + mob[i].lockedOn.damage(m.dmgScale * 2 * size); //does extra damage to target + } + } + } + //explode when bullet is close enough to target + if (this.lockedOn && Vector.magnitude(Vector.sub(this.position, this.lockedOn.position)) < this.explodeRad) { + this.endCycle = 0; //bullet ends cycle after doing damage //also triggers explosion + this.lockedOn.damage(m.dmgScale * 4 * size); //does extra damage to target + } + }, + do() { + if (!(m.cycle % this.lookFrequency)) this.tryToLockOn(); + if (this.lockedOn) { //rotate missile towards the target + const face = { + x: Math.cos(this.angle), + y: Math.sin(this.angle) + }; + const target = Vector.normalise(Vector.sub(this.position, this.lockedOn.position)); + const dot = Vector.dot(target, face) + const aim = Math.min(0.08, (1 + dot) * 1) + if (Vector.cross(target, face) > 0) { + Matter.Body.rotate(this, aim); + } else { + Matter.Body.rotate(this, -aim); + } + this.frictionAir = Math.min(0.1, Math.max(0.04, 1 + dot)) //0.08; //extra friction if turning + } + //accelerate in direction bullet is facing + const dir = this.angle; + this.force.x += thrust * Math.cos(dir); + this.force.y += thrust * Math.sin(dir); + + ctx.beginPath(); //draw rocket + ctx.arc(this.position.x - Math.cos(this.angle) * (25 * size - 3) + (Math.random() - 0.5) * 4, + this.position.y - Math.sin(this.angle) * (25 * size - 3) + (Math.random() - 0.5) * 4, + 11 * size, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(255,155,0,0.5)"; + ctx.fill(); + }, + }); + const thrust = 0.0066 * bullet[me].mass * (tech.isMissileBig ? (tech.isMissileBiggest ? 0.3 : 0.7) : 1); + Matter.Body.setVelocity(bullet[me], { + x: 0.5 * player.velocity.x + speed * Math.cos(angle), + y: 0.5 * player.velocity.y + speed * Math.sin(angle) + }); + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + lastAngle: 0, + wasExtruderOn: false, + isExtruderOn: false, + didExtruderDrain: false, + canExtruderFire: true, + extruder() { + const DRAIN = 0.0012 + if (m.energy > DRAIN && b.canExtruderFire) { + m.energy -= DRAIN + if (m.energy < 0) { + m.fieldCDcycle = m.cycle + 120; + m.energy = 0; + } + b.isExtruderOn = true + const SPEED = 8 + 12 * tech.isPlasmaRange + const me = bullet.length; + const where = Vector.add(m.pos, player.velocity) + bullet[me] = Bodies.polygon(where.x + 20 * Math.cos(m.angle), where.y + 20 * Math.sin(m.angle), 4, 0.01, { + cycle: -0.5, + isWave: true, + endCycle: simulation.cycle + 40, // + 30 * tech.isPlasmaRange, + inertia: Infinity, + frictionAir: 0, + isInHole: true, //this keeps the bullet from entering wormholes + minDmgSpeed: 0, + dmg: m.dmgScale * 2.7, //damage also changes when you divide by mob.mass on in .do() + classType: "bullet", + isBranch: false, + restitution: 0, + collisionFilter: { + // category: 0, + // mask: 0, //cat.mob | cat.mobBullet | cat.mobShield + category: 0, //cat.bullet, + mask: 0, //cat.map, //cat.mob | cat.mobBullet | cat.mobShield + }, + beforeDmg() { }, + onEnd() { }, + do() { + if (this.endCycle < simulation.cycle + 1) this.isWave = false + if (Matter.Query.point(map, this.position).length) { //check if inside map //|| Matter.Query.point(body, this.position).length + this.isBranch = true; + this.do = () => { + if (this.endCycle < simulation.cycle + 1) this.isWave = false + } + } else { //check if inside a mob + for (let i = 0, len = mob.length; i < len; i++) { + const dist = Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)) + const radius = mob[i].radius + tech.extruderRange / 2 + if (dist < radius * radius) { + if (mob[i].speed > 2) { + if (mob[i].isBoss || mob[i].isShielded) { + Matter.Body.setVelocity(mob[i], { x: mob[i].velocity.x * 0.95, y: mob[i].velocity.y * 0.95 }); + } else { + Matter.Body.setVelocity(mob[i], { x: mob[i].velocity.x * 0.25, y: mob[i].velocity.y * 0.25 }); + } + } + // Matter.Body.setPosition(this, Vector.add(this.position, mob[i].velocity)) //move with the medium + let dmg = this.dmg / Math.min(10, mob[i].mass) + mob[i].damage(dmg); + if (mob[i].alive) mob[i].foundPlayer(); + } + } + } + this.cycle++ + const wiggleMag = (m.crouch ? 6 : 12) * Math.cos(simulation.cycle * 0.09) + const wiggle = Vector.mult(transverse, wiggleMag * Math.cos(this.cycle * 0.36)) //+ wiggleMag * Math.cos(simulation.cycle * 0.3)) + const velocity = Vector.mult(player.velocity, 0.4) //move with player + Matter.Body.setPosition(this, Vector.add(velocity, Vector.add(this.position, wiggle))) + } + }); + Composite.add(engine.world, bullet[me]); //add bullet to world + Matter.Body.setVelocity(bullet[me], { + x: SPEED * Math.cos(m.angle), + y: SPEED * Math.sin(m.angle) + }); + const transverse = Vector.normalise(Vector.perp(bullet[me].velocity)) + if (180 - Math.abs(Math.abs(b.lastAngle - m.angle) - 180) > 0.13 || !b.wasExtruderOn) { + bullet[me].isBranch = true; //don't draw stroke for this bullet + bullet[me].do = function () { + if (this.endCycle < simulation.cycle + 1) this.isWave = false + } + } + b.lastAngle = m.angle //track last angle for the above angle difference calculation + } else { + b.canExtruderFire = false; + } + }, + plasma() { + const DRAIN = 0.00075 + if (m.energy > DRAIN) { + m.energy -= DRAIN; + if (m.energy < 0) { + m.fieldCDcycle = m.cycle + 120; + m.energy = 0; + } + + //calculate laser collision + let range = tech.isPlasmaRange * (120 + (m.crouch ? 400 : 300) * Math.sqrt(Math.random())) //+ 100 * Math.sin(m.cycle * 0.3); + // const dir = m.angle // + 0.04 * (Math.random() - 0.5) + const path = [ + { x: m.pos.x + 20 * Math.cos(m.angle), y: m.pos.y + 20 * Math.sin(m.angle) }, + { x: m.pos.x + range * Math.cos(m.angle), y: m.pos.y + range * Math.sin(m.angle) } + ]; + //check for collisions + let best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + best = vertexCollision(path[0], path[1], [mob, map, body]); + if (best.dist2 != Infinity) { //if hitting something + path[path.length - 1] = { x: best.x, y: best.y }; + if (best.who.alive) { + const dmg = 0.9 * m.dmgScale; //********** SCALE DAMAGE HERE ********************* + best.who.damage(dmg); + best.who.locatePlayer(); + + //push mobs away + if (best.who.speed > 3) { + const force = Vector.mult(Vector.normalise(Vector.sub(m.pos, path[1])), -0.005 * Math.min(5, best.who.mass)) + Matter.Body.applyForce(best.who, path[1], force) + Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.4, y: best.who.velocity.y * 0.4 }); + } else { + const force = Vector.mult(Vector.normalise(Vector.sub(m.pos, path[1])), -0.01 * Math.min(5, best.who.mass)) + Matter.Body.applyForce(best.who, path[1], force) + Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.7, y: best.who.velocity.y * 0.7 }); + } + //draw mob damage circle + simulation.drawList.push({ + x: path[1].x, + y: path[1].y, + radius: Math.sqrt(2000 * dmg * best.who.damageReduction), + color: "rgba(255,0,255,0.2)", + time: simulation.drawTime * 4 + }); + } else if (!best.who.isStatic) { + //push blocks away + const force = Vector.mult(Vector.normalise(Vector.sub(m.pos, path[1])), -0.007 * Math.sqrt(Math.sqrt(best.who.mass))) + Matter.Body.applyForce(best.who, path[1], force) + } + } + + //draw blowtorch laser beam + ctx.strokeStyle = "rgba(255,0,255,0.1)" + ctx.lineWidth = 14 + ctx.beginPath(); + ctx.moveTo(path[0].x, path[0].y); + ctx.lineTo(path[1].x, path[1].y); + ctx.stroke(); + ctx.strokeStyle = "#f0f"; + ctx.lineWidth = 2 + ctx.stroke(); + + //draw electricity + const Dx = Math.cos(m.angle); + const Dy = Math.sin(m.angle); + let x = m.pos.x + 20 * Dx; + let y = m.pos.y + 20 * Dy; + ctx.beginPath(); + ctx.moveTo(x, y); + const step = Vector.magnitude(Vector.sub(path[0], path[1])) / 10 + for (let i = 0; i < 8; i++) { + x += step * (Dx + 1.5 * (Math.random() - 0.5)) + y += step * (Dy + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + ctx.lineWidth = 2 * Math.random(); + ctx.stroke(); + } + }, + laser(where = { + x: m.pos.x + 20 * Math.cos(m.angle), + y: m.pos.y + 20 * Math.sin(m.angle) + }, whereEnd = { + x: where.x + 3000 * Math.cos(m.angle), + y: where.y + 3000 * Math.sin(m.angle) + }, dmg = tech.laserDamage, reflections = tech.laserReflections, isThickBeam = false, push = 1) { + const reflectivity = 1 - 1 / (reflections * 3) + let damage = m.dmgScale * dmg + let best = { x: 1, y: 1, dist2: Infinity, who: null, v1: 1, v2: 1 }; + const path = [{ x: where.x, y: where.y }, { x: whereEnd.x, y: whereEnd.y }]; + + const checkForCollisions = function () { + best = vertexCollision(path[path.length - 2], path[path.length - 1], [mob, map, body]); + }; + const laserHitMob = function () { + if (best.who.alive) { + best.who.locatePlayer(); + if (best.who.damageReduction) { + if ( //iridescence + tech.laserCrit && !best.who.shield && + Vector.dot(Vector.normalise(Vector.sub(best.who.position, path[path.length - 1])), Vector.normalise(Vector.sub(path[path.length - 1], path[path.length - 2]))) > 0.999 - 0.5 / best.who.radius + ) { + damage *= 1 + tech.laserCrit + simulation.drawList.push({ //add dmg to draw queue + x: path[path.length - 1].x, + y: path[path.length - 1].y, + radius: Math.sqrt(2500 * damage * best.who.damageReduction) + 5, + color: `hsla(${60 + 283 * Math.random()},100%,70%,0.5)`, // random hue, but not red + time: 16 + }); + } else { + simulation.drawList.push({ //add dmg to draw queue + x: path[path.length - 1].x, + y: path[path.length - 1].y, + radius: Math.sqrt(2000 * damage * best.who.damageReduction) + 2, + color: tech.laserColorAlpha, + time: simulation.drawTime + }); + } + best.who.damage(damage); + } + if (tech.isLaserPush) { //push mobs away + const index = path.length - 1 + Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.97, y: best.who.velocity.y * 0.97 }); + const force = Vector.mult(Vector.normalise(Vector.sub(path[index], path[Math.max(0, index - 1)])), 0.003 * push * Math.min(6, best.who.mass)) + Matter.Body.applyForce(best.who, path[index], force) + } + } else if (tech.isLaserPush && best.who.classType === "body") { + const index = path.length - 1 + Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.97, y: best.who.velocity.y * 0.97 }); + const force = Vector.mult(Vector.normalise(Vector.sub(path[index], path[Math.max(0, index - 1)])), 0.003 * push * Math.min(6, best.who.mass)) + Matter.Body.applyForce(best.who, path[index], force) + } + }; + const reflection = function () { // https://math.stackexchange.com/questions/13261/how-to-get-a-reflection-vector + const n = Vector.perp(Vector.normalise(Vector.sub(best.v1, best.v2))); + const d = Vector.sub(path[path.length - 1], path[path.length - 2]); + const nn = Vector.mult(n, 2 * Vector.dot(d, n)); + const r = Vector.normalise(Vector.sub(d, nn)); + path[path.length] = Vector.add(Vector.mult(r, 3000), path[path.length - 1]); + }; + + checkForCollisions(); + let lastBestOdd + let lastBestEven = best.who //used in hack below + if (best.dist2 !== Infinity) { //if hitting something + path[path.length - 1] = { x: best.x, y: best.y }; + laserHitMob(); + for (let i = 0; i < reflections; i++) { + reflection(); + checkForCollisions(); + if (best.dist2 !== Infinity) { //if hitting something + lastReflection = best + path[path.length - 1] = { x: best.x, y: best.y }; + damage *= reflectivity + laserHitMob(); + //I'm not clear on how this works, but it gets rid of a bug where the laser reflects inside a block, often vertically. + //I think it checks to see if the laser is reflecting off a different part of the same block, if it is "inside" a block + if (i % 2) { + if (lastBestOdd === best.who) break + } else { + lastBestOdd = best.who + if (lastBestEven === best.who) break + } + } else { + break + } + } + } + if (isThickBeam) { + for (let i = 1, len = path.length; i < len; ++i) { + ctx.moveTo(path[i - 1].x, path[i - 1].y); + ctx.lineTo(path[i].x, path[i].y); + } + } else if (tech.isLaserLens && b.guns[11].lensDamage !== 1) { + ctx.strokeStyle = tech.laserColor; + ctx.lineWidth = 2 + ctx.lineDashOffset = 900 * Math.random() + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + for (let i = 1, len = path.length; i < len; ++i) { + ctx.beginPath(); + ctx.moveTo(path[i - 1].x, path[i - 1].y); + ctx.lineTo(path[i].x, path[i].y); + ctx.stroke(); + ctx.globalAlpha *= reflectivity; //reflections are less intense + } + ctx.setLineDash([]); + // ctx.globalAlpha = 1; + + //glow + ctx.lineWidth = 9 + 2 * b.guns[11].lensDamageOn + ctx.globalAlpha = 0.13 + ctx.beginPath(); + for (let i = 1, len = path.length; i < len; ++i) { + ctx.moveTo(path[i - 1].x, path[i - 1].y); + ctx.lineTo(path[i].x, path[i].y); + } + ctx.stroke(); + ctx.globalAlpha = 1; + } else { + ctx.strokeStyle = tech.laserColor; + ctx.lineWidth = 2 + ctx.lineDashOffset = 900 * Math.random() + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + for (let i = 1, len = path.length; i < len; ++i) { + ctx.beginPath(); + ctx.moveTo(path[i - 1].x, path[i - 1].y); + ctx.lineTo(path[i].x, path[i].y); + ctx.stroke(); + ctx.globalAlpha *= reflectivity; //reflections are less intense + } + ctx.setLineDash([]); + ctx.globalAlpha = 1; + } + }, + AoEStunEffect(where, range, cycles = 120 + 60 * Math.random()) { + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && !mob[i].isShielded && !mob[i].shield && !mob[i].isBadTarget) { + if (Vector.magnitude(Vector.sub(where, mob[i].position)) - mob[i].radius < range) mobs.statusStun(mob[i], cycles) + } + } + simulation.drawList.push({ + x: where.x, + y: where.y, + radius: range, + color: "rgba(0,0,0,0.1)", + time: 15 + }); + }, + laserMine(position, velocity = { + x: 0, + y: -8 + }) { + const me = bullet.length; + bullet[me] = Bodies.polygon(position.x, position.y, 3, 25, { + bulletType: "laser mine", + angle: m.angle, + friction: 0, + frictionAir: 0.025, + restitution: 0.5, + dmg: 0, // 0.14 //damage done in addition to the damage from momentum + minDmgSpeed: 2, + lookFrequency: 67 + Math.floor(7 * Math.random()), + drain: 0.7 * tech.laserDrain, + isDetonated: false, + torqueMagnitude: 0.000003 * (Math.round(Math.random()) ? 1 : -1), + range: 1500, + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield + }, + beforeDmg() { }, + onEnd() { }, + do() { + if (!(simulation.cycle % this.lookFrequency) && m.energy > this.drain) { //find mob targets + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + Vector.magnitude(Vector.sub(this.position, mob[i].position)) < 1300 && + !mob[i].isBadTarget && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 + ) { + if (tech.isStun) b.AoEStunEffect(this.position, 1300); //AoEStunEffect(where, range, cycles = 90 + 60 * Math.random()) { + this.do = this.laserSpin + if (this.angularSpeed < 0.5) this.torque += this.inertia * this.torqueMagnitude * 200 //spin + this.endCycle = simulation.cycle + 360 + 120 + // if (this.angularSpeed < 0.01) this.torque += this.inertia * this.torqueMagnitude * 5 //spin + this.isDetonated = true + break + } + } + } + }, + reflections: Math.max(0, tech.laserReflections - 2), + laserSpin() { + //drain energy + if (m.energy > this.drain) { + m.energy -= this.drain + if (this.angularSpeed < 0.05) this.torque += this.inertia * this.torqueMagnitude //spin + + //fire lasers + ctx.strokeStyle = tech.laserColor; + ctx.lineWidth = 1.5 + // ctx.globalAlpha = 1; + ctx.beginPath(); + for (let i = 0; i < 3; i++) { + const where = this.vertices[i] + const endPoint = Vector.add(where, Vector.mult(Vector.normalise(Vector.sub(where, this.position)), 2500)) + b.laser(where, endPoint, tech.laserDamage * 13, this.reflections, true) + } + ctx.stroke(); + // ctx.globalAlpha = 1; + } + if (this.endCycle - 60 < simulation.cycle) { + this.do = () => { } //no nothing, no laser, no spin + } + }, + }) + Matter.Body.setVelocity(bullet[me], velocity); + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + mine(where, velocity, angle = 0) { + const bIndex = bullet.length; + bullet[bIndex] = Bodies.rectangle(where.x, where.y, 45, 16, { + angle: angle, + friction: 1, + frictionStatic: 1, + frictionAir: 0, + restitution: 0, + dmg: 0, //damage done in addition to the damage from momentum + classType: "bullet", + bulletType: "mine", + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield // | cat.bullet //doesn't collide with other bullets until it lands (was crashing into bots) + }, + minDmgSpeed: 5, + stillCount: 0, + isArmed: false, + endCycle: Infinity, + lookFrequency: 0, + range: 700 - 300 * tech.isFoamMine, + beforeDmg() { }, + onEnd() { + if (this.isArmed && !tech.isMineSentry) { + if (tech.isFoamMine) { + //send 14 in random directions slowly + for (let i = 0; i < 12; i++) { + const radius = 13 + 8 * Math.random() + const velocity = { x: 0.5 + 5.5 * Math.random(), y: 0 } + b.foam(this.position, Vector.rotate(velocity, this.angle + 1.57 + 3 * (Math.random() - 0.5)), radius) //6.28 * Math.random() + } + //send 40 targeted + let count = 0 + let cycle = () => { + if (count < 50) { + if (!simulation.paused && !simulation.isChoosing) { //!(simulation.cycle % 1) && + count++ + b.targetedFoam(this.position) + } + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle) + } else if (tech.isSuperMine) { + b.targetedBall(this.position, 22 + 2 * tech.extraSuperBalls) + } else { + b.targetedNail(this.position, 22, 40 + 10 * Math.random(), 1200, 2.2) + } + } + }, + do() { + this.force.y += this.mass * 0.002; //extra gravity + let collide = Matter.Query.collides(this, map) //check if collides with map + if (collide.length > 0) { + for (let i = 0; i < collide.length; i++) { + if (collide[i].bodyA.collisionFilter.category === cat.map) { // || collide[i].bodyB.collisionFilter.category === cat.map) { + const angle = Vector.angle(collide[i].normal, { x: 1, y: 0 }) + Matter.Body.setAngle(this, Math.atan2(collide[i].tangent.y, collide[i].tangent.x)) + for (let j = 0; j < 10; j++) { //move until touching map again after rotation + if (Matter.Query.collides(this, map).length > 0) { //touching map + if (angle > -0.2 || angle < -1.5) { //don't stick to level ground + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + Matter.Body.setStatic(this, true) //don't set to static if not touching map + this.collisionFilter.category = 0 + this.collisionFilter.mask = 0 //cat.map | cat.bullet + } else { + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + Matter.Body.setAngularVelocity(this, 0) + } + this.arm(); + //sometimes the mine can't attach to map and it just needs to be reset + setTimeout(() => { + if (Matter.Query.collides(this, map).length === 0 || Matter.Query.point(map, this.position).length > 0) { + this.endCycle = 0 // if not touching map explode + this.isArmed = false + b.mine(this.position, this.velocity, this.angle) + } + }, 100); + break + } + Matter.Body.setPosition(this, Vector.add(this.position, Vector.mult(collide[i].normal, 2))) //move until you are touching the wall + } + break + } + } + } else { + if (this.speed < 1 && this.angularSpeed < 0.01) this.stillCount++ + } + if (this.stillCount > 25) this.arm(); + }, + arm() { + this.collisionFilter.mask = cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield | cat.bullet //can now collide with other bullets + this.lookFrequency = simulation.cycle + 60 + this.do = function () { //overwrite the do method for this bullet + this.force.y += this.mass * 0.002; //extra gravity + if (simulation.cycle > this.lookFrequency) { + this.isArmed = true + this.lookFrequency = 55 + Math.floor(22 * Math.random()) + simulation.drawList.push({ x: this.position.x, y: this.position.y, radius: 10, color: "#f00", time: 4 }); + this.do = function () { //overwrite the do method for this bullet + this.force.y += this.mass * 0.002; //extra gravity + if (!(simulation.cycle % this.lookFrequency)) { //find mob targets + const random = 300 * Math.random() + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + !mob[i].isBadTarget && + !mob[i].isInvulnerable && + Vector.magnitude(Vector.sub(this.position, mob[i].position)) < this.range + mob[i].radius + random && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 + ) { + if (tech.isStun) b.AoEStunEffect(this.position, this.range + mob[i].radius + random); //AoEStunEffect(where, range, cycles = 90 + 60 * Math.random()) { + if (tech.isMineSentry) { + this.lookFrequency = Math.floor(7 + 7 * b.fireCDscale + 10 * (tech.oneSuperBall && tech.isSuperMine) + Math.floor(3 * Math.random())) + // this.endCycle = Infinity + this.shots = tech.sentryAmmo + this.do = function () { //overwrite the do method for this bullet + this.force.y += this.mass * 0.002; //extra gravity + if (!(simulation.cycle % this.lookFrequency)) { //find mob targets + if (tech.isFoamMine) { + this.shots -= 0.6 * b.targetedFoam(this.position, 1, 21 + 7 * Math.random(), 1200, false) + b.targetedFoam(this.position, 1, 21 + 7 * Math.random(), 1200, false) + } else if (tech.isSuperMine) { + const cost = tech.oneSuperBall ? 2 : 0.7 + this.shots -= cost * b.targetedBall(this.position, 1, 42 + 12 * Math.random(), 1200, false) + for (let i = 0, len = tech.extraSuperBalls / 4; i < len; i++) { + if (Math.random() < 0.33) b.targetedBall(this.position, 1, 42 + 12 * Math.random(), 1200, false) + } + } else { + this.shots -= b.targetedNail(this.position, 1, 45 + 5 * Math.random(), 1100, 2.3) + } + if (this.shots < 0) this.endCycle = 0 + if (!(simulation.cycle % (this.lookFrequency * 6))) { + simulation.drawList.push({ x: this.position.x, y: this.position.y, radius: 8, color: "#fe0", time: 4 }); + } + } + } + break + } else { + this.endCycle = 0 //end life if mob is near and visible + break + } + } + } + } + } + } + } + }, + }); + bullet[bIndex].torque += bullet[bIndex].inertia * 0.0002 * (0.5 - Math.random()) + Matter.Body.setVelocity(bullet[bIndex], velocity); + Composite.add(engine.world, bullet[bIndex]); //add bullet to world + }, + worm(where, isFreeze = tech.isSporeFreeze) { //used with the tech upgrade in mob.death() + const bIndex = bullet.length; + const wormSize = 6 + tech.wormSize * 4.2 * Math.random() + if (bIndex < 500) { //can't make over 500 spores + bullet[bIndex] = Bodies.polygon(where.x, where.y, 3, 3, { + inertia: Infinity, + isFreeze: isFreeze, + restitution: 0.5, + // angle: Math.random() * 2 * Math.PI, + friction: 0, + frictionAir: 0.025, + thrust: (tech.isSporeFollow ? 0.0012 : 0.00055) * (1 + 0.5 * (Math.random() - 0.5)), + wormSize: wormSize, + wormTail: 1 + Math.max(4, Math.min(wormSize - 2 * tech.wormSize, 30)), + dmg: (tech.isMutualism ? 9.5 : 3.2) * wormSize, + lookFrequency: 100 + Math.floor(37 * Math.random()), + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.mob | cat.mobBullet | cat.mobShield //no collide with body + }, + endCycle: simulation.cycle + Math.floor((600 + Math.floor(Math.random() * 420)) * tech.bulletsLastLonger), + minDmgSpeed: 0, + playerOffPosition: { //used when moving towards player to keep spores separate + x: 100 * (Math.random() - 0.5), + y: 100 * (Math.random() - 0.5) + }, + beforeDmg(who) { + if (who.isInvulnerable) { + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.1)); + } else { + if (tech.isSpawnBulletsOnDeath && who.alive && who.isDropPowerUp) { + setTimeout(() => { + if (!who.alive) { + for (let i = 0; i < 3; i++) { //spawn 3 more + b.worm(this.position) + bullet[bullet.length - 1].endCycle = Math.min(simulation.cycle + Math.floor(420 * tech.bulletsLastLonger), this.endCycle + 180 + Math.floor(60 * Math.random())) //simulation.cycle + Math.floor(420 * tech.bulletsLastLonger) + } + } + this.endCycle = 0; //bullet ends cycle after doing damage + }, 1); + } else { + this.endCycle = 0; //bullet ends cycle after doing damage + } + if (this.isFreeze) mobs.statusSlow(who, 90) + } + }, + onEnd() { + if (tech.isMutualism && this.isMutualismActive && !tech.isEnergyHealth) { + m.health += 0.02 + if (m.health > m.maxHealth) m.health = m.maxHealth; + m.displayHealth(); + } + }, + tailCycle: 6.28 * Math.random(), + do() { + this.tailCycle += this.speed * 0.025 + ctx.beginPath(); //draw nematode + ctx.moveTo(this.position.x, this.position.y); + // const dir = Vector.mult(Vector.normalise(this.velocity), -Math.min(100, this.wormTail * this.speed)) + const speed = Math.min(7, this.speed) + const dir = Vector.mult(Vector.normalise(this.velocity), -0.6 * this.wormTail * speed) + const tail = Vector.add(this.position, dir) + const wiggle = Vector.add(Vector.add(tail, dir), Vector.rotate(dir, Math.sin(this.tailCycle))) + // const wiggle = Vector.add(tail, Vector.rotate(dir, Math.sin((m.cycle - this.endCycle) * 0.03 * this.speed))) + ctx.quadraticCurveTo(tail.x, tail.y, wiggle.x, wiggle.y) // ctx.quadraticCurveTo(controlPoint.x, controlPoint.y, this.vertices[0].x, this.vertices[0].y) + // ctx.lineTo(tail.x, tail.y); + ctx.lineWidth = this.wormSize; + ctx.strokeStyle = "#000"; + ctx.stroke(); + + + if (this.lockedOn && this.lockedOn.alive) { + this.force = Vector.mult(Vector.normalise(Vector.sub(this.lockedOn.position, this.position)), this.mass * this.thrust) + } else { + if (!(simulation.cycle % this.lookFrequency)) { //find mob targets + this.closestTarget = null; + this.lockedOn = null; + let closeDist = Infinity; + for (let i = 0, len = mob.length; i < len; ++i) { + if (!mob[i].isBadTarget && Matter.Query.ray(map, this.position, mob[i].position).length === 0 && !mob[i].isInvulnerable) { + const targetVector = Vector.sub(this.position, mob[i].position) + const dist = Vector.magnitude(targetVector) * (Math.random() + 0.5); + if (dist < closeDist) { + this.closestTarget = mob[i].position; + closeDist = dist; + this.lockedOn = mob[i] + if (0.3 > Math.random()) break //doesn't always target the closest mob + } + } + } + } + if (tech.isSporeFollow && this.lockedOn === null) { //move towards player //checking for null means that the spores don't go after the player until it has looked and not found a target + const dx = this.position.x - m.pos.x; + const dy = this.position.y - m.pos.y; + if (dx * dx + dy * dy > 10000) { + this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, Vector.add(this.playerOffPosition, this.position))), this.mass * this.thrust) + } + } else { + const unit = Vector.normalise(this.velocity) + const force = Vector.mult(Vector.rotate(unit, 0.005 * this.playerOffPosition.x), 0.000003) + this.force.x += force.x + this.force.y += force.y + } + } + }, + }); + const SPEED = 2 + 1 * Math.random(); + const ANGLE = 2 * Math.PI * Math.random() + Matter.Body.setVelocity(bullet[bIndex], { + x: SPEED * Math.cos(ANGLE), + y: SPEED * Math.sin(ANGLE) + }); + Composite.add(engine.world, bullet[bIndex]); //add bullet to world + if (tech.isMutualism && m.health > 0.04) { + m.health -= 0.02 + m.displayHealth(); + bullet[bIndex].isMutualismActive = true + } + } + }, + spore(where, isFreeze = tech.isSporeFreeze) { //used with the tech upgrade in mob.death() + const bIndex = bullet.length; + const size = 4 + if (bIndex < 500) { //can't make over 500 spores + bullet[bIndex] = Bodies.polygon(where.x, where.y, size, size, { + // density: 0.0015, //frictionAir: 0.01, + inertia: Infinity, + isFreeze: isFreeze, + restitution: 0.5, + angle: Math.random() * 2 * Math.PI, + friction: 0, + frictionAir: 0.025, + thrust: (tech.isSporeFollow ? 0.0011 : 0.0005) * (1 + 0.3 * (Math.random() - 0.5)), + dmg: (tech.isMutualism ? 20 : 7), //bonus damage from tech.isMutualism + lookFrequency: 100 + Math.floor(117 * Math.random()), + classType: "bullet", + isSpore: true, + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.mob | cat.mobBullet | cat.mobShield //no collide with body + }, + endCycle: simulation.cycle + Math.floor((540 + Math.floor(Math.random() * 420)) * tech.bulletsLastLonger), + minDmgSpeed: 0, + playerOffPosition: { //used when moving towards player to keep spores separate + x: 100 * (Math.random() - 0.5), + y: 100 * (Math.random() - 0.5) + }, + beforeDmg(who) { + if (!who.isInvulnerable) { + this.endCycle = 0; //bullet ends cycle after doing damage + if (this.isFreeze) mobs.statusSlow(who, 90) + } + }, + onEnd() { + if (tech.isMutualism && this.isMutualismActive && !tech.isEnergyHealth) { + m.health += 0.01 + if (m.health > m.maxHealth) m.health = m.maxHealth; + m.displayHealth(); + } + // console.log(this.dmg) + }, + do() { + if (this.lockedOn && this.lockedOn.alive) { + this.force = Vector.mult(Vector.normalise(Vector.sub(this.lockedOn.position, this.position)), this.mass * this.thrust) + } else { + if (!(simulation.cycle % this.lookFrequency)) { //find mob targets + this.closestTarget = null; + this.lockedOn = null; + let closeDist = Infinity; + for (let i = 0, len = mob.length; i < len; ++i) { + if (!mob[i].isBadTarget && Matter.Query.ray(map, this.position, mob[i].position).length === 0 && !mob[i].isInvulnerable) { + const targetVector = Vector.sub(this.position, mob[i].position) + const dist = Vector.magnitude(targetVector) * (Math.random() + 0.5); + if (dist < closeDist) { + this.closestTarget = mob[i].position; + closeDist = dist; + this.lockedOn = mob[i] + if (0.3 > Math.random()) break //doesn't always target the closest mob + } + } + } + } + if (tech.isSporeFollow && this.lockedOn === null) { //move towards player + //checking for null means that the spores don't go after the player until it has looked and not found a target + const dx = this.position.x - m.pos.x; + const dy = this.position.y - m.pos.y; + if (dx * dx + dy * dy > 10000) { + this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, Vector.add(this.playerOffPosition, this.position))), this.mass * this.thrust) + } + } else { + this.force.y += this.mass * 0.0001; //gravity + } + + } + + // if (!this.lockedOn && !(simulation.cycle % this.lookFrequency)) { //find mob targets + // this.closestTarget = null; + // this.lockedOn = null; + // let closeDist = Infinity; + // for (let i = 0, len = mob.length; i < len; ++i) { + // if (mob[i].isDropPowerUp && Matter.Query.ray(map, this.position, mob[i].position).length === 0) { + // // Matter.Query.ray(body, this.position, mob[i].position).length === 0 + // const targetVector = Vector.sub(this.position, mob[i].position) + // const dist = Vector.magnitude(targetVector); + // if (dist < closeDist) { + // this.closestTarget = mob[i].position; + // closeDist = dist; + // this.lockedOn = mob[i] //Vector.normalise(targetVector); + // if (0.3 > Math.random()) break //doesn't always target the closest mob + // } + // } + // } + // } + // if (this.lockedOn && this.lockedOn.alive) { //accelerate towards mobs + // this.force = Vector.mult(Vector.normalise(Vector.sub(this.lockedOn.position, this.position)), this.mass * this.thrust) + // } else if (tech.isSporeFollow && this.lockedOn !== undefined) { //move towards player + // //checking for undefined means that the spores don't go after the player until it has looked and not found a target + // const dx = this.position.x - m.pos.x; + // const dy = this.position.y - m.pos.y; + // if (dx * dx + dy * dy > 10000) { + // this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, Vector.add(this.playerOffPosition, this.position))), this.mass * this.thrust) + // } + // // this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, this.position)), this.mass * this.thrust) + // } else { + // this.force.y += this.mass * 0.0001; //gravity + // } + + // if (this.nextPortCycle < simulation.cycle) { //teleport around if you have tech.isBulletTeleport + // this.nextPortCycle = simulation.cycle + this.portFrequency + // const range = 50 * Math.random() + // Matter.Body.setPosition(this, Vector.add(this.position, Vector.rotate({ x: range, y: 0 }, 2 * Math.PI * Math.random()))) + // } + }, + }); + // if (tech.isBulletTeleport) { + // bullet[bIndex].portFrequency = 10 + Math.floor(5 * Math.random()) + // bullet[bIndex].nextPortCycle = simulation.cycle + bullet[bIndex].portFrequency + // } + + const SPEED = 4 + 8 * Math.random(); + const ANGLE = 2 * Math.PI * Math.random() + Matter.Body.setVelocity(bullet[bIndex], { + x: SPEED * Math.cos(ANGLE), + y: SPEED * Math.sin(ANGLE) + }); + Composite.add(engine.world, bullet[bIndex]); //add bullet to world + + if (tech.isMutualism && m.health > 0.01) { + m.health -= 0.01 + m.displayHealth(); + bullet[bIndex].isMutualismActive = true + } + } + }, + iceIX(speed = 0, dir = m.angle + Math.PI * 2 * Math.random(), where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }) { + const me = bullet.length; + const THRUST = 0.0018 + const RADIUS = 18 + const SCALE = 1 - 0.11 / tech.bulletsLastLonger + bullet[me] = Bodies.polygon(where.x, where.y, 3, RADIUS, { + angle: dir - Math.PI, + // inertia: Infinity, + spin: 0.00004 * (0.1 + Math.random()) * (Math.round(Math.random()) ? 1 : -1), + friction: 0, + frictionAir: 0.02, + restitution: 0.9, + dmg: 1.3, //damage done in addition to the damage from momentum + lookFrequency: 14 + Math.floor(8 * Math.random()), + endCycle: simulation.cycle + 65 * tech.bulletsLastLonger + Math.floor(25 * Math.random()), + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield //self collide + }, + minDmgSpeed: 0, + lockedOn: null, + beforeDmg(who) { + if (!who.isInvulnerable) { + if (tech.iceEnergy && !who.shield && !who.isShielded && who.isDropPowerUp && who.alive && m.immuneCycle < m.cycle) { + setTimeout(() => { + if (!who.alive) m.energy += tech.iceEnergy * 0.8 * level.isReducedRegen + }, 10); + } + mobs.statusSlow(who, tech.iceIXFreezeTime) + this.endCycle = simulation.cycle + } + // if (tech.isHeavyWater) mobs.statusDoT(who, 0.15, 300) + }, + onEnd() { }, + do() { + // this.force.y += this.mass * 0.0002; + //find mob targets + if (!(simulation.cycle % this.lookFrequency)) { + Matter.Body.scale(this, SCALE, SCALE); + this.lockedOn = null; + let closeDist = Infinity; + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + !mob[i].isBadTarget && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + const TARGET_VECTOR = Vector.sub(this.position, mob[i].position) + const DIST = Vector.magnitude(TARGET_VECTOR); + if (DIST < closeDist) { + closeDist = DIST; + this.lockedOn = mob[i] + } + } + } + } + if (this.lockedOn) { //accelerate towards mobs + this.force = Vector.mult(Vector.normalise(Vector.sub(this.lockedOn.position, this.position)), this.mass * THRUST) + } else { + this.force = Vector.mult(Vector.normalise(this.velocity), this.mass * THRUST) + } + this.torque += this.inertia * this.spin + } + }) + + Composite.add(engine.world, bullet[me]); //add bullet to world + // Matter.Body.setAngularVelocity(bullet[me], 2 * (0.5 - Math.random())) //doesn't work due to high friction + Matter.Body.setVelocity(bullet[me], { + x: speed * Math.cos(dir), + y: speed * Math.sin(dir) + }); + Matter.Body.setAngularVelocity(bullet[me], 3000 * bullet[me].spin); + }, + flea(where, velocity, radius = 6 + 3 * Math.random() + 10 * tech.wormSize * Math.random()) { + const me = bullet.length; + bullet[me] = Bodies.polygon(where.x, where.y, 5, radius, { + isFlea: true, + angle: 0.5 * Math.random(), + friction: 1, + frictionStatic: 1, + frictionAir: 0, //0.01, + restitution: 0, + density: 0.0005, // 0.001 is normal density + lookFrequency: 19 + Math.floor(7 * Math.random()), + endCycle: simulation.cycle + Math.floor((900 * tech.bulletsLastLonger + 420 * Math.random()) + Math.max(0, 150 - bullet.length)), // 13 - 19s + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield + }, + minDmgSpeed: 0, + lockedOn: null, + delay: 50, + cd: simulation.cycle + 10, + dmg: 0, + setDamage() { //dmg is set to zero after doing damage once, and set back to normal after jumping + this.dmg = radius * (tech.isMutualism ? 3.3 : 1.1) //damage done in addition to the damage from momentum //spores do 7 dmg, worms do 18 + }, + beforeDmg(who) { + Matter.Body.setVelocity(this, Vector.mult(Vector.normalise(Vector.sub(this.position, who.position)), 10 + 10 * Math.random())); //push away from target + this.cd = simulation.cycle + this.delay; + if (!who.isInvulnerable && this.dmg !== 0) { + this.endCycle -= 110 + if (tech.isSporeFreeze) mobs.statusSlow(who, 90) + if (tech.isSpawnBulletsOnDeath && who.alive && who.isDropPowerUp) { + setTimeout(() => { + if (!who.alive) { + for (let i = 0; i < 2; i++) { //spawn 2 more + const speed = 10 + 5 * Math.random() + const angle = 2 * Math.PI * Math.random() + b.flea(this.position, { + x: speed * Math.cos(angle), + y: speed * Math.sin(angle) + }) + } + } + this.endCycle = 0; + }, 1); + } + setTimeout(() => { + this.dmg = 0 + }) + } + }, + onEnd() { + if (tech.isMutualism && this.isMutualismActive && !tech.isEnergyHealth) { + m.health += 0.02 + if (m.health > m.maxHealth) m.health = m.maxHealth; + m.displayHealth(); + } + }, + gravity: 0.002 + 0.002 * tech.isSporeFollow, + do() { + this.force.y += this.gravity * this.mass + if (this.cd < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { //if on the ground and not on jump cooldown // + this.cd = simulation.cycle + this.delay; + this.lockedOn = null; //find a target + let closeDist = Infinity; + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + !mob[i].isBadTarget && + !mob[i].isInvulnerable && + mob[i].alive && + this.position.y - mob[i].position.y < 1500 && //this is about how high fleas can jump with capMaxY = 0.12 + 0.04 * Math.random() + this.position.y - mob[i].position.y > -300 && //not too far below the flea (note that fleas should be on the ground most of the time when doing this check) + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 + ) { + const TARGET_VECTOR = Vector.sub(this.position, mob[i].position) + const DIST = Vector.magnitude(TARGET_VECTOR); + if (DIST < closeDist) { + closeDist = DIST; + this.lockedOn = mob[i] + } + } + } + if (tech.isSporeFollow && !this.lockedOn && Matter.Query.ray(map, this.position, m.pos).length === 0) { + this.lockedOn = { //make target player if there are no mobs to target + position: m.pos, + velocity: { x: 0, y: 0 } + } + } + if (this.lockedOn) { //hop towards mob target + const where = Vector.add(this.lockedOn.position, Vector.mult(this.lockedOn.velocity, 5)) //estimate where the mob will be in 5 cycles + const Dy = Math.max(0, this.position.y - where.y) //can't be negative because you can't hop down + const Dx = this.position.x - where.x + const Vx = -0.06 * Dx / Math.sqrt(2 * Dy / this.gravity) //calibrated to hit target, don't mess with this + const Vy = 0.085 * Math.sqrt(this.gravity * Dy) //calibrated to hit target, don't mess with this + const capX = 0.07 + 0.02 * tech.isSporeFollow + const capMaxY = 0.12 + 0.04 * Math.random() + 0.05 * tech.isSporeFollow + const capMinY = closeDist > 500 ? 0.05 + 0.02 * Math.random() : 0.02 + 0.01 * Math.random() //don't jump super low, unless you are very close to mob target + this.force.x = Math.max(-capX, Math.min(capX, Vx)) * this.mass; + this.force.y = -Math.max(capMinY, Math.min(capMaxY, Vy)) * this.mass + } else { //random hops + if (Math.random() < 0.5) { //chance to continue in the same horizontal direction + this.force.x = (0.01 + 0.03 * Math.random()) * this.mass * (this.velocity.x > 0 ? 1 : -1); //random move + } else { + this.force.x = (0.01 + 0.03 * Math.random()) * this.mass * (Math.random() < 0.5 ? 1 : -1); //random move + } + this.force.y = -(0.03 + 0.08 * Math.random()) * this.mass + } + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + this.setDamage() //after jumping damage is no longer zero + } + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + Matter.Body.setVelocity(bullet[me], velocity); + if (tech.isMutualism && m.health > 0.01) { + m.health -= 0.01 + m.displayHealth(); + bullet[bullet.length - 1].isMutualismActive = true + } + }, + delayDrones(where, droneCount = 1, deliveryCount = 0) { + let respawnDrones = () => { + if (droneCount > 0) { + requestAnimationFrame(respawnDrones); + if (!simulation.paused && !simulation.isChoosing && m.alive) { + droneCount-- + if (tech.isDroneRadioactive) { + b.droneRadioactive({ x: where.x + 50 * (Math.random() - 0.5), y: where.y + 50 * (Math.random() - 0.5) }, 0) + } else { + b.drone({ x: where.x + 50 * (Math.random() - 0.5), y: where.y + 50 * (Math.random() - 0.5) }, 0) + if (tech.isDroneGrab && deliveryCount > 0) { // + const who = bullet[bullet.length - 1] + who.isImproved = true; + const SCALE = 2.25 + Matter.Body.scale(who, SCALE, SCALE); + who.lookFrequency = 30 + Math.floor(11 * Math.random()); + who.endCycle += 3000 * tech.droneCycleReduction * tech.bulletsLastLonger + deliveryCount-- + } + } + } + } + } + requestAnimationFrame(respawnDrones); + }, + drone(where = { x: m.pos.x + 30 * Math.cos(m.angle) + 20 * (Math.random() - 0.5), y: m.pos.y + 30 * Math.sin(m.angle) + 20 * (Math.random() - 0.5) }, speed = 1) { + const me = bullet.length; + const THRUST = 0.0015 + const dir = m.angle + 0.2 * (Math.random() - 0.5); + const RADIUS = (4.5 + 3 * Math.random()) + bullet[me] = Bodies.polygon(where.x, where.y, 8, RADIUS, { + angle: dir, + inertia: Infinity, + friction: 0.05, + frictionAir: 0, + restitution: 1, + density: 0.0005, // 0.001 is normal density + dmg: 0.34 + 0.12 * tech.isDroneTeleport + 0.15 * tech.isDroneFastLook, //damage done in addition to the damage from momentum + lookFrequency: (tech.isDroneFastLook ? 20 : 70) + Math.floor(17 * Math.random()), + endCycle: simulation.cycle + Math.floor((950 + 400 * Math.random()) * tech.bulletsLastLonger * tech.droneCycleReduction) + 5 * RADIUS + Math.max(0, 150 - bullet.length), + classType: "bullet", + isDrone: true, + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield //self collide + }, + minDmgSpeed: 0, + lockedOn: null, + deathCycles: 110 + RADIUS * 5, + isImproved: false, + beforeDmg(who) { + if (who.isInvulnerable) { + //move away from target after hitting + const unit = Vector.mult(Vector.normalise(Vector.sub(this.position, who.position)), -20) + Matter.Body.setVelocity(this, { x: unit.x, y: unit.y }); + this.lockedOn = null + } else { + // if (tech.isIncendiary && simulation.cycle + this.deathCycles < this.endCycle && !tech.isForeverDrones) { + // const max = Math.max(Math.min(this.endCycle - simulation.cycle - this.deathCycles, 1500), 0) + // b.explosion(this.position, max * 0.14 + this.isImproved * 110 + 60 * Math.random()); //makes bullet do explosive damage at end + // if (tech.isForeverDrones) { + // this.endCycle = 0 + // b.drone({ x: m.pos.x + 30 * (Math.random() - 0.5), y: m.pos.y + 30 * (Math.random() - 0.5) }, 5) + // bullet[bullet.length - 1].endCycle = Infinity + // } else { + // this.endCycle -= max + // } + // } else { + //move away from target after hitting + const unit = Vector.mult(Vector.normalise(Vector.sub(this.position, who.position)), -20) + Matter.Body.setVelocity(this, { x: unit.x, y: unit.y }); + this.lockedOn = null + if (this.endCycle > simulation.cycle + this.deathCycles) { + this.endCycle -= 60 + if (simulation.cycle + this.deathCycles > this.endCycle) this.endCycle = simulation.cycle + this.deathCycles + } + // } + } + }, + onEnd() { + if (tech.isDroneRespawn) { + //are there any nearby bodies nearby that aren't blocked by map? + const canSee = body.filter(a => Matter.Query.ray(map, this.position, a.position).length === 0 && !a.isNotHoldable && Vector.magnitude(Vector.sub(this.position, a.position)) < 70 + 30 * a.mass) + if (canSee.length) { + //find the closest body to the drone from the canSee array + const found = canSee.reduce((a, b) => { + const distA = Vector.magnitude(Vector.sub(this.position, a.position)) + const distB = Vector.magnitude(Vector.sub(this.position, b.position)) + return distA < distB ? a : b + }) + if (found && m.energy > 0.041) { + m.energy -= 0.04 + //remove the body and spawn a new drone + Composite.remove(engine.world, found) + body.splice(body.indexOf(found), 1) + b.delayDrones(found.position, Math.sqrt(found.mass)) + //draw a line from the drone to the body on the canvas + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(found.position.x, found.position.y); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 2; + ctx.stroke(); + + //animate the block fading away + simulation.ephemera.push({ + name: "droneRespawn", + count: 60, //cycles before it self removes + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + ctx.beginPath(); + let vertices = found.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 2; + ctx.strokeStyle = `rgba(0,0,0,${this.count / 60})` + ctx.stroke(); + }, + }) + } + } + } + }, + doRespawning() { //fall shrink and die + const scale = 0.995; + Matter.Body.scale(this, scale, scale); + if (this.bodyTarget) { + this.force = Vector.mult(Vector.normalise(Vector.sub(this.position, this.bodyTarget.position)), -this.mass * THRUST) + } else { + this.force.y += this.mass * 0.0012; + } + }, + doDieing() { //fall shrink and die + this.force.y += this.mass * 0.0012; + const scale = 0.995; + Matter.Body.scale(this, scale, scale); + }, + hasExploded: false, + do() { + if (simulation.cycle + this.deathCycles > this.endCycle) { + if (tech.isIncendiary && !this.hasExploded) { + this.hasExploded = true + // const max = Math.max(Math.min(this.endCycle - simulation.cycle - this.deathCycles, 1500), 0) + // this.endCycle -= max + b.explosion(this.position, 200 + this.isImproved * 110 + 60 * Math.random()); //makes bullet do explosive damage at end + } + this.restitution = 0.2; + if (tech.isDroneRespawn) { + this.do = this.doRespawning + //make a list of all elements of array body that a ray can be drawn to from the drone + const canSee = body.filter(a => Matter.Query.ray(map, this.position, a.position).length === 0 && !a.isNotHoldable) + if (canSee.length) { + //find the closest body to the drone from the canSee array + const found = canSee.reduce((a, b) => { + const distA = Vector.magnitude(Vector.sub(this.position, a.position)) + const distB = Vector.magnitude(Vector.sub(this.position, b.position)) + return distA < distB ? a : b + }) + if (found) this.bodyTarget = found + } + } else { + this.do = this.doDieing + } + } + + this.force.y += this.mass * 0.0002; + if (!(simulation.cycle % this.lookFrequency)) { + //find mob targets + this.lockedOn = null; + let closeDist = Infinity; + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + !mob[i].isBadTarget && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + const TARGET_VECTOR = Vector.sub(this.position, mob[i].position) + const DIST = Vector.magnitude(TARGET_VECTOR) + if (DIST < closeDist) { + closeDist = DIST; + this.lockedOn = mob[i] + } + } + } + //blink towards mobs + if (tech.isDroneTeleport && this.lockedOn) { + const sub = Vector.sub(this.lockedOn.position, this.position); + const distMag = Vector.magnitude(sub); + const unit = Vector.normalise(sub) + Matter.Body.setVelocity(this, Vector.mult(unit, Math.max(20, this.speed * 1.5))); + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + Matter.Body.translate(this, Vector.mult(unit, Math.min(350, distMag - this.lockedOn.radius + 10))); + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = RADIUS * 2; + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + ctx.stroke(); + } + //power ups + if (!this.isImproved && !simulation.isChoosing) { + if (this.lockedOn) { + for (let i = 0, len = powerUp.length; i < len; ++i) { //grab, but don't lock onto nearby power up + if ( + Vector.magnitudeSquared(Vector.sub(this.position, powerUp[i].position)) < 20000 && + !( + (m.health > 0.93 * m.maxHealth && !tech.isDroneGrab && powerUp[i].name === "heal") || + (tech.isSuperDeterminism && powerUp[i].name === "field") || + ((tech.isEnergyNoAmmo || b.inventory.length === 0) && powerUp[i].name === "ammo") + ) + ) { + //draw pickup for a single cycle + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(powerUp[i].position.x, powerUp[i].position.y); + ctx.strokeStyle = "#000" + ctx.lineWidth = 4 + ctx.stroke(); + //pick up nearby power ups + powerUps.onPickUp(powerUp[i]); + powerUp[i].effect(); + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + if (tech.isDroneGrab) { + this.isImproved = true; + const SCALE = 2.25 + Matter.Body.scale(this, SCALE, SCALE); + this.lookFrequency = 30 + Math.floor(11 * Math.random()); + this.endCycle += 3000 * tech.droneCycleReduction * tech.bulletsLastLonger + } + break; + } + } + } else { + //look for power ups to lock onto + let closeDist = Infinity; + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (!( + (m.health > 0.93 * m.maxHealth && !tech.isDroneGrab && powerUp[i].name === "heal") || + (tech.isSuperDeterminism && powerUp[i].name === "field") || + ((tech.isEnergyNoAmmo || b.inventory.length === 0) && powerUp[i].name === "ammo") + )) { + if (Vector.magnitudeSquared(Vector.sub(this.position, powerUp[i].position)) < 20000 && !simulation.isChoosing) { + //draw pickup for a single cycle + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(powerUp[i].position.x, powerUp[i].position.y); + ctx.strokeStyle = "#000" + ctx.lineWidth = 4 + ctx.stroke(); + //pick up nearby power ups + powerUps.onPickUp(powerUp[i]); + powerUp[i].effect(); + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + if (tech.isDroneGrab) { + this.isImproved = true; + const SCALE = 2.25 + Matter.Body.scale(this, SCALE, SCALE); + this.lookFrequency = 30 + Math.floor(11 * Math.random()); + this.endCycle += 3000 * tech.droneCycleReduction * tech.bulletsLastLonger + // this.frictionAir = 0 + } + break; + } + //look for power ups to lock onto + if ( + Matter.Query.ray(map, this.position, powerUp[i].position).length === 0 //&& Matter.Query.ray(body, this.position, powerUp[i].position).length === 0 + ) { + const TARGET_VECTOR = Vector.sub(this.position, powerUp[i].position) + const DIST = Vector.magnitude(TARGET_VECTOR); + if (DIST < closeDist) { + closeDist = DIST; + this.lockedOn = powerUp[i] + } + } + } + } + } + } + } + if (this.lockedOn) { //accelerate towards mobs + this.force = Vector.mult(Vector.normalise(Vector.sub(this.position, this.lockedOn.position)), -this.mass * THRUST) + } else { //accelerate towards mouse + this.force = Vector.mult(Vector.normalise(Vector.sub(this.position, simulation.mouseInGame)), -this.mass * THRUST) + } + // speed cap instead of friction to give more agility + if (this.speed > 6) { + Matter.Body.setVelocity(this, { x: this.velocity.x * 0.97, y: this.velocity.y * 0.97 }); + } + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + Matter.Body.setVelocity(bullet[me], { x: speed * Math.cos(dir), y: speed * Math.sin(dir) }); + }, + droneRadioactive(where = { + x: m.pos.x + 30 * Math.cos(m.angle) + 20 * (Math.random() - 0.5), + y: m.pos.y + 30 * Math.sin(m.angle) + 20 * (Math.random() - 0.5) + }, speed = 1) { + const me = bullet.length; + const THRUST = (tech.isFastDrones ? 0.003 : 0.0012) + 0.0005 * (Math.random() - 0.5) + const dir = m.angle + 0.4 * (Math.random() - 0.5); + const RADIUS = 3 + bullet[me] = Bodies.polygon(where.x, where.y, 8, RADIUS, { + angle: dir, + inertia: Infinity, + friction: 0, + frictionAir: 0, + restitution: 0.4 + 0.199 * Math.random(), + dmg: 0, //0.24 damage done in addition to the damage from momentum and radiation + lookFrequency: 120 + Math.floor(23 * Math.random()), + endCycle: simulation.cycle + Math.floor((900 + 110 * Math.random()) * tech.bulletsLastLonger / tech.droneRadioDamage) + 5 * RADIUS + Math.max(0, 150 - 2 * bullet.length), + classType: "bullet", + isDrone: true, + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield //self collide + }, + minDmgSpeed: 0, + speedCap: 5 + 2 * Math.random(), //6 is normal + lockedOn: null, + deathCycles: 110 + RADIUS * 5, + isImproved: false, + radioRadius: 0, + maxRadioRadius: 270 + Math.floor(90 * Math.random()), + beforeDmg() { }, + onEnd() { + if (tech.isDroneRespawn) { + //are there any nearby bodies nearby that aren't blocked by map? + const canSee = body.filter(a => Matter.Query.ray(map, this.position, a.position).length === 0 && !a.isNotHoldable && Vector.magnitude(Vector.sub(this.position, a.position)) < 70 + 30 * a.mass) + if (canSee.length) { + //find the closest body to the drone from the canSee array + const found = canSee.reduce((a, b) => { + const distA = Vector.magnitude(Vector.sub(this.position, a.position)) + const distB = Vector.magnitude(Vector.sub(this.position, b.position)) + return distA < distB ? a : b + }) + if (found && m.energy > 0.091) { + m.energy -= 0.09 + //remove the body and spawn a new drone + Composite.remove(engine.world, found) + body.splice(body.indexOf(found), 1) + b.delayDrones(found.position, 0.5 * Math.sqrt(found.mass)) + //draw a line from the drone to the body on the canvas + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(found.position.x, found.position.y); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 2; + ctx.stroke(); + + //animate the block fading away + simulation.ephemera.push({ + name: "droneRespawn", + count: 60, //cycles before it self removes + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + ctx.beginPath(); + let vertices = found.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 2; + ctx.strokeStyle = `rgba(0,0,0,${this.count / 60})` + ctx.stroke(); + }, + }) + } + } + } + }, + do() { + //radioactive zone + this.radioRadius = this.radioRadius * 0.993 + 0.007 * this.maxRadioRadius //smooth radius towards max + //aoe damage to player + if (Vector.magnitude(Vector.sub(player.position, this.position)) < this.radioRadius) { + const DRAIN = tech.isRadioactiveResistance ? 0.001 : 0.004 + if (m.energy > DRAIN) { + if (m.immuneCycle < m.cycle) m.energy -= DRAIN + } else { + m.energy = 0; + if (simulation.dmgScale) m.damage((tech.isRadioactiveResistance ? 0.00004 : 0.0002) * tech.radioactiveDamage) //0.00015 + } + } + //aoe damage to mobs + let dmg = (0.12 + 0.04 * tech.isFastDrones) * m.dmgScale * tech.droneRadioDamage * tech.radioactiveDamage + for (let i = 0, len = mob.length; i < len; i++) { + if (Vector.magnitude(Vector.sub(mob[i].position, this.position)) < this.radioRadius + mob[i].radius) { + if (Matter.Query.ray(map, mob[i].position, this.position).length > 0) dmg *= 0.25 //reduce damage if a wall is in the way + mob[i].damage(mob[i].shield ? dmg * 3 : dmg); + mob[i].locatePlayer(); + } + } + //draw + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.radioRadius, 0, 2 * Math.PI); + ctx.globalCompositeOperation = "lighter" + // ctx.fillStyle = `rgba(25,139,170,${0.15+0.05*Math.random()})`; + // ctx.fillStyle = `rgba(36, 207, 255,${0.1+0.05*Math.random()})`; + ctx.fillStyle = `rgba(28, 175, 217,${0.13 + 0.07 * Math.random()})`; + ctx.fill(); + ctx.globalCompositeOperation = "source-over" + + //normal drone actions + if (simulation.cycle + this.deathCycles > this.endCycle) { //fall shrink and die + this.force.y += this.mass * 0.0012; + this.restitution = 0.2; + const scale = 0.995; + Matter.Body.scale(this, scale, scale); + this.maxRadioRadius = 0 + this.radioRadius = this.radioRadius * 0.98 //let radioactivity decrease + } else { + this.force.y += this.mass * 0.0002; //gravity + + if (!(simulation.cycle % this.lookFrequency)) { + //find mob targets + this.lockedOn = null; + let closeDist = Infinity; + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + !mob[i].isBadTarget && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + const TARGET_VECTOR = Vector.sub(this.position, mob[i].position) + const DIST = Vector.magnitude(TARGET_VECTOR); + if (DIST < closeDist) { + closeDist = DIST; + this.lockedOn = mob[i] + } + } + } + //power ups + if (!this.isImproved && !simulation.isChoosing) { + if (this.lockedOn) { + //grab, but don't lock onto nearby power up + for (let i = 0, len = powerUp.length; i < len; ++i) { + if ( + Vector.magnitudeSquared(Vector.sub(this.position, powerUp[i].position)) < 20000 && + !( + (m.health > 0.93 * m.maxHealth && !tech.isDroneGrab && powerUp[i].name === "heal") || + (tech.isSuperDeterminism && powerUp[i].name === "field") || + ((tech.isEnergyNoAmmo || b.inventory.length === 0) && powerUp[i].name === "ammo") + ) + ) { + //draw pickup for a single cycle + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(powerUp[i].position.x, powerUp[i].position.y); + ctx.strokeStyle = "#000" + ctx.lineWidth = 4 + ctx.stroke(); + //pick up nearby power ups + powerUps.onPickUp(powerUp[i]); + powerUp[i].effect(); + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + if (tech.isDroneGrab) { + this.isImproved = true; + const SCALE = 2.25 + Matter.Body.scale(this, SCALE, SCALE); + this.lookFrequency = 30 + Math.floor(11 * Math.random()); + this.endCycle += 1000 * tech.bulletsLastLonger + this.maxRadioRadius *= 1.25 + } + break; + } + } + } else { + //look for power ups to lock onto + let closeDist = Infinity; + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (!( + (m.health > 0.93 * m.maxHealth && !tech.isDroneGrab && powerUp[i].name === "heal") || + (tech.isSuperDeterminism && powerUp[i].name === "field") || + ((tech.isEnergyNoAmmo || b.inventory.length === 0) && powerUp[i].name === "ammo") + )) { + if (Vector.magnitudeSquared(Vector.sub(this.position, powerUp[i].position)) < 20000 && !simulation.isChoosing) { + //draw pickup for a single cycle + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(powerUp[i].position.x, powerUp[i].position.y); + ctx.strokeStyle = "#000" + ctx.lineWidth = 4 + ctx.stroke(); + //pick up nearby power ups + powerUps.onPickUp(powerUp[i]); + powerUp[i].effect(); + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + if (tech.isDroneGrab) { + this.isImproved = true; + const SCALE = 2.25 + Matter.Body.scale(this, SCALE, SCALE); + this.lookFrequency = 30 + Math.floor(11 * Math.random()); + this.endCycle += 1000 * tech.bulletsLastLonger + this.maxRadioRadius *= 1.25 + } + break; + } + //look for power ups to lock onto + if ( + Matter.Query.ray(map, this.position, powerUp[i].position).length === 0 && + Matter.Query.ray(body, this.position, powerUp[i].position).length === 0 + ) { + const TARGET_VECTOR = Vector.sub(this.position, powerUp[i].position) + const DIST = Vector.magnitude(TARGET_VECTOR); + if (DIST < closeDist) { + closeDist = DIST; + this.lockedOn = powerUp[i] + } + } + } + } + } + } + } + if (this.lockedOn) { //accelerate towards mobs + this.force = Vector.mult(Vector.normalise(Vector.sub(this.position, this.lockedOn.position)), -this.mass * THRUST) + } else { //accelerate towards mouse + this.force = Vector.mult(Vector.normalise(Vector.sub(this.position, simulation.mouseInGame)), -this.mass * THRUST) + } + // speed cap instead of friction to give more agility + if (this.speed > this.speedCap) { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.97, + y: this.velocity.y * 0.97 + }); + } + } + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + Matter.Body.setVelocity(bullet[me], { + x: speed * Math.cos(dir), + y: speed * Math.sin(dir) + }); + }, + superBall(where, velocity, radius) { + let gravity = 0.001 + if (tech.superBallDelay) { + velocity = Vector.mult(velocity, 1.4) + gravity *= 6 + } + let dir = m.angle + const me = bullet.length; + bullet[me] = Bodies.polygon(where.x, where.y, 12, radius, b.fireAttributes(dir, false)); + Composite.add(engine.world, bullet[me]); //add bullet to world + Matter.Body.setVelocity(bullet[me], velocity); + Matter.Body.setDensity(bullet[me], 0.0007 + 0.0007 * tech.isSuperHarm + 0.0007 * tech.isBulletTeleport); + bullet[me].endCycle = simulation.cycle + Math.floor(270 + 90 * Math.random()); + bullet[me].minDmgSpeed = 0; + bullet[me].restitution = 1; + bullet[me].frictionAir = 0; + bullet[me].friction = 0; + bullet[me].frictionStatic = 0; + if (tech.isSuperHarm) { + bullet[me].collidePlayerDo = function () { + this.force.y += this.mass * gravity;; + if (Matter.Query.collides(this, [player]).length) { + this.endCycle = 0 + // m.energy -= 0.04 + // if (m.energy < 0) m.energy = 0 + // simulation.drawList.push({ //add dmg to draw queue + // x: this.position.x, + // y: this.position.y, + // radius: radius, + // color: "#0ad", + // time: 15 + // }); + } + } + bullet[me].cycle = 0 + bullet[me].do = function () { + this.cycle++ + if (this.cycle > 2) this.do = this.collidePlayerDo + this.force.y += this.mass * 0.001; + }; + } else if (tech.isBulletTeleport) { + bullet[me].portFrequency = 25 + Math.floor(10 * Math.random()) + bullet[me].nextPortCycle = simulation.cycle + bullet[me].portFrequency + bullet[me].do = function () { + this.force.y += this.mass * gravity; + if (this.nextPortCycle < simulation.cycle) { //teleport around if you have tech.isBulletTeleport + this.nextPortCycle = simulation.cycle + this.portFrequency + const range = 33 * Math.sqrt(radius) * Math.random() + Matter.Body.setPosition(this, Vector.add(this.position, Vector.rotate({ x: range, y: 0 }, 2 * Math.PI * Math.random()))) + Matter.Body.setVelocity(this, Vector.rotate(this.velocity, 2 * (Math.random() * Math.random() - 0.25))) + } + }; + } else { + bullet[me].do = function () { + this.force.y += this.mass * gravity; + }; + } + bullet[me].beforeDmg = function (who) { + if (!who.isInvulnerable) { + if (tech.oneSuperBall) mobs.statusStun(who, 120) // (2.3) * 2 / 14 ticks (2x damage over 7 seconds) + if (tech.isFoamBall) { + for (let i = 0, len = 6 * this.mass; i < len; i++) { + const radius = 6 + 9 * Math.random() + const velocity = { x: Math.max(0.5, 2 - radius * 0.1), y: 0 } + b.foam(this.position, Vector.rotate(velocity, 6.28 * Math.random()), radius) + } + this.endCycle = 0 + } + if (tech.isIncendiary) { + b.explosion(this.position, this.mass * 280); //makes bullet do explosive damage at end + this.endCycle = 0 + } else if (tech.isSuperBounce) { + const cycle = () => { + Matter.Body.setDensity(this, (0.0007 + 0.0007 * tech.isSuperHarm + 0.0007 * tech.isBulletTeleport) * 1.33);//33% more density and damage + this.endCycle = simulation.cycle + Math.floor(300 + 90 * Math.random()); //reset to full duration of time + Matter.Body.setVelocity(this, Vector.mult(Vector.normalise(this.velocity), 60)); //reset to high velocity + let count = 5 + const wait = () => { + count-- + if (count > 0) requestAnimationFrame(wait); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: radius, + color: 'rgba(255, 0, 0, 0.33)', + time: 8 + }); + } + requestAnimationFrame(wait); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: radius, + color: 'rgba(255, 0, 0, 0.33)', + time: 8 + }); + } + requestAnimationFrame(cycle); + } + } + }; + }, + targetedBall(position, num = 1, speed = 42 + 12 * Math.random(), range = 1200, isRandomAim = true) { + let shotsFired = 0 + const targets = [] //target nearby mobs + for (let i = 0, len = mob.length; i < len; i++) { + const dist = Vector.magnitude(Vector.sub(position, mob[i].position)); + if ( + dist < range + mob[i].radius && + !mob[i].isBadTarget && + Matter.Query.ray(map, position, mob[i].position).length === 0 && + Matter.Query.ray(body, position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + targets.push(Vector.add(mob[i].position, Vector.mult(mob[i].velocity, dist / 60))) //predict where the mob will be in a few cycles + } + } + const radius = (11 + 9 * tech.oneSuperBall) * tech.bulletSize + for (let i = 0; i < num; i++) { + if (targets.length > 0) { // aim near a random target in array + const index = Math.floor(Math.random() * targets.length) + const SPREAD = 160 / targets.length + const WHERE = { + x: targets[index].x + SPREAD * (Math.random() - 0.5), + y: targets[index].y + SPREAD * (Math.random() - 0.5) + } + b.superBall(position, Vector.mult(Vector.normalise(Vector.sub(WHERE, position)), speed), radius) + shotsFired++ + } else if (isRandomAim) { // aim in random direction + const ANGLE = 2 * Math.PI * Math.random() + b.superBall(position, { x: speed * Math.cos(ANGLE), y: speed * Math.sin(ANGLE) }, radius) + } + } + return shotsFired + }, + targetedFoam(position, num = 1, speed = 21 + 7 * Math.random(), range = 1200, isRandomAim = true) { + let shotsFired = 0 + const targets = [] //target nearby mobs + for (let i = 0, len = mob.length; i < len; i++) { + const dist = Vector.magnitude(Vector.sub(position, mob[i].position)); + if ( + dist < range + mob[i].radius && + !mob[i].isBadTarget && //|| mob[i].isMobBullet + Matter.Query.ray(map, position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + targets.push(Vector.add(mob[i].position, Vector.mult(mob[i].velocity, dist / 60))) //predict where the mob will be in a few cycles + } + } + for (let i = 0; i < num; i++) { + if (targets.length > 0) { // aim near a random target in array + const SPREAD = 160 / targets.length + const index = Math.floor(Math.random() * targets.length) + const radius = 11 + 12 * Math.random() + const where = { + x: targets[index].x + SPREAD * (Math.random() - 0.5), + y: targets[index].y + SPREAD * (Math.random() - 0.5) + } + b.foam(position, Vector.mult(Vector.normalise(Vector.sub(where, position)), speed - radius * 0.25), radius) + shotsFired++ + } else if (isRandomAim) { // aim in random direction + const ANGLE = 2 * Math.PI * Math.random() + b.foam(position, { x: speed * Math.cos(ANGLE), y: speed * Math.sin(ANGLE) }, 8 + 11 * Math.random()) + } + } + return shotsFired + }, + foam(position, velocity, radius) { + if (tech.isFoamCavitation && Math.random() < 0.25) { + velocity = Vector.mult(velocity, 1.35) + radius = 1.2 * radius + 13 + } + // radius *= Math.sqrt(tech.bulletSize) + const me = bullet.length; + bullet[me] = Bodies.polygon(position.x, position.y, 20, radius, { + density: 0.000001, // 0.001 is normal density + inertia: Infinity, + frictionAir: 0.003, + dmg: 0, //damage on impact + damage: tech.foamDamage * (tech.isFastFoam ? 2.8 : 1) * (tech.isBulletTeleport ? 1.53 : 1), //damage done over time + scale: 1 - 0.006 / tech.bulletsLastLonger * (tech.isFastFoam ? 1.65 : 1), + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: cat.mob | cat.mobBullet // cat.map | cat.body | cat.mob | cat.mobShield + }, + minDmgSpeed: 0, + endCycle: Infinity, + count: 0, + radius: radius, + target: null, + targetVertex: null, + targetRelativePosition: null, + portFrequency: 7 + Math.floor(5 * Math.random()), + nextPortCycle: Infinity, //disabled unless you have the teleport tech + beforeDmg(who) { + if (!this.target && who.alive) { + this.target = who; + if (who.radius < 20) { + this.targetRelativePosition = { + x: 0, + y: 0 + } //find relative position vector for zero mob rotation + } else if (Matter.Query.collides(this, [who]).length > 0) { + const normal = Matter.Query.collides(this, [who])[0].normal + this.targetRelativePosition = Vector.rotate(Vector.sub(Vector.sub(this.position, who.position), Vector.mult(normal, -this.radius)), -who.angle) //find relative position vector for zero mob rotation + } else { + this.targetRelativePosition = Vector.rotate(Vector.sub(this.position, who.position), -who.angle) //find relative position vector for zero mob rotation + } + this.collisionFilter.category = cat.body; + this.collisionFilter.mask = null; + + let bestVertexDistance = Infinity + let bestVertex = null + for (let i = 0; i < this.target.vertices.length; i++) { + const dist = Vector.magnitude(Vector.sub(this.position, this.target.vertices[i])); + if (dist < bestVertexDistance) { + bestVertex = i + bestVertexDistance = dist + } + } + this.targetVertex = bestVertex + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + } + }, + onEnd() { }, + do() { + if (this.count < 20) { + this.count++ + //grow + const SCALE = 1.06 + Matter.Body.scale(this, SCALE, SCALE); + this.radius *= SCALE; + } else { + //shrink + Matter.Body.scale(this, this.scale, this.scale); + this.radius *= this.scale; + if (this.radius < 8) this.endCycle = 0; + } + if (this.target && this.target.alive) { //if stuck to a target + const rotate = Vector.rotate(this.targetRelativePosition, this.target.angle) //add in the mob's new angle to the relative position vector + if (this.target.isVerticesChange) { + Matter.Body.setPosition(this, this.target.vertices[this.targetVertex]) + } else { + Matter.Body.setPosition(this, Vector.add(Vector.add(rotate, this.target.velocity), this.target.position)) + } + if (this.target.isBoss) { + if (this.target.speed > 6.5) Matter.Body.setVelocity(this.target, Vector.mult(this.target.velocity, 0.975)) + } else { + if (this.target.speed > 2.5) Matter.Body.setVelocity(this.target, Vector.mult(this.target.velocity, 0.94)) + } + + Matter.Body.setAngularVelocity(this.target, this.target.angularVelocity * 0.9); + // Matter.Body.setAngularVelocity(this.target, this.target.angularVelocity * 0.9) + if (this.target.isShielded) { + this.target.damage(m.dmgScale * this.damage, true); //shield damage bypass + const SCALE = 1 - 0.004 / tech.bulletsLastLonger //shrink if mob is shielded + Matter.Body.scale(this, SCALE, SCALE); + this.radius *= SCALE; + } else { + this.target.damage(m.dmgScale * this.damage); + } + } else if (this.target !== null) { //look for a new target + this.collisionFilter.category = cat.bullet; + this.collisionFilter.mask = cat.mob //| cat.mobShield //cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield + Matter.Body.setVelocity(this, { x: this.target.velocity.x, y: this.target.velocity.y }); + if (tech.isSpawnBulletsOnDeath && bullet.length < 180 && !this.target.isMobBullet) { + let targets = [] + for (let i = 0, len = mob.length; i < len; i++) { + const dist = Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)); + if (dist < 1000000) targets.push(mob[i]) + } + const radius = Math.min(this.radius * 0.5, 9) + const len = bullet.length < 80 ? 2 : 1 + for (let i = 0; i < len; i++) { + if (targets.length - i > 0) { + const index = Math.floor(Math.random() * targets.length) + const speed = 6 + 6 * Math.random() + const velocity = Vector.mult(Vector.normalise(Vector.sub(targets[index].position, this.position)), speed) + b.foam(this.position, Vector.rotate(velocity, 0.5 * (Math.random() - 0.5)), radius) + } else { + b.foam(this.position, Vector.rotate({ + x: 15 + 10 * Math.random(), + y: 0 + }, 2 * Math.PI * Math.random()), radius) + } + } + } + this.target = null + } else if (Matter.Query.point(map, this.position).length > 0) { //slow when touching map + const slow = 0.87 + Matter.Body.setVelocity(this, { x: this.velocity.x * slow, y: this.velocity.y * slow }); + const SCALE = 0.97 + Matter.Body.scale(this, SCALE, SCALE); + this.radius *= SCALE; + // } else if (Matter.Query.collides(this, body).length > 0) { + } else if (Matter.Query.point(body, this.position).length > 0) { //slow when touching blocks + const slow = 0.94 + Matter.Body.setVelocity(this, { x: this.velocity.x * slow, y: this.velocity.y * slow }); + const SCALE = 0.99 + Matter.Body.scale(this, SCALE, SCALE); + this.radius *= SCALE; + } else { + this.force.y += this.mass * tech.foamGravity; //gravity + if (tech.isFoamAttract) { + for (let i = 0, len = mob.length; i < len; i++) { + const range = Vector.magnitude(Vector.sub(mob[i].position, this.position)) + if ( + !mob[i].isBadTarget && + mob[i].alive && + !mob[i].isInvulnerable && + range < 500 && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 + ) { + const mag = 0.001 * Math.min(1, 200 / range) + this.force = Vector.mult(Vector.normalise(Vector.sub(mob[i].position, this.position)), this.mass * mag) + const slow = 0.98 + Matter.Body.setVelocity(this, { x: this.velocity.x * slow, y: this.velocity.y * slow }); + break + } + } + } + } + if (this.nextPortCycle < simulation.cycle) { //teleport around if you have tech.isBulletTeleport + this.nextPortCycle = simulation.cycle + this.portFrequency + const range = 13 * Math.sqrt(this.radius) * Math.random() + Matter.Body.setPosition(this, Vector.add(this.position, Vector.rotate({ + x: range, + y: 0 + }, 2 * Math.PI * Math.random()))) + } + } + }); + if (tech.isBulletTeleport) bullet[me].nextPortCycle = simulation.cycle + bullet[me].portFrequency + Composite.add(engine.world, bullet[me]); //add bullet to world + Matter.Body.setVelocity(bullet[me], velocity); + }, + targetedBlock(who, speed = 50 - Math.min(20, who.mass * 2), range = 1600) { + let closestMob, dist + for (let i = 0, len = mob.length; i < len; i++) { + if (who !== mob[i] && !mob[i].isBadTarget && !mob[i].isInvulnerable) { + dist = Vector.magnitude(Vector.sub(who.position, mob[i].position)); + if (dist < range && Matter.Query.ray(map, who.position, mob[i].position).length === 0) { //&& Matter.Query.ray(body, position, mob[i].position).length === 0 + closestMob = mob[i] + range = dist + } + } + } + if (closestMob) { + const where = Vector.add(closestMob.position, Vector.mult(closestMob.velocity, dist / 60)) + const velocity = Vector.mult(Vector.normalise(Vector.sub(where, who.position)), speed) + velocity.y -= Math.abs(who.position.x - closestMob.position.x) / 150; //gives an arc, but not a good one + Matter.Body.setVelocity(who, velocity); + } + }, + targetedNail(position, num = 1, speed = 40 + 10 * Math.random(), range = 1200, damage = 1.4) { + let shotsFired = 0 + const targets = [] //target nearby mobs + for (let i = 0, len = mob.length; i < len; i++) { + const dist = Vector.magnitude(Vector.sub(position, mob[i].position)); + if ( + dist < range + mob[i].radius && + !mob[i].isBadTarget && //|| mob[i].isMobBullet + Matter.Query.ray(map, position, mob[i].position).length === 0 && + Matter.Query.ray(body, position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + targets.push(Vector.add(mob[i].position, Vector.mult(mob[i].velocity, dist / 60))) //predict where the mob will be in a few cycles + } + } + for (let i = 0; i < num; i++) { + if (targets.length > 0) { // aim near a random target in array + const index = Math.floor(Math.random() * targets.length) + const SPREAD = 150 / targets.length + const WHERE = { + x: targets[index].x + SPREAD * (Math.random() - 0.5), + y: targets[index].y + SPREAD * (Math.random() - 0.5) + } + b.nail(position, Vector.mult(Vector.normalise(Vector.sub(WHERE, position)), speed), damage) + shotsFired++ + } else { // aim in random direction + const ANGLE = 2 * Math.PI * Math.random() + b.nail(position, { + x: speed * Math.cos(ANGLE), + y: speed * Math.sin(ANGLE) + }, damage) + shotsFired++ + } + } + return shotsFired + }, + crit(mob, bullet) { + if (!mob.shield && Vector.dot(Vector.normalise(Vector.sub(mob.position, bullet.position)), Vector.normalise(bullet.velocity)) > 0.999 - 1 / mob.radius) { + if (mob.isFinalBoss && !(Vector.dot(Vector.normalise(Vector.sub(mob.position, bullet.position)), Vector.normalise(bullet.velocity)) > 0.999999)) return + let cycle = () => { //makes this run after damage + if (mob.health < 0.5 && mob.damageReduction > 0 && mob.alive) { + // mob.death(); + // mob.damage(this.health * Math.sqrt(this.mass) / this.damageReduction); + mob.damage(Infinity); + + const color = 'rgb(255,255,255)' + simulation.drawList.push({ + x: mob.position.x, + y: mob.position.y, + radius: mob.radius * 1.2, + color: color, //"rgba(0,0,0,0.6)", + time: 8 + }); + simulation.drawList.push({ + x: mob.position.x, + y: mob.position.y, + radius: mob.radius * 0.75, + color: color, //"rgba(0,0,0,0.85)", + time: 15 + }); + simulation.drawList.push({ + x: mob.position.x, + y: mob.position.y, + radius: mob.radius * 0.4, + color: color, //"rgb(0,0,0)", + time: 20 + }); + } + } + requestAnimationFrame(cycle); + } + }, + nail(pos, velocity, dmg = 1) { + dmg *= tech.bulletSize + const me = bullet.length; + bullet[me] = Bodies.rectangle(pos.x, pos.y, 25 * tech.bulletSize, 2 * tech.bulletSize, b.fireAttributes(Math.atan2(velocity.y, velocity.x))); + Matter.Body.setVelocity(bullet[me], velocity); + Composite.add(engine.world, bullet[me]); //add bullet to world + bullet[me].endCycle = simulation.cycle + 60 + 18 * Math.random(); + bullet[me].dmg = tech.isNailRadiation ? 0 : dmg + bullet[me].beforeDmg = function (who) { //beforeDmg is rewritten with ice crystal tech + if (tech.isNailRadiation) mobs.statusDoT(who, dmg * (tech.isFastRadiation ? 1.3 : 0.44), tech.isSlowRadiation ? 360 : (tech.isFastRadiation ? 60 : 180)) // one tick every 30 cycles + if (tech.isNailCrit) { //makes bullet do explosive damage if it hits center + if (!who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.97 - 1 / who.radius) { + b.explosion(this.position, 80 + 90 * (b.activeGun === 0) + 30 * Math.random()); //larger explosions for human aimed nail gun, smaller for auto aimed sources, like bots, and mine + } + } + this.ricochet(who) + }; + bullet[me].ricochet = function (who) { //use for normal nails, and ice crystal nails + if (tech.isRicochet) { + const targets = [] //target nearby mobs + for (let i = 0, len = mob.length; i < len; i++) { + const dist = Vector.magnitude(Vector.sub(this.position, mob[i].position)); + if ( + mob[i] !== who && + dist < 2500 + mob[i].radius && + !mob[i].isBadTarget && //|| mob[i].isMobBullet + !mob[i].isInvulnerable && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 + ) { + targets.push(Vector.add(mob[i].position, Vector.mult(mob[i].velocity, dist / 60))) //predict where the mob will be in a few cycles + } + } + if (targets.length > 0) { // aim near a random target in array + const index = Math.floor(Math.random() * targets.length) + Matter.Body.setVelocity(this, Vector.mult(Vector.normalise(Vector.sub(targets[index], this.position)), 45)); + Matter.Body.setAngle(this, Math.atan2(this.velocity.y, this.velocity.x)) + Matter.Body.setAngularVelocity(this, 0); + } + this.dmg += 2 + } + } + bullet[me].do = function () { }; + }, + needle(angle = m.angle) { + const me = bullet.length; + bullet[me] = Bodies.rectangle(m.pos.x + 40 * Math.cos(m.angle), m.pos.y + 40 * Math.sin(m.angle), 75 * tech.bulletSize, 0.75 * tech.bulletSize, b.fireAttributes(angle)); + Matter.Body.setDensity(bullet[me], 0.00001); //0.001 is normal + bullet[me].immuneList = [] + bullet[me].dmg = 6 + if (tech.needleTunnel) { + bullet[me].dmg *= 1.2 + bullet[me].endCycle = simulation.cycle + 300; + bullet[me].collisionFilter.mask = tech.isShieldPierce ? 0 : cat.mobShield + // bullet[me].turnRate = 0.005 * (Math.random() - 0.5) + bullet[me].isInMap = false + bullet[me].do = function () { + const whom = Matter.Query.collides(this, mob) + if (whom.length && this.speed > 20) { //if touching a mob + for (let i = 0, len = whom.length; i < len; i++) { + who = whom[i].bodyA + if (who && who.mob) { + let immune = false + for (let i = 0; i < this.immuneList.length; i++) { //check if this needle has hit this mob already + if (this.immuneList[i] === who.id) { + immune = true + break + } + } + if (!immune) { + if (tech.isNailCrit) { + if (!who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.97 - 1 / who.radius) { + b.explosion(this.position, 220 + 50 * Math.random()); //makes bullet do explosive damage at end + } + } else if (tech.isCritKill) b.crit(who, this) + + this.immuneList.push(who.id) //remember that this needle has hit this mob once already + let dmg = this.dmg * tech.bulletSize * m.dmgScale + if (tech.isNailRadiation) { + mobs.statusDoT(who, (tech.isFastRadiation ? 6 : 2) * tech.bulletSize, tech.isSlowRadiation ? 360 : (tech.isFastRadiation ? 60 : 180)) // one tick every 30 cycles + dmg *= 0.25 + } + if (tech.isCrit && who.isStunned) dmg *= 4 + who.damage(dmg, tech.isShieldPierce); + if (who.alive) who.foundPlayer(); + if (who.damageReduction) { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.log(dmg + 1.1) * 40 * who.damageReduction + 3, + color: simulation.playerDmgColor, + time: simulation.drawTime + }); + } + } + } + } + } else if (Matter.Query.collides(this, map).length) { //penetrate walls + if (!this.isInMap) { //turn after entering the map, but only turn once + this.isInMap = true + Matter.Body.setVelocity(this, Vector.rotate(this.velocity, 0.25 * (Math.random() - 0.5))); + Matter.Body.setAngle(this, Math.atan2(this.velocity.y, this.velocity.x)) + } + Matter.Body.setPosition(this, Vector.add(this.position, Vector.mult(this.velocity, -0.98))) //move back 1/2 your velocity = moving at 1/2 speed + } else if (Matter.Query.collides(this, body).length) { //penetrate blocks + Matter.Body.setAngularVelocity(this, 0) + Matter.Body.setPosition(this, Vector.add(this.position, Vector.mult(this.velocity, -0.94))) //move back 1/2 your velocity = moving at 1/2 speed + } else if (this.speed < 30) { + this.force.y += this.mass * 0.001; //no gravity until it slows down to improve aiming + } + }; + } else { + bullet[me].endCycle = simulation.cycle + 100; + bullet[me].collisionFilter.mask = tech.isShieldPierce ? cat.body : cat.body | cat.mobShield + bullet[me].do = function () { + const whom = Matter.Query.collides(this, mob) + if (whom.length && this.speed > 20) { //if touching a mob + for (let i = 0, len = whom.length; i < len; i++) { + who = whom[i].bodyA + if (who && who.mob) { + let immune = false + for (let i = 0; i < this.immuneList.length; i++) { //check if this needle has hit this mob already + if (this.immuneList[i] === who.id) { + immune = true + break + } + } + if (!immune) { + if (tech.isNailCrit) { + if (!who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.97 - 1 / who.radius) { + b.explosion(this.position, 220 + 50 * Math.random()); //makes bullet do explosive damage at end + } + } else if (tech.isCritKill) b.crit(who, this) + + this.immuneList.push(who.id) //remember that this needle has hit this mob once already + let dmg = this.dmg * tech.bulletSize * m.dmgScale + if (tech.isNailRadiation) { + mobs.statusDoT(who, (tech.isFastRadiation ? 6 : 2) * tech.bulletSize, tech.isSlowRadiation ? 360 : (tech.isFastRadiation ? 60 : 180)) // one tick every 30 cycles + dmg *= 0.25 + } + if (tech.isCrit && who.isStunned) dmg *= 4 + who.damage(dmg, tech.isShieldPierce); + if (who.alive) who.foundPlayer(); + if (who.damageReduction) { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.log(dmg + 1.1) * 40 * who.damageReduction + 3, + color: simulation.playerDmgColor, + time: simulation.drawTime + }); + } + } + } + } + } else if (Matter.Query.collides(this, map).length) { //stick in walls + this.collisionFilter.mask = 0; + Matter.Body.setAngularVelocity(this, 0) + Matter.Body.setVelocity(this, { + x: 0, + y: 0 + }); + this.do = function () { + if (!Matter.Query.collides(this, map).length) this.force.y += this.mass * 0.001; + } + if (tech.isNeedleIce) { + b.iceIX(5 + 5 * Math.random(), 2 * Math.PI * Math.random(), this.position) // iceIX(speed = 0, dir = m.angle + Math.PI * 2 * Math.random(), where = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) }) { + if (0.5 < Math.random()) b.iceIX(5 + 5 * Math.random(), 2 * Math.PI * Math.random(), this.position) + } + } else if (this.speed < 30) { + this.force.y += this.mass * 0.001; //no gravity until it slows down to improve aiming + } + }; + } + const SPEED = 90 + Matter.Body.setVelocity(bullet[me], { + x: 0.5 * player.velocity.x + SPEED * Math.cos(angle), + y: 0.5 * player.velocity.y + SPEED * Math.sin(angle) + }); + // Matter.Body.setDensity(bullet[me], 0.00001); + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + // ************************************************************************************************** + // ************************************************************************************************** + // ******************************** Bots ********************************************* + // ************************************************************************************************** + // ************************************************************************************************** + totalBots() { + return tech.dynamoBotCount + tech.foamBotCount + tech.soundBotCount + tech.nailBotCount + tech.laserBotCount + tech.boomBotCount + tech.orbitBotCount + tech.plasmaBotCount + tech.missileBotCount + }, + hasBotUpgrade() { + return tech.isNailBotUpgrade + tech.isFoamBotUpgrade + tech.isBoomBotUpgrade + tech.isLaserBotUpgrade + tech.isOrbitBotUpgrade + tech.isDynamoBotUpgrade + tech.isSoundBotUpgrade + }, + convertBotsTo(type) { //type can be a string like "dynamoBotCount" + const totalPermanentBots = b.totalBots() + //remove all bots techs and convert them to the new type so that tech refunds work correctly + let totalTechToConvert = 0 //count how many tech need to be converted + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].count && tech.tech[i].isBot) { + totalTechToConvert += tech.tech[i].count + tech.removeTech(i) + } + } + //remove all bots + b.zeroBotCount() + b.clearPermanentBots() + for (let i = 0; i < totalTechToConvert; i++) tech.giveTech(type) //spawn tech for the correct bot type + + //find index of new bot type tech effect + let index = null + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].name === type) { + index = i + break + } + } + for (let i = 0, len = totalPermanentBots - totalTechToConvert; i < len; i++) tech.tech[index].effect(); //also convert any permanent bots that didn't come from a tech + //in experiment mode set the unselect color for bot tech that was converted + // if (build.isExperimentSelection) { } + }, + clearPermanentBots() { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType && bullet[i].endCycle === Infinity) bullet[i].endCycle = 0 //remove active bots, but don't remove temp bots + } + }, + removeBot() { + if (tech.nailBotCount > 1) { + tech.nailBotCount-- + return + } + if (tech.laserBotCount > 1) { + tech.laserBotCount-- + return + } + if (tech.foamBotCount > 1) { + tech.foamBotCount-- + return + } + if (tech.soundBotCount > 1) { + tech.soundBotCount-- + return + } + if (tech.boomBotCount > 1) { + tech.boomBotCount-- + return + } + if (tech.orbitBotCount > 1) { + tech.orbitBotCount-- + return + } + if (tech.dynamoBotCount > 1) { + tech.dynamoBotCount-- + return + } + if (tech.missileBotCount > 1) { + tech.missileBotCount-- + return + } + if (tech.plasmaBotCount > 1) { + tech.plasmaBotCount-- + return + } + }, + zeroBotCount() { //remove all bots + tech.dynamoBotCount = 0; + tech.nailBotCount = 0; + tech.laserBotCount = 0; + tech.orbitBotCount = 0; + tech.foamBotCount = 0; + tech.soundBotCount = 0; + tech.boomBotCount = 0; + tech.plasmaBotCount = 0; + tech.missileBotCount = 0; + }, + respawnBots() { + for (let i = 0; i < tech.dynamoBotCount; i++) b.dynamoBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }, !level.isSlowBots) + for (let i = 0; i < tech.laserBotCount; i++) b.laserBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }, !level.isSlowBots) + for (let i = 0; i < tech.nailBotCount; i++) b.nailBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }, !level.isSlowBots) + for (let i = 0; i < tech.foamBotCount; i++) b.foamBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }, !level.isSlowBots) + for (let i = 0; i < tech.soundBotCount; i++) b.soundBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }, !level.isSlowBots) + for (let i = 0; i < tech.boomBotCount; i++) b.boomBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }, !level.isSlowBots) + for (let i = 0; i < tech.orbitBotCount; i++) b.orbitBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }, !level.isSlowBots) + for (let i = 0; i < tech.plasmaBotCount; i++) b.plasmaBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }) + for (let i = 0; i < tech.missileBotCount; i++) b.missileBot({ + x: player.position.x + 50 * (Math.random() - 0.5), + y: player.position.y + 50 * (Math.random() - 0.5) + }) + if (tech.isIntangible && m.isCloak) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) bullet[i].collisionFilter.mask = cat.map | cat.bullet | cat.mobBullet | cat.mobShield + } + } + }, + randomBot(where = player.position, isKeep = true, isLaser = true) { + if (Math.random() < 0.5) { //chance to match bot to your upgrade + if (tech.isNailBotUpgrade) { //check for upgrades first + b.nailBot(where, isKeep) + if (isKeep) tech.nailBotCount++; + } else if (tech.isFoamBotUpgrade) { + b.foamBot(where, isKeep) + if (isKeep) tech.foamBotCount++; + } else if (tech.isSoundBotUpgrade) { + b.soundBot(where, isKeep) + if (isKeep) tech.soundBotCount++; + } else if (tech.isBoomBotUpgrade) { + b.boomBot(where, isKeep) + if (isKeep) tech.boomBotCount++; + } else if (tech.isLaserBotUpgrade) { + b.laserBot(where, isKeep) + if (isKeep) tech.laserBotCount++; + } else if (tech.isOrbitBotUpgrade) { + b.orbitBot(where, isKeep); + if (isKeep) tech.orbitBotCount++; + } else if (tech.isDynamoBotUpgrade) { + b.dynamoBot(where, isKeep) + if (isKeep) tech.dynamoBotCount++; + } else if (Math.random() < 0.143) { //random + b.soundBot(where, isKeep) + if (isKeep) tech.soundBotCount++; + } else if (Math.random() < 0.166 && isLaser) { + b.laserBot(where, isKeep) + if (isKeep) tech.laserBotCount++; + } else if (Math.random() < 0.2) { + b.dynamoBot(where, isKeep) + if (isKeep) tech.dynamoBotCount++; + } else if (Math.random() < 0.25) { + b.orbitBot(where, isKeep); + if (isKeep) tech.orbitBotCount++; + } else if (Math.random() < 0.33) { + b.nailBot(where, isKeep) + if (isKeep) tech.nailBotCount++; + } else if (Math.random() < 0.5) { + b.foamBot(where, isKeep) + if (isKeep) tech.foamBotCount++; + } else { + b.boomBot(where, isKeep) + if (isKeep) tech.boomBotCount++; + } + } else { //else don't match bot to upgrade + if (Math.random() < 0.143) { //random + b.soundBot(where, isKeep) + if (isKeep) tech.soundBotCount++; + } else if (Math.random() < 0.166 && isLaser) { //random + b.laserBot(where, isKeep) + if (isKeep) tech.laserBotCount++; + } else if (Math.random() < 0.2) { + b.dynamoBot(where, isKeep) + if (isKeep) tech.dynamoBotCount++; + } else if (Math.random() < 0.25) { + b.orbitBot(where, isKeep); + if (isKeep) tech.orbitBotCount++; + } else if (Math.random() < 0.33) { + b.nailBot(where, isKeep) + if (isKeep) tech.nailBotCount++; + } else if (Math.random() < 0.5) { + b.foamBot(where, isKeep) + if (isKeep) tech.foamBotCount++; + } else { + b.boomBot(where, isKeep) + if (isKeep) tech.boomBotCount++; + } + } + + }, + setDynamoBotDelay() { + let total = 0 + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'dynamo') total++ + } + let count = 0 + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'dynamo') { + count++ + const step = Math.max(60 - 3 * total, 10) + if (bullet[i].isKeep) { + bullet[i].followDelay = (step * count) % 600 + } else { + bullet[i].followDelay = Math.floor(step * bullet.length * Math.random()) % 600 + } + } + } + }, + dynamoBot(position = player.position, isKeep = true) { + const me = bullet.length; + bullet[me] = Bodies.polygon(position.x, position.y, 5, 10, { + isUpgraded: tech.isDynamoBotUpgrade, + botType: "dynamo", + friction: 0, + frictionStatic: 0, + frictionAir: 0.02, + spin: 0.07 * (Math.random() < 0.5 ? -1 : 1), + // isStatic: true, + isKeep: isKeep, + isSensor: true, + restitution: 0, + dmg: 0, // 0.14 //damage done in addition to the damage from momentum + minDmgSpeed: 0, + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: 0 //cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield + }, + beforeDmg() { }, + onEnd() { + b.setDynamoBotDelay() + }, + followDelay: 0, + phase: Math.floor(60 * Math.random()), + do() { + // if (Vector.magnitude(Vector.sub(this.position, player.position)) < 150) { + // ctx.fillStyle = "rgba(0,0,0,0.06)"; + // ctx.beginPath(); + // ctx.arc(this.position.x, this.position.y, 150, 0, 2 * Math.PI); + // ctx.fill(); + // } + + //check for damage + if (m.immuneCycle < m.cycle && !((m.cycle + this.phase) % 30)) { //twice a second + if (Vector.magnitude(Vector.sub(this.position, player.position)) < 250 && m.immuneCycle < m.cycle) { //give energy + Matter.Body.setAngularVelocity(this, this.spin) + if (this.isUpgraded) { + m.energy += 0.12 * level.isReducedRegen + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 10, + color: m.fieldMeterColor, + time: simulation.drawTime + }); + } else { + m.energy += 0.04 * level.isReducedRegen + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 5, + color: m.fieldMeterColor, + time: simulation.drawTime + }); + } + } + } + + if (!m.isCloak) { //if cloaking field isn't active + const size = 33 - 6 * isKeep + q = Matter.Query.region(mob, { + min: { + x: this.position.x - size, + y: this.position.y - size + }, + max: { + x: this.position.x + size, + y: this.position.y + size + } + }) + for (let i = 0; i < q.length; i++) { + if (!q[i].isShielded) { + Matter.Body.setAngularVelocity(this, this.spin) + // mobs.statusStun(q[i], 180) + // const dmg = 0.5 * m.dmgScale * (this.isUpgraded ? 2.5 : 1) + const dmg = 0.5 * m.dmgScale + q[i].damage(dmg); + if (q[i].alive) q[i].foundPlayer(); + if (q[i].damageReduction) { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + // radius: 600 * dmg * q[i].damageReduction, + radius: Math.sqrt(2000 * dmg * q[i].damageReduction) + 2, + color: 'rgba(0,0,0,0.4)', + time: simulation.drawTime + }); + } + } + } + } + let history = m.history[(m.cycle - this.followDelay) % 600] + Matter.Body.setPosition(this, { x: history.position.x, y: history.position.y - history.yOff + 24.2859 }) //bullets move with player + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + b.setDynamoBotDelay() + }, + nailBot(position = { x: player.position.x + 50 * (Math.random() - 0.5), y: player.position.y + 50 * (Math.random() - 0.5) }, isKeep = true) { + const me = bullet.length; + const dir = m.angle; + const RADIUS = (12 + 4 * Math.random()) + bullet[me] = Bodies.polygon(position.x, position.y, 4, RADIUS, { + isUpgraded: tech.isNailBotUpgrade, + botType: "nail", + angle: dir, + friction: 0, + frictionStatic: 0, + frictionAir: 0.05, + restitution: 0.6 * (1 + 0.5 * Math.random()), + dmg: 0, // 0.14 //damage done in addition to the damage from momentum + minDmgSpeed: 2, + // lookFrequency: 56 + Math.floor(17 * Math.random()) - isUpgraded * 20, + lastLookCycle: simulation.cycle + 60 * Math.random(), + delay: Math.floor((tech.isNailBotUpgrade ? 22 : 85) + 10 * isKeep), + acceleration: (isKeep ? 0.005 : 0.001) * (1 + 0.5 * Math.random()), + range: 60 * (1 + 0.3 * Math.random()) + 3 * b.totalBots() + !isKeep * 100, + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: b.totalBots() < 50 ? cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield : cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield //if over 50 bots, they no longer collide with each other + }, + beforeDmg() { }, + onEnd() { }, + do() { + const distanceToPlayer = Vector.magnitude(Vector.sub(this.position, m.pos)) + if (distanceToPlayer > this.range) { //if far away move towards player + this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, this.position)), this.mass * this.acceleration) + } else { //close to player + Matter.Body.setVelocity(this, Vector.add(Vector.mult(this.velocity, 0.90), Vector.mult(player.velocity, 0.17))); //add player's velocity + if (this.lastLookCycle < simulation.cycle && !m.isCloak) { + this.lastLookCycle = simulation.cycle + this.delay + for (let i = 0, len = mob.length; i < len; i++) { + const dist = Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)); + if ( + !mob[i].isBadTarget && + dist < 3000000 && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 && + !mob[i].isShielded && + !mob[i].isInvulnerable + ) { + const unit = Vector.normalise(Vector.sub(Vector.add(mob[i].position, Vector.mult(mob[i].velocity, Math.sqrt(dist) / 60)), this.position)) + if (this.isUpgraded) { + const SPEED = 60 + b.nail(this.position, Vector.mult(unit, SPEED)) + this.force = Vector.mult(unit, -0.02 * this.mass) + } else { + const SPEED = 45 + b.nail(this.position, Vector.mult(unit, SPEED)) + this.force = Vector.mult(unit, -0.012 * this.mass) + } + break; + } + } + } + } + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + missileBot(position = { x: player.position.x + 50 * (Math.random() - 0.5), y: player.position.y + 50 * (Math.random() - 0.5) }, isKeep = true) { + const me = bullet.length; + bullet[me] = Bodies.rectangle(position.x, position.y, 28, 11, { + botType: "missile", + angle: m.angle, + friction: 0, + frictionStatic: 0, + frictionAir: 0.04, + restitution: 0.7, + dmg: 0, // 0.14 //damage done in addition to the damage from momentum + minDmgSpeed: 2, + lookFrequency: 26 + Math.ceil(6 * Math.random()), + cd: 0, + delay: Math.floor(60), + range: 70 + 3 * b.totalBots(), + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: b.totalBots() < 50 ? (cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield) : (cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield) //if over 50 bots, they no longer collide with each other + }, + beforeDmg() { }, + onEnd() { }, + do() { + const distanceToPlayer = Vector.magnitude(Vector.sub(this.position, m.pos)) + if (distanceToPlayer > this.range) { //if far away move towards player + this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, this.position)), this.mass * 0.006) + } else { //close to player + Matter.Body.setVelocity(this, Vector.add(Vector.mult(this.velocity, 0.90), Vector.mult(player.velocity, 0.17))); //add player's velocity + if (this.cd < simulation.cycle && !(simulation.cycle % this.lookFrequency) && !m.isCloak) { + for (let i = 0, len = mob.length; i < len; i++) { + const dist2 = Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)); + if ( + mob[i].alive && + !mob[i].isBadTarget && + dist2 > 40000 && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + this.cd = simulation.cycle + this.delay; + const angle = Vector.angle(this.position, mob[i].position) + Matter.Body.setAngle(this, angle) + // Matter.Body.setAngularVelocity(this, 0.025) + this.torque += this.inertia * 0.00004 * (Math.round(Math.random()) ? 1 : -1) + this.force = Vector.mult(Vector.normalise(Vector.sub(this.position, mob[i].position)), this.mass * 0.02) + + if (tech.missileCount > 1) { + const countReduction = Math.pow(0.85, tech.missileCount) + const size = Math.sqrt(countReduction) + const direction = { x: Math.cos(angle), y: Math.sin(angle) } + const push = Vector.mult(Vector.perp(direction), 0.015 * countReduction / Math.sqrt(tech.missileCount)) + for (let i = 0; i < tech.missileCount; i++) { + setTimeout(() => { + b.missile(this.position, angle, -8, size) + bullet[bullet.length - 1].force.x += push.x * (i - (tech.missileCount - 1) / 2); + bullet[bullet.length - 1].force.y += push.y * (i - (tech.missileCount - 1) / 2); + }, 40 * tech.missileCount * Math.random()); + } + } else { + b.missile(this.position, angle, -8) // missile(where, angle, speed, size = 1) { + } + break; + } + } + } + } + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + foamBot(position = { x: player.position.x + 50 * (Math.random() - 0.5), y: player.position.y + 50 * (Math.random() - 0.5) }, isKeep = true) { + const me = bullet.length; + const dir = m.angle; + const RADIUS = (10 + 5 * Math.random()) + bullet[me] = Bodies.polygon(position.x, position.y, 6, RADIUS, { + isUpgraded: tech.isFoamBotUpgrade, + botType: "foam", + angle: dir, + friction: 0, + frictionStatic: 0, + frictionAir: 0.05, + restitution: 0.6 * (1 + 0.5 * Math.random()), + dmg: 0, // 0.14 //damage done in addition to the damage from momentum + minDmgSpeed: 2, + lookFrequency: 60 + Math.floor(17 * Math.random()) - 50 * tech.isFoamBotUpgrade, + cd: 0, + fireCount: 0, + fireLimit: 5 + 2 * tech.isFoamBotUpgrade - isKeep, + delay: Math.floor((200 + (tech.isFoamBotUpgrade ? 0 : 200))),// + 30 - 20 * tech.isFoamBotUpgrade,//20 + Math.floor(85 * b.fireCDscale) - 20 * tech.isFoamBotUpgrade, + acceleration: (isKeep ? 0.005 : 0.001) * (1 + 0.5 * Math.random()), + range: 60 * (1 + 0.3 * Math.random()) + 3 * b.totalBots() + !isKeep * 100, //how far from the player the bot will move + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: b.totalBots() < 50 ? cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield : cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield //if over 50 bots, they no longer collide with each other + }, + beforeDmg() { }, + onEnd() { }, + fireTarget: { x: 0, y: 0 }, + fire() { + this.fireCount++ + if (this.fireCount > this.fireLimit) { + this.fireCount = 0 + this.cd = simulation.cycle + this.delay; + } // else {this.cd = simulation.cycle + 1;} + + const radius = 5 + 3 * Math.random() + const SPEED = Math.max(5, 25 - radius * 0.4); //(m.crouch ? 32 : 20) - radius * 0.7; + const velocity = Vector.mult(Vector.normalise(Vector.sub(this.fireTarget, this.position)), SPEED) + b.foam(this.position, Vector.rotate(velocity, 0.07 * (Math.random() - 0.5)), radius + 5 * this.isUpgraded) + + //recoil + // const force = Vector.mult(Vector.normalise(velocity), 0.005 * this.mass * (tech.isFoamCavitation ? 2 : 1)) + const force = Vector.mult(velocity, 0.0001 * this.mass * (tech.isFoamCavitation ? 2 : 1)) + this.force.x -= force.x + this.force.y -= force.y + }, + do() { + if (this.fireCount === 0) { //passive mode: look for targets and following player + const distanceToPlayer = Vector.magnitude(Vector.sub(this.position, m.pos)) + if (distanceToPlayer > this.range) { //if far away move towards player + this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, this.position)), this.mass * this.acceleration) + } else { //close to player + Matter.Body.setVelocity(this, Vector.add(Vector.mult(this.velocity, 0.90), Vector.mult(player.velocity, 0.17))); //add player's velocity + } + + if (this.cd < simulation.cycle && !m.isCloak && !(simulation.cycle % this.lookFrequency)) { + for (let i = 0, len = mob.length; i < len; i++) { + const dist2 = Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)); + if (dist2 < 1600000 && !mob[i].isBadTarget && Matter.Query.ray(map, this.position, mob[i].position).length === 0 && !mob[i].isInvulnerable) { + this.fireTarget = Vector.add(mob[i].position, Vector.mult(mob[i].velocity, Math.sqrt(dist2) / 60)) //set target to where the mob will be in 1 second + this.fire() + break; + } + } + } + } else { //fire mode: quickly fire at targets and doesn't follow player + this.fire() + } + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + soundBot(position = { x: player.position.x + 50 * (Math.random() - 0.5), y: player.position.y + 50 * (Math.random() - 0.5) }, isKeep = true) { + const me = bullet.length; + const dir = m.angle; + bullet[me] = Bodies.rectangle(position.x, position.y, 12, 30, { + isUpgraded: tech.isSoundBotUpgrade, + botType: "sound", + angle: dir, + friction: 0, + frictionStatic: 0, + frictionAir: 0.05, + restitution: 0.6 * (1 + 0.5 * Math.random()), + dmg: 0, // 0.14 //damage done in addition to the damage from momentum + minDmgSpeed: 2, + lookFrequency: 17 + Math.floor(7 * Math.random()) - 3 * tech.isSoundBotUpgrade, + cd: 0, + fireCount: 0, + fireLimit: 5 - isKeep, + delay: Math.floor(140),// + 30 - 20 * tech.isFoamBotUpgrade,//20 + Math.floor(85 * b.fireCDscale) - 20 * tech.isFoamBotUpgrade, + acceleration: (isKeep ? 0.005 : 0.001) * (1 + 0.5 * Math.random()), + range: 60 * (1 + 0.3 * Math.random()) + 3 * b.totalBots() + !isKeep * 100, //how far from the player the bot will move + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: b.totalBots() < 50 ? cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield : cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield //if over 50 bots, they no longer collide with each other + }, + beforeDmg() { }, + onEnd() { }, + fireTarget: { x: 0, y: 0 }, + waves: [], + phononWaveCD: 0, + addWave(where, angle) { + const halfArc = 0.2 * (tech.isBulletTeleport ? 0.66 + (Math.random() - 0.5) : 1) + 0.04 * tech.isSoundBotUpgrade //6.28 is a full circle, but these arcs needs to stay small because we are using small angle linear approximation, for collisions + this.waves.push({ + position: where, + angle: angle - halfArc, //used in drawing ctx.arc + unit1: { x: Math.cos(angle - halfArc), y: Math.sin(angle - halfArc) }, //used for collision + unit2: { x: Math.cos(angle + halfArc), y: Math.sin(angle + halfArc) }, //used for collision + arc: halfArc * 2, + radius: 25, + resonanceCount: 0, + dmg: (tech.isUpgraded ? 9 : 1.5) * m.dmgScale * tech.wavePacketDamage * tech.waveBeamDamage * (tech.isBulletTeleport ? 1.5 : 1), + }) + }, + fire() { + if (!(simulation.cycle % 6)) { + this.fireCount++ + if (this.fireCount > this.fireLimit) { + this.fireCount = 0 + this.cd = simulation.cycle + this.delay; + } + this.addWave({ x: this.position.x, y: this.position.y }, Math.atan2(this.fireTarget.y - this.position.y, this.fireTarget.x - this.position.x) + tech.isBulletTeleport * 0.3 * (Math.random() - 0.5)) //add wave to waves array + //face target + Matter.Body.setAngle(this, Vector.angle(this.position, this.fireTarget)); + } + }, + do() { + if (this.fireCount === 0) { //passive mode: look for targets and following player + const distanceToPlayer = Vector.magnitude(Vector.sub(this.position, m.pos)) + if (distanceToPlayer > this.range) { //if far away move towards player + this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, this.position)), this.mass * this.acceleration) + } else { //close to player + Matter.Body.setVelocity(this, Vector.add(Vector.mult(this.velocity, 0.90), Vector.mult(player.velocity, 0.17))); //add player's velocity + } + if (this.cd < simulation.cycle && !m.isCloak && !(simulation.cycle % this.lookFrequency)) { + for (let i = 0, len = mob.length; i < len; i++) { + const dist2 = Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)); + if (dist2 < 1300000 && !mob[i].isBadTarget && (Matter.Query.ray(map, this.position, mob[i].position).length === 0 || dist2 < 300000) && !mob[i].isInvulnerable) { + this.fireTarget = Vector.add(mob[i].position, Vector.mult(mob[i].velocity, Math.sqrt(dist2) / 60)) //set target to where the mob will be in 1 second + this.fire() + break; + } + } + } + } else { //fire mode: quickly fire at targets and doesn't follow player + this.fire() + } + if (!m.isTimeDilated) { //update current waves + ctx.strokeStyle = "rgba(0,0,0,0.6)" //"000"; + ctx.lineWidth = 2 * tech.wavePacketDamage + ctx.beginPath(); + const end = 1200 * Math.sqrt(tech.bulletsLastLonger) + //this does less damage than the player phonon waves 2.3 -> 2 + for (let i = this.waves.length - 1; i > -1; i--) { + const v1 = Vector.add(this.waves[i].position, Vector.mult(this.waves[i].unit1, this.waves[i].radius)) + const v2 = Vector.add(this.waves[i].position, Vector.mult(this.waves[i].unit2, this.waves[i].radius)) + //draw wave + ctx.moveTo(v1.x, v1.y) + ctx.arc(this.waves[i].position.x, this.waves[i].position.y, this.waves[i].radius, this.waves[i].angle, this.waves[i].angle + this.waves[i].arc); + //using small angle linear approximation of circle arc, this will not work if the arc gets large // https://stackoverflow.com/questions/13652518/efficiently-find-points-inside-a-circle-sector + let hits = Matter.Query.ray(mob, v1, v2, 50) + for (let j = 0; j < hits.length; j++) { + const who = hits[j].body + if (!who.isShielded) { + who.force.x += 0.01 * (Math.random() - 0.5) * who.mass + who.force.y += 0.01 * (Math.random() - 0.5) * who.mass + Matter.Body.setVelocity(who, { x: who.velocity.x * 0.98, y: who.velocity.y * 0.98 }); + let vertices = who.vertices; + const vibe = 50 + who.radius * 0.15 + ctx.moveTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x + vibe * (Math.random() - 0.5), vertices[j].y + vibe * (Math.random() - 0.5)); + ctx.lineTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + who.locatePlayer(); + who.damage(this.waves[i].dmg / Math.pow(who.radius, 0.33)); + + + if (tech.isPhononWave && this.phononWaveCD < m.cycle) { + this.phononWaveCD = m.cycle + 10 * (1 + this.waves[i].resonanceCount) + let closestMob, dist + let range = end - 30 * this.waves[i].resonanceCount + for (let i = 0, len = mob.length; i < len; i++) { + if (who !== mob[i] && !mob[i].isBadTarget && !mob[i].isInvulnerable) { + dist = Vector.magnitude(Vector.sub(who.position, mob[i].position)); + if (dist < range) { + closestMob = mob[i] + range = dist + } + } + } + if (closestMob) { //add wave to waves array + this.addWave(who.position, Math.atan2(closestMob.position.y - who.position.y, closestMob.position.x - who.position.x) + tech.isBulletTeleport * 0.3 * (Math.random() - 0.5)) + } else { + this.addWave(who.position, Math.random() * Math.PI) + } + this.waves[this.waves.length - 1].resonanceCount = this.waves[i].resonanceCount + 1 + break + } + } + } + + hits = Matter.Query.ray(body, v1, v2, 50) //Matter.Query.ray(bodies, startPoint, endPoint, [rayWidth]) + for (let j = 0, len = Math.min(30, hits.length); j < len; j++) { + const who = hits[j].body + //make them shake around + who.force.x += 0.005 * (Math.random() - 0.5) * who.mass + who.force.y += (0.005 * (Math.random() - 0.5) - simulation.g * 0.1) * who.mass //remove force of gravity + let vertices = who.vertices; + const vibe = 25 + ctx.moveTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x + vibe * (Math.random() - 0.5), vertices[j].y + vibe * (Math.random() - 0.5)); + } + ctx.lineTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + + if (tech.isPhononBlock && !who.isNotHoldable && who.speed < 5 && who.angularSpeed < 0.1) { + if (Math.random() < 0.5) b.targetedBlock(who, 50 - Math.min(25, who.mass * 3)) // targetedBlock(who, speed = 50 - Math.min(20, who.mass * 2), range = 1600) { + // Matter.Body.setAngularVelocity(who, (0.25 + 0.12 * Math.random()) * (Math.random() < 0.5 ? -1 : 1)); + who.torque += who.inertia * 0.001 * (Math.random() - 0.5) + } + } + + this.waves[i].radius += tech.waveBeamSpeed * 2 + if (this.waves[i].radius > end - 30 * this.waves[i].resonanceCount) { + this.waves.splice(i, 1) //end + } + } + ctx.stroke(); + } + + + + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + laserBot(position = { x: player.position.x + 50 * (Math.random() - 0.5), y: player.position.y + 50 * (Math.random() - 0.5) }, isKeep = true) { + const me = bullet.length; + const dir = m.angle; + const RADIUS = (14 + 6 * Math.random()) + bullet[me] = Bodies.polygon(position.x, position.y, 3, RADIUS, { + botType: "laser", + angle: dir, + friction: 0, + frictionStatic: 0, + frictionAir: 0.008 * (1 + 0.3 * Math.random()), + restitution: 0.5 * (1 + 0.5 * Math.random()), + acceleration: 0.0015 * (1 + 0.3 * Math.random()), + playerRange: 140 + Math.floor(30 * Math.random()) + 2 * b.totalBots(), + offPlayer: { x: 0, y: 0, }, + dmg: 0, //damage done in addition to the damage from momentum + minDmgSpeed: 2, + lookFrequency: 20 + Math.floor(7 * Math.random()) - 13 * tech.isLaserBotUpgrade, + range: (600 + 375 * tech.isLaserBotUpgrade) * (1 + 0.12 * Math.random()), + drainThreshold: 0.15 + 0.5 * Math.random() + (tech.isEnergyHealth ? 0.3 : 0),// laser bot will not attack if the player is below this energy + drain: (0.57 - 0.43 * tech.isLaserBotUpgrade + isKeep * 0.08) * tech.laserDrain, + laserDamage: 0.75 + 0.75 * tech.isLaserBotUpgrade, + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: b.totalBots() < 50 ? cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield : cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield //if over 50 bots, they no longer collide with each other + }, + lockedOn: null, + beforeDmg() { + this.lockedOn = null + }, + onEnd() { }, + do() { + const playerPos = Vector.add(Vector.add(this.offPlayer, m.pos), Vector.mult(player.velocity, 20)) //also include an offset unique to this bot to keep many bots spread out + const farAway = Math.max(0, (Vector.magnitude(Vector.sub(this.position, playerPos))) / this.playerRange) //linear bounding well + const mag = Math.min(farAway, 4) * this.mass * this.acceleration + this.force = Vector.mult(Vector.normalise(Vector.sub(playerPos, this.position)), mag) + //manual friction to not lose rotational velocity + Matter.Body.setVelocity(this, { x: this.velocity.x * 0.95, y: this.velocity.y * 0.95 }); + //find targets + if (!(simulation.cycle % this.lookFrequency)) { + this.lockedOn = null; + if (!m.isCloak) { + let closeDist = this.range; + for (let i = 0, len = mob.length; i < len; ++i) { + const DIST = Vector.magnitude(Vector.sub(this.vertices[0], mob[i].position)); + if ( + DIST - mob[i].radius < closeDist && + !mob[i].isShielded && + (!mob[i].isBadTarget || mob[i].isMobBullet) && + Matter.Query.ray(map, this.vertices[0], mob[i].position).length === 0 && + Matter.Query.ray(body, this.vertices[0], mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + closeDist = DIST; + this.lockedOn = mob[i] + } + } + } + //randomize position relative to player + if (Math.random() < 0.1) { + if (isKeep) { + const range = 110 + 4 * b.totalBots() + this.offPlayer = { x: range * (Math.random() - 0.5), y: range * (Math.random() - 0.5) - 20, } + } else { + const range = 110 + 4 * b.totalBots() + 100 * Math.random() + this.offPlayer = Vector.mult(Vector.rotate({ x: 1, y: 0 }, 6.28 * Math.random()), range) + } + } + } + //hit target with laser + if (this.lockedOn && this.lockedOn.alive && m.energy > this.drainThreshold) { + m.energy -= this.drain + this.laser(); + // b.laser(this.vertices[0], this.lockedOn.position, m.dmgScale * this.laserDamage * tech.laserDamage, tech.laserReflections, false, 0.4) //tech.laserDamage = 0.16 + } + }, + laser() { + const push = 0.4 + const reflectivity = 1 - 1 / (tech.laserReflections * 3) + let damage = m.dmgScale * this.laserDamage * tech.laserDamage + //make the laser wiggle as it aims at the target + let best = { x: 1, y: 1, dist2: Infinity, who: null, v1: 1, v2: 1 }; + const perp2 = Vector.mult(Vector.rotate({ x: 1, y: 0 }, m.angle + Math.PI / 2), 0.6 * this.lockedOn.radius * Math.sin(simulation.cycle / this.lookFrequency)) + const path = [{ x: this.vertices[0].x, y: this.vertices[0].y }, Vector.add(this.lockedOn.position, perp2)]; + + const checkForCollisions = function () { + best = { x: 1, y: 1, dist2: Infinity, who: null, v1: 1, v2: 1 }; + best = vertexCollision(path[path.length - 2], path[path.length - 1], [mob, map, body]); + }; + const laserHitMob = function () { + if (best.who.alive) { + best.who.locatePlayer(); + if (best.who.damageReduction) { + if ( //iridescence + tech.laserCrit && !best.who.shield && + Vector.dot(Vector.normalise(Vector.sub(best.who.position, path[path.length - 1])), Vector.normalise(Vector.sub(path[path.length - 1], path[path.length - 2]))) > 0.999 - 0.5 / best.who.radius + ) { + damage *= 1 + tech.laserCrit + simulation.drawList.push({ //add dmg to draw queue + x: path[path.length - 1].x, + y: path[path.length - 1].y, + radius: Math.sqrt(2500 * damage * best.who.damageReduction) + 5, + color: `hsla(${60 + 283 * Math.random()},100%,70%,0.5)`, // random hue, but not red + time: 16 + }); + } else { + simulation.drawList.push({ //add dmg to draw queue + x: path[path.length - 1].x, + y: path[path.length - 1].y, + radius: Math.sqrt(2000 * damage * best.who.damageReduction) + 2, + color: tech.laserColorAlpha, + time: simulation.drawTime + }); + } + best.who.damage(damage); + } + if (tech.isLaserPush) { //push mobs away + const index = path.length - 1 + Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.97, y: best.who.velocity.y * 0.97 }); + const force = Vector.mult(Vector.normalise(Vector.sub(path[index], path[Math.max(0, index - 1)])), 0.003 * push * Math.min(6, best.who.mass)) + Matter.Body.applyForce(best.who, path[index], force) + } + } else if (tech.isLaserPush && best.who.classType === "body") { + const index = path.length - 1 + Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.97, y: best.who.velocity.y * 0.97 }); + const force = Vector.mult(Vector.normalise(Vector.sub(path[index], path[Math.max(0, index - 1)])), 0.003 * push * Math.min(6, best.who.mass)) + Matter.Body.applyForce(best.who, path[index], force) + } + }; + const reflection = function () { // https://math.stackexchange.com/questions/13261/how-to-get-a-reflection-vector + const n = Vector.perp(Vector.normalise(Vector.sub(best.v1, best.v2))); + const d = Vector.sub(path[path.length - 1], path[path.length - 2]); + const nn = Vector.mult(n, 2 * Vector.dot(d, n)); + const r = Vector.normalise(Vector.sub(d, nn)); + path[path.length] = Vector.add(Vector.mult(r, 3000), path[path.length - 1]); + }; + + checkForCollisions(); + let lastBestOdd + let lastBestEven = best.who //used in hack below + if (best.dist2 !== Infinity) { //if hitting something + path[path.length - 1] = { x: best.x, y: best.y }; + laserHitMob(); + for (let i = 0; i < tech.laserReflections; i++) { + reflection(); + checkForCollisions(); + if (best.dist2 !== Infinity) { //if hitting something + lastReflection = best + path[path.length - 1] = { x: best.x, y: best.y }; + damage *= reflectivity + laserHitMob(); + //I'm not clear on how this works, but it gets rid of a bug where the laser reflects inside a block, often vertically. + //I think it checks to see if the laser is reflecting off a different part of the same block, if it is "inside" a block + if (i % 2) { + if (lastBestOdd === best.who) break + } else { + lastBestOdd = best.who + if (lastBestEven === best.who) break + } + } else { + break + } + } + } + ctx.strokeStyle = tech.laserColor; + ctx.lineWidth = 2 + ctx.lineDashOffset = 900 * Math.random() + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + for (let i = 1, len = path.length; i < len; ++i) { + ctx.beginPath(); + ctx.moveTo(path[i - 1].x, path[i - 1].y); + ctx.lineTo(path[i].x, path[i].y); + ctx.stroke(); + ctx.globalAlpha *= reflectivity; //reflections are less intense + } + ctx.setLineDash([]); + ctx.globalAlpha = 1; + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + boomBot(position = { x: player.position.x + 50 * (Math.random() - 0.5), y: player.position.y + 50 * (Math.random() - 0.5) }, isKeep = true) { + const me = bullet.length; + const dir = m.angle; + const RADIUS = (7 + 2 * Math.random()) + bullet[me] = Bodies.polygon(position.x, position.y, 4, RADIUS, { + isUpgraded: tech.isBoomBotUpgrade, + botType: "boom", + angle: dir, + friction: 0, + frictionStatic: 0, + frictionAir: 0.05, + restitution: 1, + dmg: 0, + minDmgSpeed: 0, + lookFrequency: 43 + Math.floor(7 * Math.random()) - 15 * tech.isBoomBotUpgrade, + acceleration: (isKeep ? 0.005 : 0.001) * (1 + 0.5 * Math.random()), + attackAcceleration: 0.012 + 0.005 * tech.isBoomBotUpgrade, + range: 500 * (1 + 0.1 * Math.random()) + 250 * tech.isBoomBotUpgrade + !isKeep * 100, + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: b.totalBots() < 50 ? cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield : cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield //if over 50 bots, they no longer collide with each other + }, + lockedOn: null, + explode: 0, + beforeDmg() { + if (this.lockedOn) { + const explosionRadius = Math.min(136 + 230 * this.isUpgraded, Vector.magnitude(Vector.sub(this.position, m.pos)) - 30) + if (explosionRadius > 60) { + this.explode = explosionRadius + // + //push away from player, because normal explosion knock doesn't do much + // const sub = Vector.sub(this.lockedOn.position, m.pos) + // mag = Math.min(35, 20 / Math.sqrt(this.lockedOn.mass)) + // Matter.Body.setVelocity(this.lockedOn, Vector.mult(Vector.normalise(sub), mag)) + } + this.lockedOn = null //lose target so bot returns to player + } + }, + onEnd() { }, + do() { + const distanceToPlayer = Vector.magnitude(Vector.sub(this.position, player.position)) + if (distanceToPlayer > 100) { //if far away move towards player + if (this.explode) { + // if (tech.isImmuneExplosion && m.energy > 1.43) { + // b.explosion(this.position, this.explode); + // } else { + // } + b.explosion(this.position, Math.max(0, Math.min(this.explode, (distanceToPlayer - 70) / b.explosionRange()))); + this.explode = 0; + } + this.force = Vector.mult(Vector.normalise(Vector.sub(player.position, this.position)), this.mass * this.acceleration) + } else if (distanceToPlayer < 250) { //close to player + Matter.Body.setVelocity(this, Vector.add(Vector.mult(this.velocity, 0.90), Vector.mult(player.velocity, 0.17))); //add player's velocity + //find targets + if (!(simulation.cycle % this.lookFrequency) && !m.isCloak) { + this.lockedOn = null; + let closeDist = this.range; + for (let i = 0, len = mob.length; i < len; ++i) { + const DIST = Vector.magnitude(Vector.sub(this.position, mob[i].position)) - mob[i].radius; + if ( + DIST < closeDist && + !mob[i].isBadTarget && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + closeDist = DIST; + this.lockedOn = mob[i] + } + } + } + } + //punch target + if (this.lockedOn && this.lockedOn.alive && !m.isCloak) { + const DIST = Vector.magnitude(Vector.sub(this.vertices[0], this.lockedOn.position)); + if (DIST - this.lockedOn.radius < this.range && + Matter.Query.ray(map, this.position, this.lockedOn.position).length === 0) { + //move towards the target + this.force = Vector.add(this.force, Vector.mult(Vector.normalise(Vector.sub(this.lockedOn.position, this.position)), this.attackAcceleration * this.mass)) + } + } + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + plasmaBot(position = { x: player.position.x + 50 * (Math.random() - 0.5), y: player.position.y + 50 * (Math.random() - 0.5) }, isKeep = true) { + const me = bullet.length; + const dir = m.angle; + const RADIUS = 21 + bullet[me] = Bodies.polygon(position.x, position.y, 5, RADIUS, { + botType: "plasma", + angle: dir, + friction: 0, + frictionStatic: 0, + frictionAir: 0.05, + restitution: 1, + dmg: 0, // 0.14 //damage done in addition to the damage from momentum + minDmgSpeed: 2, + lookFrequency: 25, + cd: 0, + acceleration: 0.009, + endCycle: Infinity, + drainThreshold: tech.isEnergyHealth ? 0.5 : 0.05, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: b.totalBots() < 50 ? cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield : cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield //if over 50 bots, they no longer collide with each other + }, + lockedOn: null, + beforeDmg() { + this.lockedOn = null + }, + onEnd() { }, + do() { + const distanceToPlayer = Vector.magnitude(Vector.sub(this.position, m.pos)) + if (distanceToPlayer > 150) this.force = Vector.mult(Vector.normalise(Vector.sub(m.pos, this.position)), this.mass * this.acceleration) //if far away move towards player + Matter.Body.setVelocity(this, Vector.add(Vector.mult(this.velocity, 0.90), Vector.mult(player.velocity, 0.17))); //add player's velocity + + if (!(simulation.cycle % this.lookFrequency)) { //find closest + this.lockedOn = null; + if (!m.isCloak) { + let closeDist = tech.isPlasmaRange * 1000; + for (let i = 0, len = mob.length; i < len; ++i) { + const DIST = Vector.magnitude(Vector.sub(this.position, mob[i].position)) - mob[i].radius; + if ( + DIST < closeDist && (!mob[i].isBadTarget || mob[i].isMobBullet) && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 && + !mob[i].isInvulnerable + ) { + closeDist = DIST; + this.lockedOn = mob[i] + } + } + } + } + //fire plasma at target + if (this.lockedOn && this.lockedOn.alive && m.fieldCDcycle < m.cycle) { + const sub = Vector.sub(this.lockedOn.position, this.position) + const DIST = Vector.magnitude(sub); + const unit = Vector.normalise(sub) + if (DIST < tech.isPlasmaRange * 450 && m.energy > this.drainThreshold) { + m.energy -= 0.001 + //calculate laser collision + let best; + let range = tech.isPlasmaRange * (120 + 300 * Math.sqrt(Math.random())) + const path = [{ x: this.position.x, y: this.position.y }, { x: this.position.x + range * unit.x, y: this.position.y + range * unit.y }]; + //check for collisions + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + best = vertexCollision(path[0], path[1], [mob, map, body]); + if (best.dist2 != Infinity) { //if hitting something + path[path.length - 1] = { x: best.x, y: best.y }; + if (best.who.alive) { + const dmg = 1.4 * m.dmgScale; //********** SCALE DAMAGE HERE ********************* + best.who.damage(dmg); + best.who.locatePlayer(); + //push mobs away + // const force = Vector.mult(Vector.normalise(Vector.sub(m.pos, path[1])), -0.007 * Math.min(5, best.who.mass)) + // Matter.Body.applyForce(best.who, path[1], force) + //push mobs away + if (best.who.speed > 3) { + const force = Vector.mult(Vector.normalise(Vector.sub(m.pos, path[1])), -0.004 * Math.min(5, best.who.mass)) + Matter.Body.applyForce(best.who, path[1], force) + Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.5, y: best.who.velocity.y * 0.5 }); + } else { + const force = Vector.mult(Vector.normalise(Vector.sub(m.pos, path[1])), -0.01 * Math.min(5, best.who.mass)) + Matter.Body.applyForce(best.who, path[1], force) + Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.7, y: best.who.velocity.y * 0.7 }); + } + + if (best.who.speed > 2.5) Matter.Body.setVelocity(best.who, { x: best.who.velocity.x * 0.75, y: best.who.velocity.y * 0.75 }); + //draw mob damage circle + if (best.who.damageReduction) { + simulation.drawList.push({ + x: path[1].x, + y: path[1].y, + // radius: Math.sqrt(dmg) * 50 * mob[k].damageReduction, + // radius: 600 * dmg * best.who.damageReduction, + radius: Math.sqrt(2000 * dmg * best.who.damageReduction) + 2, + color: "rgba(255,0,255,0.2)", + time: simulation.drawTime * 4 + }); + } + } else if (!best.who.isStatic) { + //push blocks away + const force = Vector.mult(Vector.normalise(Vector.sub(m.pos, path[1])), -0.007 * Math.sqrt(Math.sqrt(best.who.mass))) + Matter.Body.applyForce(best.who, path[1], force) + } + } + //draw blowtorch laser beam + ctx.beginPath(); + ctx.moveTo(path[0].x, path[0].y); + ctx.lineTo(path[1].x, path[1].y); + ctx.strokeStyle = "rgba(255,0,255,0.1)" + ctx.lineWidth = 14 + ctx.stroke(); + ctx.strokeStyle = "#f0f"; + ctx.lineWidth = 2 + ctx.stroke(); + //draw electricity + let x = this.position.x + 20 * unit.x; + let y = this.position.y + 20 * unit.y; + ctx.beginPath(); + ctx.moveTo(x, y); + const step = Vector.magnitude(Vector.sub(path[0], path[1])) / 5 + for (let i = 0; i < 4; i++) { + x += step * (unit.x + 1.5 * (Math.random() - 0.5)) + y += step * (unit.y + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + ctx.lineWidth = 2 * Math.random(); + ctx.stroke(); + } + } + } + }) + Composite.add(engine.world, bullet[me]); //add bullet to world + }, + orbitBot(position = player.position, isKeep = true) { + const me = bullet.length; + bullet[me] = Bodies.polygon(position.x, position.y, 9, 12, { + isUpgraded: tech.isOrbitBotUpgrade, + botType: "orbit", + friction: 0, + frictionStatic: 0, + frictionAir: 1, + isStatic: true, + isSensor: true, + isKeep: isKeep, + restitution: 0, + dmg: 0, // 0.14 //damage done in addition to the damage from momentum + minDmgSpeed: 0, + endCycle: Infinity, + classType: "bullet", + collisionFilter: { + category: cat.bullet, + mask: 0 //cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield + }, + beforeDmg() { }, + onEnd() { + //reorder orbital bot positions around a circle + let totalOrbitalBots = 0 + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'orbit' && bullet[i] !== this && bullet[i].isKeep) totalOrbitalBots++ + } + let index = 0 + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'orbit' && bullet[i] !== this && bullet[i].isKeep) { + bullet[i].phase = (index / totalOrbitalBots) * 2 * Math.PI + index++ + } + } + }, + range: 160 + 170 * tech.isOrbitBotUpgrade + !isKeep * 100 * (0.5 - Math.random()), //range is set in bot upgrade too! + orbitalSpeed: 0, + phase: 2 * Math.PI * Math.random(), + do() { + if (!m.isCloak) { //if time dilation isn't active + const size = 40 + q = Matter.Query.region(mob, { + min: { + x: this.position.x - size, + y: this.position.y - size + }, + max: { + x: this.position.x + size, + y: this.position.y + size + } + }) + for (let i = 0; i < q.length; i++) { + if (!q[i].isShielded) { + mobs.statusStun(q[i], 210 + 90 * this.isUpgraded) + const dmg = 0.4 * m.dmgScale * (this.isUpgraded ? 4.5 : 1) * (tech.isCrit ? 4 : 1) + q[i].damage(dmg); + if (q[i].alive) q[i].foundPlayer(); + if (q[i].damageReduction) { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + // radius: 600 * dmg * q[i].damageReduction, + radius: Math.sqrt(2000 * dmg * q[i].damageReduction) + 2, + color: 'rgba(0,0,0,0.4)', + time: simulation.drawTime + }); + } + } + } + } + //orbit player + const time = simulation.cycle * this.orbitalSpeed + this.phase + const orbit = { x: Math.cos(time), y: Math.sin(time) } + Matter.Body.setPosition(this, Vector.add(m.pos, Vector.mult(orbit, this.range))) //bullets move with player + } + }) + // bullet[me].orbitalSpeed = Math.sqrt(0.7 / bullet[me].range) + bullet[me].orbitalSpeed = Math.sqrt(0.25 / bullet[me].range) //also set in bot upgrade too! + // bullet[me].phase = (index / tech.orbitBotCount) * 2 * Math.PI + Composite.add(engine.world, bullet[me]); //add bullet to world + + //reorder orbital bot positions around a circle + let totalOrbitalBots = 0 + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'orbit' && bullet[i].isKeep) totalOrbitalBots++ + } + let index = 0 + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'orbit' && bullet[i].isKeep) { + bullet[i].phase = (index / totalOrbitalBots) * 2 * Math.PI + index++ + } + } + }, + // ************************************************************************************************** + // ************************************************************************************************** + // ******************************** Guns ********************************************* + // ************************************************************************************************** + // ************************************************************************************************** + //0 nail gun + //1 shotgun + //2 super balls + //3 wave + //4 missiles + //5 grenades + //6 spores + //7 drones + //8 foam + //9 harpoon + //10 mine + //11 laser + guns: [ + { + name: "nail gun", // 0 + // description: `use compressed air to shoot a stream of nails
fire rate increases the longer you fire
60 nails per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `use compressed air to rapidly drive nails
fire rate increases the longer you fire
${this.ammoPack.toFixed(0)} nails per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 27, + defaultAmmoPack: 27, + recordedAmmo: 0, + have: false, + nextFireCycle: 0, //use to remember how longs its been since last fire, used to reset count + startingHoldCycle: 0, + chooseFireMethod() { //set in simulation.startGame + if (tech.nailRecoil) { + if (tech.isRivets) { + this.fire = this.fireRecoilRivets + } else { + this.fire = this.fireRecoilNails + } + } else if (tech.isRivets) { + this.fire = this.fireRivets + } else if (tech.isNeedles) { + this.fire = this.fireNeedles + } else if (tech.nailInstantFireRate) { + this.fire = this.fireInstantFireRate + // } else if (tech.nailFireRate) { + // this.fire = this.fireNailFireRate + } else { + this.fire = this.fireNormal + } + }, + do() { }, + fire() { }, + fireRecoilNails() { + if (this.nextFireCycle + 1 < m.cycle) this.startingHoldCycle = m.cycle //reset if not constantly firing + const CD = Math.max(11 - 0.06 * (m.cycle - this.startingHoldCycle), 0.99) //CD scales with cycles fire is held down + this.nextFireCycle = m.cycle + CD * b.fireCDscale //predict next fire cycle if the fire button is held down + + m.fireCDcycle = m.cycle + Math.floor(CD * b.fireCDscale); // cool down + this.baseFire(m.angle + (Math.random() - 0.5) * (m.crouch ? 0.04 : 0.13) / CD, 45 + 6 * Math.random()) + //very complex recoil system + if (m.onGround) { + if (m.crouch) { + const KNOCK = 0.006 + player.force.x -= KNOCK * Math.cos(m.angle) + player.force.y -= KNOCK * Math.sin(m.angle) //reduce knock back in vertical direction to stop super jumps + Matter.Body.setVelocity(player, { + x: player.velocity.x * 0.5, + y: player.velocity.y * 0.5 + }); + } else { + const KNOCK = 0.03 + player.force.x -= KNOCK * Math.cos(m.angle) + player.force.y -= KNOCK * Math.sin(m.angle) //reduce knock back in vertical direction to stop super jumps + Matter.Body.setVelocity(player, { + x: player.velocity.x * 0.8, + y: player.velocity.y * 0.8 + }); + } + } else { + player.force.x -= 0.06 * Math.cos(m.angle) * Math.min(1, 3 / (0.1 + Math.abs(player.velocity.x))) + player.force.y -= 0.006 * Math.sin(m.angle) //reduce knock back in vertical direction to stop super jumps + } + }, + fireNormal() { + if (this.nextFireCycle + 1 < m.cycle) this.startingHoldCycle = m.cycle //reset if not constantly firing + const CD = Math.max(11 - 0.06 * (m.cycle - this.startingHoldCycle), 1) //CD scales with cycles fire is held down + this.nextFireCycle = m.cycle + CD * b.fireCDscale //predict next fire cycle if the fire button is held down + + m.fireCDcycle = m.cycle + Math.floor(CD * b.fireCDscale); // cool down + this.baseFire(m.angle + (Math.random() - 0.5) * (m.crouch ? 0.05 : 0.3) / CD) + }, + fireNeedles() { + if (m.crouch) { + m.fireCDcycle = m.cycle + 30 * b.fireCDscale; // cool down + b.needle() + + function cycle() { + if (simulation.paused || m.isTimeDilated) { + requestAnimationFrame(cycle) + } else { + count++ + if (count % 2) b.needle() + if (count < 7 && m.alive) requestAnimationFrame(cycle); + } + } + let count = -1 + requestAnimationFrame(cycle); + } else { + m.fireCDcycle = m.cycle + 22 * b.fireCDscale; // cool down + b.needle() + + function cycle() { + if (simulation.paused || m.isTimeDilated) { + requestAnimationFrame(cycle) + } else { + count++ + if (count % 2) b.needle() + if (count < 3 && m.alive) requestAnimationFrame(cycle); + } + } + let count = -1 + requestAnimationFrame(cycle); + } + }, + fireRivets() { + m.fireCDcycle = m.cycle + Math.floor((m.crouch ? 22 : 14) * b.fireCDscale); // cool down + const me = bullet.length; + const size = tech.bulletSize * 8 + bullet[me] = Bodies.rectangle(m.pos.x + 35 * Math.cos(m.angle), m.pos.y + 35 * Math.sin(m.angle), 5 * size, size, b.fireAttributes(m.angle)); + bullet[me].dmg = tech.isNailRadiation ? 0 : 2.75 + Matter.Body.setDensity(bullet[me], 0.002); + Composite.add(engine.world, bullet[me]); //add bullet to world + const SPEED = m.crouch ? 60 : 44 + Matter.Body.setVelocity(bullet[me], { + x: SPEED * Math.cos(m.angle), + y: SPEED * Math.sin(m.angle) + }); + bullet[me].endCycle = simulation.cycle + 180 + + bullet[me].beforeDmg = function (who) { //beforeDmg is rewritten with ice crystal tech + if (tech.isIncendiary) { + this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + b.explosion(this.position, 100 + (Math.random() - 0.5) * 20); //makes bullet do explosive damage at end + } + if (tech.isNailCrit) { + if (!who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.97 - 1 / who.radius) { + b.explosion(this.position, 300 + 40 * Math.random()); //makes bullet do explosive damage at end + } + } else if (tech.isCritKill) b.crit(who, this) + if (tech.isNailRadiation) mobs.statusDoT(who, 7 * (tech.isFastRadiation ? 0.7 : 0.24), tech.isSlowRadiation ? 360 : (tech.isFastRadiation ? 60 : 180)) // one tick every 30 cycles + if (this.speed > 4 && tech.fragments) { + b.targetedNail(this.position, 1.25 * tech.fragments * tech.bulletSize) + this.endCycle = 0 //triggers despawn + } + }; + + bullet[me].minDmgSpeed = 10 + bullet[me].frictionAir = 0.006; + bullet[me].rotateToVelocity = function () { //rotates bullet to face current velocity? + if (this.speed > 7) { + const facing = { + x: Math.cos(this.angle), + y: Math.sin(this.angle) + } + const mag = 0.002 * this.mass + if (Vector.cross(Vector.normalise(this.velocity), facing) < 0) { + this.torque += mag + } else { + this.torque -= mag + } + } + }; + if (tech.isIncendiary) { + bullet[me].do = function () { + this.force.y += this.mass * 0.0008 + this.rotateToVelocity() + //collide with map + if (Matter.Query.collides(this, map).length) { //penetrate walls + this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + b.explosion(this.position, 300 + 40 * Math.random()); //makes bullet do explosive damage at end + } + }; + } else { + bullet[me].do = function () { + this.force.y += this.mass * 0.0008 + this.rotateToVelocity() + }; + } + b.muzzleFlash(); + //very complex recoil system + if (m.onGround) { + if (m.crouch) { + const KNOCK = 0.01 + player.force.x -= KNOCK * Math.cos(m.angle) + player.force.y -= KNOCK * Math.sin(m.angle) //reduce knock back in vertical direction to stop super jumps + } else { + const KNOCK = 0.02 + player.force.x -= KNOCK * Math.cos(m.angle) + player.force.y -= KNOCK * Math.sin(m.angle) //reduce knock back in vertical direction to stop super jumps + } + } else { + const KNOCK = 0.01 + player.force.x -= KNOCK * Math.cos(m.angle) + player.force.y -= KNOCK * Math.sin(m.angle) * 0.5 //reduce knock back in vertical direction to stop super jumps + } + }, + fireRecoilRivets() { + // m.fireCDcycle = m.cycle + Math.floor((m.crouch ? 25 : 17) * b.fireCDscale); // cool down + if (this.nextFireCycle + 1 < m.cycle) this.startingHoldCycle = m.cycle //reset if not constantly firing + const CD = Math.max(25 - 0.14 * (m.cycle - this.startingHoldCycle), 5) //CD scales with cycles fire is held down + this.nextFireCycle = m.cycle + CD * b.fireCDscale //predict next fire cycle if the fire button is held down + m.fireCDcycle = m.cycle + Math.floor(CD * b.fireCDscale); // cool down + + const me = bullet.length; + const size = tech.bulletSize * 8 + bullet[me] = Bodies.rectangle(m.pos.x + 35 * Math.cos(m.angle), m.pos.y + 35 * Math.sin(m.angle), 5 * size, size, b.fireAttributes(m.angle)); + bullet[me].dmg = tech.isNailRadiation ? 0 : 2.75 + Matter.Body.setDensity(bullet[me], 0.002); + Composite.add(engine.world, bullet[me]); //add bullet to world + const SPEED = m.crouch ? 62 : 52 + Matter.Body.setVelocity(bullet[me], { + x: SPEED * Math.cos(m.angle), + y: SPEED * Math.sin(m.angle) + }); + bullet[me].endCycle = simulation.cycle + 180 + bullet[me].beforeDmg = function (who) { //beforeDmg is rewritten with ice crystal tech + if (tech.isIncendiary) { + this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + b.explosion(this.position, 100 + (Math.random() - 0.5) * 20); //makes bullet do explosive damage at end + } + if (tech.isNailCrit) { + if (!who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.97 - 1 / who.radius) { + b.explosion(this.position, 300 + 40 * Math.random()); //makes bullet do explosive damage at end + } + } else if (tech.isCritKill) b.crit(who, this) + if (tech.isNailRadiation) mobs.statusDoT(who, 7 * (tech.isFastRadiation ? 0.7 : 0.24), tech.isSlowRadiation ? 360 : (tech.isFastRadiation ? 60 : 180)) // one tick every 30 cycles + if (this.speed > 4 && tech.fragments) { + b.targetedNail(this.position, 1.25 * tech.fragments * tech.bulletSize) + this.endCycle = 0 //triggers despawn + } + }; + + bullet[me].minDmgSpeed = 10 + bullet[me].frictionAir = 0.006; + bullet[me].rotateToVelocity = function () { //rotates bullet to face current velocity? + if (this.speed > 7) { + const facing = { + x: Math.cos(this.angle), + y: Math.sin(this.angle) + } + const mag = 0.002 * this.mass + if (Vector.cross(Vector.normalise(this.velocity), facing) < 0) { + this.torque += mag + } else { + this.torque -= mag + } + } + }; + if (tech.isIncendiary) { + bullet[me].do = function () { + this.force.y += this.mass * 0.0008 + this.rotateToVelocity() + //collide with map + if (Matter.Query.collides(this, map).length) { //penetrate walls + this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + b.explosion(this.position, 100 + (Math.random() - 0.5) * 20); //makes bullet do explosive damage at end + } + }; + } else { + bullet[me].do = function () { + this.force.y += this.mass * 0.0008 + this.rotateToVelocity() + }; + } + + b.muzzleFlash(); + //very complex recoil system + if (m.onGround) { + if (m.crouch) { + const KNOCK = 0.03 + player.force.x -= KNOCK * Math.cos(m.angle) + player.force.y -= KNOCK * Math.sin(m.angle) //reduce knock back in vertical direction to stop super jumps + Matter.Body.setVelocity(player, { + x: player.velocity.x * 0.4, + y: player.velocity.y * 0.4 + }); + } else { + const KNOCK = 0.1 + player.force.x -= KNOCK * Math.cos(m.angle) + player.force.y -= KNOCK * Math.sin(m.angle) //reduce knock back in vertical direction to stop super jumps + Matter.Body.setVelocity(player, { + x: player.velocity.x * 0.7, + y: player.velocity.y * 0.7 + }); + } + } else { + player.force.x -= 0.2 * Math.cos(m.angle) * Math.min(1, 3 / (0.1 + Math.abs(player.velocity.x))) + // player.force.x -= 0.06 * Math.cos(m.angle) * Math.min(1, 3 / (0.1 + Math.abs(player.velocity.x))) + + player.force.y -= 0.02 * Math.sin(m.angle) //reduce knock back in vertical direction to stop super jumps + } + }, + fireInstantFireRate() { + m.fireCDcycle = m.cycle + Math.floor(1 * b.fireCDscale); // cool down + this.baseFire(m.angle + (Math.random() - 0.5) * (Math.random() - 0.5) * (m.crouch ? 1.15 : 2) / 2) + }, + baseFire(angle, speed = 30 + 6 * Math.random()) { + b.nail({ + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }, { + x: 0.8 * player.velocity.x + speed * Math.cos(angle), + y: 0.5 * player.velocity.y + speed * Math.sin(angle) + }) //position, velocity, damage + if (tech.isIceCrystals) { + bullet[bullet.length - 1].beforeDmg = function (who) { + mobs.statusSlow(who, 60) + if (tech.isNailRadiation) mobs.statusDoT(who, 1 * (tech.isFastRadiation ? 1.3 : 0.44), tech.isSlowRadiation ? 360 : (tech.isFastRadiation ? 60 : 180)) // one tick every 30 cycles + if (tech.isNailCrit) { + if (!who.shield && Vector.dot(Vector.normalise(Vector.sub(who.position, this.position)), Vector.normalise(this.velocity)) > 0.97 - 1 / who.radius) { + b.explosion(this.position, 150 + 30 * Math.random()); //makes bullet do explosive damage at end + } + } + this.ricochet(who) + }; + if (m.energy < 0.01) { + m.fireCDcycle = m.cycle + 60; // cool down + } else { + m.energy -= 0.01 + } + } + }, + }, + { + name: "shotgun", //1 + // description: `fire a wide burst of short range bullets
with a low fire rate
3-4 nails per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `fire a wide burst of short range pellets
has a slow fire rate
${this.ammoPack.toFixed(1)} shots per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 1.6, + defaultAmmoPack: 1.6, + have: false, + do() { + //fade cross hairs + + + + // draw loop around player head + // const left = m.fireCDcycle !== Infinity ? 0.05 * Math.max(m.fireCDcycle - m.cycle, 0) : 0 + // if (left > 0) { + // ctx.beginPath(); + // // ctx.arc(simulation.mouseInGame.x, simulation.mouseInGame.y, 30, 0, left); + // ctx.arc(m.pos.x, m.pos.y, 28, m.angle - left, m.angle); + // // ctx.fillStyle = "rgba(0,0,0,0.3)" //"#333" + // // ctx.fill(); + // ctx.strokeStyle = "#333"; + // ctx.lineWidth = 2; + // ctx.stroke(); + // } + + + //draw hip circle + // ctx.beginPath(); + // ctx.arc(m.pos.x + m.hip.x, m.pos.y + m.hip.y, 11, 0, 2 * Math.PI); + // ctx.fillStyle = "rgba(0,0,0,0.3)" //"#333" + // ctx.fill(); + }, + fire() { + let knock, spread + const coolDown = function () { + if (m.crouch) { + spread = 0.65 + m.fireCDcycle = m.cycle + Math.floor((73 + 36 * tech.shotgunExtraShots) * b.fireCDscale) // cool down + if (tech.isShotgunImmune && m.immuneCycle < m.cycle + Math.floor(60 * b.fireCDscale)) m.immuneCycle = m.cycle + Math.floor(60 * b.fireCDscale); //player is immune to damage for 30 cycles + knock = 0.01 + } else { + m.fireCDcycle = m.cycle + Math.floor((56 + 28 * tech.shotgunExtraShots) * b.fireCDscale) // cool down + if (tech.isShotgunImmune && m.immuneCycle < m.cycle + Math.floor(47 * b.fireCDscale)) m.immuneCycle = m.cycle + Math.floor(47 * b.fireCDscale); //player is immune to damage for 30 cycles + spread = 1.3 + knock = 0.1 + } + + if (tech.isShotgunReversed) { + player.force.x += 1.5 * knock * Math.cos(m.angle) + player.force.y += 1.5 * knock * Math.sin(m.angle) - 3 * player.mass * simulation.g + } else if (tech.isShotgunRecoil) { + m.fireCDcycle -= 0.66 * (56 * b.fireCDscale) + player.force.x -= 2 * knock * Math.cos(m.angle) + player.force.y -= 2 * knock * Math.sin(m.angle) + } else { + player.force.x -= knock * Math.cos(m.angle) + player.force.y -= knock * Math.sin(m.angle) * 0.5 //reduce knock back in vertical direction to stop super jumps + } + } + const spray = (num) => { + const side = 22 + for (let i = 0; i < num; i++) { + const me = bullet.length; + const dir = m.angle + (Math.random() - 0.5) * spread + bullet[me] = Bodies.rectangle(m.pos.x, m.pos.y, side, side, b.fireAttributes(dir)); + Composite.add(engine.world, bullet[me]); //add bullet to world + const SPEED = 52 + Math.random() * 8 + Matter.Body.setVelocity(bullet[me], { + x: SPEED * Math.cos(dir), + y: SPEED * Math.sin(dir) + }); + bullet[me].endCycle = simulation.cycle + 40 * tech.bulletsLastLonger + bullet[me].minDmgSpeed = 15 + if (tech.isShotgunReversed) Matter.Body.setDensity(bullet[me], 0.0015) + // bullet[me].restitution = 0.4 + bullet[me].frictionAir = 0.034; + bullet[me].do = function () { + const scale = 1 - 0.034 / tech.bulletsLastLonger + Matter.Body.scale(this, scale, scale); + }; + } + } + const chooseBulletType = function () { + if (tech.isRivets) { + const me = bullet.length; + // const dir = m.angle + 0.02 * (Math.random() - 0.5) + bullet[me] = Bodies.rectangle(m.pos.x + 35 * Math.cos(m.angle), m.pos.y + 35 * Math.sin(m.angle), 56 * tech.bulletSize, 25 * tech.bulletSize, b.fireAttributes(m.angle)); + + Matter.Body.setDensity(bullet[me], 0.005 * (tech.isShotgunReversed ? 1.5 : 1)); + Composite.add(engine.world, bullet[me]); //add bullet to world + const SPEED = (m.crouch ? 50 : 43) + Matter.Body.setVelocity(bullet[me], { + x: SPEED * Math.cos(m.angle), + y: SPEED * Math.sin(m.angle) + }); + if (tech.isIncendiary) { + bullet[me].endCycle = simulation.cycle + 60 + bullet[me].onEnd = function () { + b.explosion(this.position, 400 + (Math.random() - 0.5) * 60); //makes bullet do explosive damage at end + } + bullet[me].beforeDmg = function () { + this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + }; + } else { + bullet[me].endCycle = simulation.cycle + 180 + } + bullet[me].minDmgSpeed = 7 + // bullet[me].restitution = 0.4 + bullet[me].frictionAir = 0.004; + bullet[me].turnMag = 0.04 * Math.pow(tech.bulletSize, 3.75) + bullet[me].do = function () { + this.force.y += this.mass * 0.002 + if (this.speed > 6) { //rotates bullet to face current velocity? + const facing = { + x: Math.cos(this.angle), + y: Math.sin(this.angle) + } + if (Vector.cross(Vector.normalise(this.velocity), facing) < 0) { + this.torque += this.turnMag + } else { + this.torque -= this.turnMag + } + } + if (tech.isIncendiary && Matter.Query.collides(this, map).length) { + this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + } + }; + bullet[me].beforeDmg = function (who) { + if (this.speed > 4) { + if (tech.fragments) { + b.targetedNail(this.position, 6 * tech.fragments * tech.bulletSize) + this.endCycle = 0 //triggers despawn + } + if (tech.isIncendiary) this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + if (tech.isCritKill) b.crit(who, this) + } + } + spray(12); //fires normal shotgun bullets + } else if (tech.isIncendiary) { + spread *= 0.15 + const END = Math.floor(m.crouch ? 8 : 5); + const totalBullets = 9 + const angleStep = (m.crouch ? 0.3 : 0.8) / totalBullets + let dir = m.angle - angleStep * totalBullets / 2; + for (let i = 0; i < totalBullets; i++) { //5 -> 7 + dir += angleStep + const me = bullet.length; + bullet[me] = Bodies.rectangle(m.pos.x + 50 * Math.cos(m.angle), m.pos.y + 50 * Math.sin(m.angle), 17, 4, b.fireAttributes(dir)); + const end = END + Math.random() * 4 + bullet[me].endCycle = 2 * end * tech.bulletsLastLonger + simulation.cycle + const speed = 25 * end / END + const dirOff = dir + (Math.random() - 0.5) * spread + Matter.Body.setVelocity(bullet[me], { + x: speed * Math.cos(dirOff), + y: speed * Math.sin(dirOff) + }); + bullet[me].onEnd = function () { + b.explosion(this.position, 180 * (tech.isShotgunReversed ? 1.4 : 1) + (Math.random() - 0.5) * 30); //makes bullet do explosive damage at end + } + bullet[me].beforeDmg = function () { + this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + }; + bullet[me].do = function () { + if (Matter.Query.collides(this, map).length) this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion + } + Composite.add(engine.world, bullet[me]); //add bullet to world + } + } else if (tech.isNailShot) { + spread *= 0.65 + const dmg = 2 * (tech.isShotgunReversed ? 1.5 : 1) + if (m.crouch) { + for (let i = 0; i < 17; i++) { + speed = 38 + 15 * Math.random() + const dir = m.angle + (Math.random() - 0.5) * spread + const pos = { + x: m.pos.x + 35 * Math.cos(m.angle) + 15 * (Math.random() - 0.5), + y: m.pos.y + 35 * Math.sin(m.angle) + 15 * (Math.random() - 0.5) + } + b.nail(pos, { + x: speed * Math.cos(dir), + y: speed * Math.sin(dir) + }, dmg) + } + } else { + for (let i = 0; i < 17; i++) { + speed = 38 + 15 * Math.random() + const dir = m.angle + (Math.random() - 0.5) * spread + const pos = { + x: m.pos.x + 35 * Math.cos(m.angle) + 15 * (Math.random() - 0.5), + y: m.pos.y + 35 * Math.sin(m.angle) + 15 * (Math.random() - 0.5) + } + b.nail(pos, { + x: speed * Math.cos(dir), + y: speed * Math.sin(dir) + }, dmg) + } + } + } else if (tech.isSporeFlea) { + const where = { + x: m.pos.x + 35 * Math.cos(m.angle), + y: m.pos.y + 35 * Math.sin(m.angle) + } + const number = 2 * (tech.isShotgunReversed ? 1.5 : 1) + for (let i = 0; i < number; i++) { + const angle = m.angle + 0.2 * (Math.random() - 0.5) + const speed = (m.crouch ? 35 * (1 + 0.05 * Math.random()) : 30 * (1 + 0.15 * Math.random())) + b.flea(where, { + x: speed * Math.cos(angle), + y: speed * Math.sin(angle) + }) + bullet[bullet.length - 1].setDamage() + } + spray(10); //fires normal shotgun bullets + } else if (tech.isSporeWorm) { + const where = { + x: m.pos.x + 35 * Math.cos(m.angle), + y: m.pos.y + 35 * Math.sin(m.angle) + } + const spread = (m.crouch ? 0.02 : 0.07) + const number = 3 * (tech.isShotgunReversed ? 1.5 : 1) + let angle = m.angle - (number - 1) * spread * 0.5 + for (let i = 0; i < number; i++) { + b.worm(where) + const SPEED = (30 + 10 * m.crouch) * (1 + 0.2 * Math.random()) + Matter.Body.setVelocity(bullet[bullet.length - 1], { + x: player.velocity.x * 0.5 + SPEED * Math.cos(angle), + y: player.velocity.y * 0.5 + SPEED * Math.sin(angle) + }); + angle += spread + } + spray(7); //fires normal shotgun bullets + } else if (tech.isIceShot) { + const spread = (m.crouch ? 0.7 : 1.2) + for (let i = 0, len = 10 * (tech.isShotgunReversed ? 1.5 : 1); i < len; i++) { + b.iceIX(23 + 10 * Math.random(), m.angle + spread * (Math.random() - 0.5)) + } + spray(10); //fires normal shotgun bullets + } else if (tech.isFoamShot) { + const spread = (m.crouch ? 0.15 : 0.4) + const where = { + x: m.pos.x + 25 * Math.cos(m.angle), + y: m.pos.y + 25 * Math.sin(m.angle) + } + const number = 16 * (tech.isShotgunReversed ? 1.5 : 1) + for (let i = 0; i < number; i++) { + const SPEED = 13 + 4 * Math.random(); + const angle = m.angle + spread * (Math.random() - 0.5) + b.foam(where, { + x: 0.6 * player.velocity.x + SPEED * Math.cos(angle), + y: 0.5 * player.velocity.y + SPEED * Math.sin(angle) + }, 8 + 7 * Math.random()) + } + } else if (tech.isNeedles) { + const number = 9 * (tech.isShotgunReversed ? 1.5 : 1) + const spread = (m.crouch ? 0.03 : 0.05) + let angle = m.angle - (number - 1) * spread * 0.5 + for (let i = 0; i < number; i++) { + b.needle(angle) + angle += spread + } + } else { + spray(16); //fires normal shotgun bullets + } + } + + + coolDown(); + b.muzzleFlash(35); + chooseBulletType(); + + if (tech.shotgunExtraShots) { + const delay = 7 + let count = tech.shotgunExtraShots * delay + + function cycle() { + count-- + if (!(count % delay)) { + coolDown(); + b.muzzleFlash(35); + chooseBulletType(); + } + if (count > 0) { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + } + } + }, { + name: "super balls", //2 + descriptionFunction() { + return `fire 3 balls that retain
momentum and kinetic energy after collisions
${this.ammoPack.toFixed(0)} balls per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 4.05, + defaultAmmoPack: 4.05, + have: false, + // num: 5, + do() { }, + foamBall() { }, + fireOne() { + m.fireCDcycle = m.cycle + Math.floor((m.crouch ? 27 : 19) * b.fireCDscale); // cool down + const speed = m.crouch ? 43 : 36 + b.superBall({ + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }, { + x: speed * Math.cos(m.angle), + y: speed * Math.sin(m.angle) + }, 21 * tech.bulletSize) + }, + fireMulti() { + m.fireCDcycle = m.cycle + Math.floor((m.crouch ? 23 : 15) * b.fireCDscale); // cool down + const SPREAD = m.crouch ? 0.08 : 0.13 + const num = 3 + Math.floor(tech.extraSuperBalls * Math.random()) + const speed = m.crouch ? 43 : 36 + if (tech.isBulletTeleport) { + for (let i = 0; i < num; i++) { + b.superBall({ + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }, { + x: speed * Math.cos(m.angle), + y: speed * Math.sin(m.angle) + }, 11 * tech.bulletSize) + } + } else { + let dir = m.angle - SPREAD * (num - 1) / 2; + for (let i = 0; i < num; i++) { + b.superBall({ + x: m.pos.x + 30 * Math.cos(dir), + y: m.pos.y + 30 * Math.sin(dir) + }, { + x: speed * Math.cos(dir), + y: speed * Math.sin(dir) + }, 11 * tech.bulletSize) + dir += SPREAD; + } + } + }, + fireQueue() { + m.fireCDcycle = m.cycle + Math.floor((m.crouch ? 23 : 15) * b.fireCDscale); // cool down + const num = 2 + 3 + Math.floor(tech.extraSuperBalls * Math.random()) //2 extra + const speed = m.crouch ? 43 : 36 + + const delay = Math.floor((m.crouch ? 18 : 12) * b.fireCDscale) + m.fireCDcycle = m.cycle + delay; // cool down + function cycle() { + count++ + b.superBall({ + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + }, { + x: speed * Math.cos(m.angle), + y: speed * Math.sin(m.angle) + }, 11 * tech.bulletSize) + if (count < num && m.alive) requestAnimationFrame(cycle); + m.fireCDcycle = m.cycle + delay; // cool down + } + let count = 0 + requestAnimationFrame(cycle); + }, + chooseFireMethod() { //set in simulation.startGame + if (tech.oneSuperBall) { + this.fire = this.fireOne + } else if (tech.superBallDelay) { + this.fire = this.fireQueue + } else { + this.fire = this.fireMulti + } + }, + fire() { } + }, + { + name: "wave", //3 + // description: `emit wave packets that propagate through solids
waves slow mobs
115 packets per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `emit wave packets that propagate through solids
waves slow mobs
${this.ammoPack.toFixed(0)} wave packets per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 60, + defaultAmmoPack: 60, + have: false, + wavePacketCycle: 0, + delay: 40, + phononWaveCD: 0, + waves: [], //used in longitudinal mode + chooseFireMethod() { //set in simulation.startGame + this.waves = []; + if (tech.isLongitudinal) { + if (tech.is360Longitudinal) { + this.fire = this.fire360Longitudinal + this.do = this.do360Longitudinal + } else { + this.fire = this.fireLongitudinal + this.do = this.doLongitudinal + } + } else { + this.fire = this.fireTransverse + this.do = this.doTransverse + } + }, + do() { }, + do360Longitudinal() { + if (!m.isTimeDilated) { + ctx.strokeStyle = "rgba(0,0,0,0.6)" //"000"; + ctx.lineWidth = 2 * tech.wavePacketDamage + ctx.beginPath(); + const end = 700 * Math.sqrt(tech.bulletsLastLonger) + const damage = 2.3 * m.dmgScale * tech.wavePacketDamage * tech.waveBeamDamage * (tech.isBulletTeleport ? 1.43 : 1) * (tech.isInfiniteWaveAmmo ? 0.75 : 1) //damage is lower for large radius mobs, since they feel the waves longer + + for (let i = this.waves.length - 1; i > -1; i--) { + //draw wave + ctx.moveTo(this.waves[i].position.x + this.waves[i].radius, this.waves[i].position.y) + ctx.arc(this.waves[i].position.x, this.waves[i].position.y, this.waves[i].radius, 0, 2 * Math.PI); + // collisions + // if (tech.isBulletTeleport && Math.random() < 0.04) { + // const scale = 400 * Math.random() + // this.waves[i].position = Vector.add(this.waves[i].position, { x: scale * (Math.random() - 0.5), y: scale * (Math.random() - 0.5) }) + // } + for (let j = 0, len = mob.length; j < len; j++) { + if (!mob[j].isShielded) { + const dist = Vector.magnitude(Vector.sub(this.waves[i].position, mob[j].position)) + const r = mob[j].radius + 30 + if (dist + r > this.waves[i].radius && dist - r < this.waves[i].radius) { + //make them shake around + if (!mob[j].isBadTarget) { + mob[j].force.x += 0.01 * (Math.random() - 0.5) * mob[j].mass + mob[j].force.y += 0.01 * (Math.random() - 0.5) * mob[j].mass + } + // if (!mob[j].isShielded) { + Matter.Body.setVelocity(mob[j], { //friction + x: mob[j].velocity.x * 0.95, + y: mob[j].velocity.y * 0.95 + }); + //draw vibes + let vertices = mob[j].vertices; + const vibe = 50 + mob[j].radius * 0.15 + ctx.moveTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + for (let k = 1; k < vertices.length; k++) { + ctx.lineTo(vertices[k].x + vibe * (Math.random() - 0.5), vertices[k].y + vibe * (Math.random() - 0.5)); + } + ctx.lineTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + //damage + mob[j].locatePlayer(); + mob[j].damage(damage / Math.sqrt(mob[j].radius)); + // } + if (tech.isPhononWave && this.phononWaveCD < m.cycle) { + this.phononWaveCD = m.cycle + 8 * (1 + this.waves[i].resonanceCount) + this.waves.push({ + position: mob[j].position, + radius: 25, + resonanceCount: this.waves[i].resonanceCount + 1, + }) + } + } + } + } + // for (let j = 0, len = body.length; j < len; j++) { + for (let j = 0, len = Math.min(30, body.length); j < len; j++) { + const dist = Vector.magnitude(Vector.sub(this.waves[i].position, body[j].position)) + const r = 20 + if (dist + r > this.waves[i].radius && dist - r < this.waves[i].radius) { + const who = body[j] + //make them shake around + who.force.x += 0.01 * (Math.random() - 0.5) * who.mass + who.force.y += (0.01 * (Math.random() - 0.5) - simulation.g * 0.25) * who.mass //remove force of gravity + //draw vibes + let vertices = who.vertices; + const vibe = 25 + ctx.moveTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + for (let k = 1; k < vertices.length; k++) { + ctx.lineTo(vertices[k].x + vibe * (Math.random() - 0.5), vertices[k].y + vibe * (Math.random() - 0.5)); + } + ctx.lineTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + + if (tech.isPhononBlock && !who.isNotHoldable && who.speed < 5 && who.angularSpeed < 0.1) { + if (Math.random() < 0.5) b.targetedBlock(who, 50 - Math.min(25, who.mass * 3)) // targetedBlock(who, speed = 50 - Math.min(20, who.mass * 2), range = 1600) { + // Matter.Body.setAngularVelocity(who, (0.25 + 0.1 * Math.random()) * (Math.random() < 0.5 ? -1 : 1)); + who.torque += who.inertia * 0.001 * (Math.random() - 0.5) + } + } + } + this.waves[i].radius += 0.9 * tech.waveBeamSpeed //expand / move + // if (this.waves[i].radius > end) this.waves.splice(i, 1) //end + if (this.waves[i].radius > end - 30 * this.waves[i].resonanceCount) { //* Math.pow(0.9, this.waves[i].resonanceCount) + this.waves.splice(i, 1) //end + } + } + ctx.stroke(); + } + }, + fire360Longitudinal() { + m.fireCDcycle = m.cycle + Math.floor((m.crouch ? 4 : 8) * b.fireCDscale); // cool down + this.waves.push({ + position: { x: m.pos.x, y: m.pos.y, }, + radius: 25, + resonanceCount: 0 //used with tech.isPhononWave + }) + }, + doLongitudinal() { + if (!m.isTimeDilated) { + ctx.strokeStyle = "rgba(0,0,0,0.6)" //"000"; + ctx.lineWidth = 2 * tech.wavePacketDamage + ctx.beginPath(); + const end = 1100 * tech.bulletsLastLonger + const damage = 2.3 * m.dmgScale * tech.wavePacketDamage * tech.waveBeamDamage * (tech.isBulletTeleport ? 1.4 : 1) * (tech.isInfiniteWaveAmmo ? 0.75 : 1) //damage is lower for large radius mobs, since they feel the waves longer + for (let i = this.waves.length - 1; i > -1; i--) { + const v1 = Vector.add(this.waves[i].position, Vector.mult(this.waves[i].unit1, this.waves[i].radius)) + const v2 = Vector.add(this.waves[i].position, Vector.mult(this.waves[i].unit2, this.waves[i].radius)) + //draw wave + ctx.moveTo(v1.x, v1.y) + ctx.arc(this.waves[i].position.x, this.waves[i].position.y, this.waves[i].radius, this.waves[i].angle, this.waves[i].angle + this.waves[i].arc); + //using small angle linear approximation of circle arc, this will not work if the arc gets large // https://stackoverflow.com/questions/13652518/efficiently-find-points-inside-a-circle-sector + let hits = Matter.Query.ray(mob, v1, v2, 50) //Matter.Query.ray(bodies, startPoint, endPoint, [rayWidth]) + for (let j = 0; j < hits.length; j++) { + const who = hits[j].body + if (!who.isShielded) { + who.force.x += 0.01 * (Math.random() - 0.5) * who.mass + who.force.y += 0.01 * (Math.random() - 0.5) * who.mass + Matter.Body.setVelocity(who, { x: who.velocity.x * 0.95, y: who.velocity.y * 0.95 }); + let vertices = who.vertices; + const vibe = 50 + who.radius * 0.15 + ctx.moveTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x + vibe * (Math.random() - 0.5), vertices[j].y + vibe * (Math.random() - 0.5)); + ctx.lineTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + who.locatePlayer(); + who.damage(damage / Math.sqrt(who.radius)); + + if (tech.isPhononWave && this.phononWaveCD < m.cycle) { + this.phononWaveCD = m.cycle + 8 * (1 + this.waves[i].resonanceCount) + const halfArc = 0.27 //6.28 is a full circle, but these arcs needs to stay small because we are using small angle linear approximation, for collisions + let closestMob, dist + let range = end - 30 * this.waves[i].resonanceCount + for (let i = 0, len = mob.length; i < len; i++) { + if (who !== mob[i] && !mob[i].isBadTarget && !mob[i].isInvulnerable) { + dist = Vector.magnitude(Vector.sub(who.position, mob[i].position)); + if (dist < range) { + closestMob = mob[i] + range = dist + } + } + } + if (closestMob) { + const dir = Vector.normalise(Vector.sub(closestMob.position, who.position)) + var angle = Math.atan2(dir.y, dir.x) + } else { + var angle = 2 * Math.PI * Math.random() + } + this.waves.push({ + position: who.position, + angle: angle - halfArc, //used in drawing ctx.arc + unit1: { x: Math.cos(angle - halfArc), y: Math.sin(angle - halfArc) }, //used for collision + unit2: { x: Math.cos(angle + halfArc), y: Math.sin(angle + halfArc) }, //used for collision + arc: halfArc * 2, + radius: 25, + resonanceCount: this.waves[i].resonanceCount + 1 + }) + } + } + } + + hits = Matter.Query.ray(body, v1, v2, 50) //Matter.Query.ray(bodies, startPoint, endPoint, [rayWidth]) + for (let j = 0, len = Math.min(30, hits.length); j < len; j++) { + const who = hits[j].body + //make them shake around + who.force.x += 0.01 * (Math.random() - 0.5) * who.mass + who.force.y += (0.01 * (Math.random() - 0.5) - simulation.g * 0.25) * who.mass //remove force of gravity + let vertices = who.vertices; + const vibe = 25 + ctx.moveTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x + vibe * (Math.random() - 0.5), vertices[j].y + vibe * (Math.random() - 0.5)); + } + ctx.lineTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + + if (tech.isPhononBlock && !who.isNotHoldable && who.speed < 5 && who.angularSpeed < 0.1) { + if (Math.random() < 0.5) b.targetedBlock(who, 50 - Math.min(25, who.mass * 3)) // targetedBlock(who, speed = 50 - Math.min(20, who.mass * 2), range = 1600) { + // Matter.Body.setAngularVelocity(who, (0.25 + 0.12 * Math.random()) * (Math.random() < 0.5 ? -1 : 1)); + who.torque += who.inertia * 0.001 * (Math.random() - 0.5) + } + } + + this.waves[i].radius += tech.waveBeamSpeed * 1.8 //expand / move + if (this.waves[i].radius > end - 30 * this.waves[i].resonanceCount) { + this.waves.splice(i, 1) //end + } + } + ctx.stroke(); + } + }, + fireLongitudinal() { + m.fireCDcycle = m.cycle + Math.floor((m.crouch ? 4 : 8) * b.fireCDscale); // cool down + const halfArc = (m.crouch ? 0.0785 : 0.275) * (tech.isBulletTeleport ? 0.66 + (Math.random() - 0.5) : 1) //6.28 is a full circle, but these arcs needs to stay small because we are using small angle linear approximation, for collisions + const angle = m.angle + tech.isBulletTeleport * 0.3 * (Math.random() - 0.5) + this.waves.push({ + position: { x: m.pos.x + 25 * Math.cos(m.angle), y: m.pos.y + 25 * Math.sin(m.angle), }, + angle: angle - halfArc, //used in drawing ctx.arc + unit1: { x: Math.cos(angle - halfArc), y: Math.sin(angle - halfArc) }, //used for collision + unit2: { x: Math.cos(angle + halfArc), y: Math.sin(angle + halfArc) }, //used for collision + arc: halfArc * 2, + radius: 25, + resonanceCount: 0 + }) + }, + doTransverse() { + // if (this.wavePacketCycle && !input.fire) { + // this.wavePacketCycle = 0; + // m.fireCDcycle = m.cycle + Math.floor(this.delay * b.fireCDscale); // cool down + // } + }, + fireTransverse() { + totalCycles = Math.floor((3.5) * 35 * tech.waveReflections * tech.bulletsLastLonger / Math.sqrt(tech.waveReflections * 0.5)) + const me = bullet.length; + bullet[me] = Bodies.polygon(m.pos.x + 25 * Math.cos(m.angle), m.pos.y + 25 * Math.sin(m.angle), 5, 4, { + angle: m.angle, + cycle: -0.5, + endCycle: simulation.cycle + totalCycles, + inertia: Infinity, + frictionAir: 0, + slow: 0, + // amplitude: (m.crouch ? 5 : 10) * ((this.wavePacketCycle % 2) ? -1 : 1) * Math.sin((this.wavePacketCycle + 1) * 0.088), //0.0968 //0.1012 //0.11 //0.088 //shorten wave packet + amplitude: (m.crouch ? 6 : 12) * ((this.wavePacketCycle % 2) ? -1 : 1) * Math.sin(this.wavePacketCycle * 0.088) * Math.sin(this.wavePacketCycle * 0.04), //0.0968 //0.1012 //0.11 //0.088 //shorten wave packet + minDmgSpeed: 0, + dmg: m.dmgScale * tech.waveBeamDamage * tech.wavePacketDamage * (tech.isBulletTeleport ? 1.43 : 1) * (tech.isInfiniteWaveAmmo ? 0.75 : 1), //also control damage when you divide by mob.mass + dmgCoolDown: 0, + classType: "bullet", + collisionFilter: { + category: 0, + mask: 0, //cat.mob | cat.mobBullet | cat.mobShield + }, + beforeDmg() { }, + onEnd() { }, + do() { }, + query() { + let slowCheck = 1 + if (Matter.Query.point(map, this.position).length) { //check if inside map + slowCheck = waveSpeedMap + } else { //check if inside a body + let q = Matter.Query.point(body, this.position) + if (q.length) { + slowCheck = waveSpeedBody + Matter.Body.setPosition(this, Vector.add(this.position, q[0].velocity)) //move with the medium + } + } + if (slowCheck !== this.slow) { //toggle velocity based on inside and outside status change + this.slow = slowCheck + Matter.Body.setVelocity(this, Vector.mult(Vector.normalise(this.velocity), tech.waveBeamSpeed * slowCheck)); + } + + if (this.dmgCoolDown < 1) { + q = Matter.Query.point(mob, this.position) // check if inside a mob + for (let i = 0; i < q.length; i++) { + this.dmgCoolDown = 5 + Math.floor(8 * Math.random() * b.fireCDscale); + let dmg = this.dmg + q[i].damage(dmg); + if (q[i].alive) { + q[i].foundPlayer(); + Matter.Body.setVelocity(q[i], Vector.mult(q[i].velocity, 0.9)) + } + // this.endCycle = 0; //bullet ends cycle after doing damage + if (q[i].damageReduction) { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.log(dmg + 1.1) * 40 * q[i].damageReduction + 3, + color: 'rgba(0,0,0,0.4)', + time: simulation.drawTime + }); + } + } + } else { + this.dmgCoolDown-- + } + }, + wiggle() { + this.cycle++ + const where = Vector.mult(transverse, this.amplitude * Math.cos(this.cycle * tech.waveFrequency)) + Matter.Body.setPosition(this, Vector.add(this.position, where)) + } + }); + if (tech.isBulletTeleport) { + bullet[me].wiggle = function () { + this.cycle++ + const where = Vector.mult(transverse, this.amplitude * Math.cos(this.cycle * tech.waveFrequency)) + if (Math.random() < 0.005) { + if (Math.random() < 0.33) { //randomize position + const scale = 500 * Math.random() + Matter.Body.setPosition(this, Vector.add({ + x: scale * (Math.random() - 0.5), + y: scale * (Math.random() - 0.5) + }, Vector.add(this.position, where))) + } else { //randomize position in velocity direction + const velocityScale = Vector.mult(this.velocity, 50 * (Math.random() - 0.5)) + Matter.Body.setPosition(this, Vector.add(velocityScale, Vector.add(this.position, where))) + } + + } else { + Matter.Body.setPosition(this, Vector.add(this.position, where)) + } + } + } + let waveSpeedMap = 0.13 + let waveSpeedBody = 0.3 + if (tech.isPhaseVelocity) { + waveSpeedMap = 3.5 + waveSpeedBody = 2 + bullet[me].dmg *= 1.5 + } + if (tech.waveReflections) { + bullet[me].reflectCycle = totalCycles / tech.waveReflections //tech.waveLengthRange + bullet[me].do = function () { + this.query() + if (this.cycle > this.reflectCycle) { + this.reflectCycle += totalCycles / tech.waveReflections + Matter.Body.setVelocity(this, Vector.mult(this.velocity, -1)); + // if (this.reflectCycle > tech.waveLengthRange * (1 + tech.waveReflections)) this.endCycle = 0; + } + this.wiggle() + } + } else { + bullet[me].do = function () { + this.query() + this.wiggle(); + } + } + Composite.add(engine.world, bullet[me]); //add bullet to world + Matter.Body.setVelocity(bullet[me], { + x: tech.waveBeamSpeed * Math.cos(m.angle), + y: tech.waveBeamSpeed * Math.sin(m.angle) + }); + const transverse = Vector.normalise(Vector.perp(bullet[me].velocity)) + this.wavePacketCycle++ + }, + fire() { } + }, + { + name: "missiles", //6 + // description: `launch homing missiles that target mobs
missiles explode on contact with mobs
5 missiles per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `launch homing missiles that target mobs
missiles explode on contact with mobs
${this.ammoPack.toFixed(1)} missiles per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 2.3, + defaultAmmoPack: 2.3, + have: false, + fireCycle: 0, + do() { }, + fire() { + const countReduction = Math.pow(0.86, tech.missileCount) + // if (m.crouch) { + // m.fireCDcycle = m.cycle + tech.missileFireCD * b.fireCDscale / countReduction; // cool down + // // for (let i = 0; i < tech.missileCount; i++) { + // // b.missile(where, -Math.PI / 2 + 0.2 * (Math.random() - 0.5) * Math.sqrt(tech.missileCount), -2, Math.sqrt(countReduction)) + // // bullet[bullet.length - 1].force.x += 0.004 * countReduction * (i - (tech.missileCount - 1) / 2); + // // } + + // if (tech.missileCount > 1) { + // for (let i = 0; i < tech.missileCount; i++) { + // setTimeout(() => { + // const where = { x: m.pos.x, y: m.pos.y - 40 } + // b.missile(where, -Math.PI / 2 + 0.2 * (Math.random() - 0.5) * Math.sqrt(tech.missileCount), -2, Math.sqrt(countReduction)) + // bullet[bullet.length - 1].force.x += 0.025 * countReduction * (i - (tech.missileCount - 1) / 2); + // }, 20 * tech.missileCount * Math.random()); + // } + // } else { + // const where = { + // x: m.pos.x, + // y: m.pos.y - 40 + // } + // b.missile(where, -Math.PI / 2 + 0.2 * (Math.random() - 0.5), -2) + // } + // } else { + m.fireCDcycle = m.cycle + tech.missileFireCD * b.fireCDscale / countReduction; // cool down + const direction = { x: Math.cos(m.angle), y: Math.sin(m.angle) } + // const where = { + // x: m.pos.x + 30 * direction.x, + // y: m.pos.y + 30 * direction.y + // } + if (tech.missileCount > 1) { + const push = Vector.mult(Vector.perp(direction), 0.2 * countReduction / Math.sqrt(tech.missileCount)) + const sqrtCountReduction = Math.sqrt(countReduction) + // for (let i = 0; i < tech.missileCount; i++) { + // setTimeout(() => { + // if (m.crouch) { + // b.missile(where, m.angle, 20, sqrtCountReduction) + // // bullet[bullet.length - 1].force.x += 0.7 * push.x * (i - (tech.missileCount - 1) / 2); + // // bullet[bullet.length - 1].force.y += 0.7 * push.y * (i - (tech.missileCount - 1) / 2); + // } else { + // b.missile(where, m.angle, -10, sqrtCountReduction) + // bullet[bullet.length - 1].force.x += push.x * (i - (tech.missileCount - 1) / 2); + // bullet[bullet.length - 1].force.y += 0.005 + push.y * (i - (tech.missileCount - 1) / 2); + // } + + // }, 1 + i * 10 * tech.missileCount); + // } + const launchDelay = 4 + let count = 0 + const fireMissile = () => { + if (m.crouch) { + b.missile({ x: m.pos.x + 30 * direction.x, y: m.pos.y + 30 * direction.y }, m.angle, 20, sqrtCountReduction) + bullet[bullet.length - 1].force.x += 0.5 * push.x * (Math.random() - 0.5) + bullet[bullet.length - 1].force.y += 0.004 + 0.5 * push.y * (Math.random() - 0.5) + } else { + b.missile({ x: m.pos.x + 30 * direction.x, y: m.pos.y + 30 * direction.y }, m.angle, -15, sqrtCountReduction) + bullet[bullet.length - 1].force.x += push.x * (Math.random() - 0.5) + bullet[bullet.length - 1].force.y += 0.005 + push.y * (Math.random() - 0.5) + } + } + const cycle = () => { + if ((simulation.paused) && m.alive) { + requestAnimationFrame(cycle) + } else { + count++ + if (!(count % launchDelay)) { + fireMissile() + } + if (count < tech.missileCount * launchDelay && m.alive) requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + } else { + if (m.crouch) { + b.missile({ x: m.pos.x + 40 * direction.x, y: m.pos.y + 40 * direction.y }, m.angle, 25) + } else { + b.missile({ x: m.pos.x + 40 * direction.x, y: m.pos.y + 40 * direction.y }, m.angle, -12) + bullet[bullet.length - 1].force.y += 0.04 * (Math.random() - 0.2) + } + } + } + }, { + name: "grenades", //5 + // description: `lob a single bouncy projectile
explodes on contact or after one second
7 grenades per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `lob a single bouncy projectile
explodes on contact or after 1.5 seconds
${this.ammoPack.toFixed(0)} grenades per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 3.2, + defaultAmmoPack: 3.2, + have: false, + do() { }, //do is set in b.setGrenadeMode() + fire() { + const countReduction = Math.pow(0.93, tech.missileCount) + m.fireCDcycle = m.cycle + Math.floor((m.crouch ? 35 : 27) * b.fireCDscale / countReduction); // cool down + const where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + } + const SPREAD = m.crouch ? 0.12 : 0.2 + let angle = m.angle - SPREAD * (tech.missileCount - 1) / 2; + for (let i = 0; i < tech.missileCount; i++) { + b.grenade(where, angle, countReduction) //function(where = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) }, angle = m.angle, size = 1) + angle += SPREAD + } + }, + }, { + name: "spores", //6 + // description: `toss a sporangium that discharges spores
spores seek out nearby mobs
2-3 sporangium per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `toss a sporangium that discharges ${b.guns[6].nameString("s")}
${b.guns[6].nameString("s")} seek out nearby mobs
${this.ammoPack.toFixed(1)} sporangium per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 1.22, + defaultAmmoPack: 1.22, + have: false, + nameString(suffix = "") { + if (tech.isSporeFlea) { + return `flea${suffix}` + } else if (tech.isSporeWorm) { + return `worm${suffix}` + } else { + return `spore${suffix}` + } + }, + do() { }, + fire() { + const me = bullet.length; + const dir = m.angle; + bullet[me] = Bodies.polygon(m.pos.x + 30 * Math.cos(m.angle), m.pos.y + 30 * Math.sin(m.angle), 20, 4.5, b.fireAttributes(dir, false)); + b.fireProps(m.crouch ? 40 : 20, m.crouch ? 30 : 16, dir, me); //cd , speed + Matter.Body.setDensity(bullet[me], 0.000001); + bullet[me].endCycle = simulation.cycle + 480 + Math.max(0, 120 - 2 * bullet.length); + bullet[me].frictionAir = 0; + bullet[me].friction = 0.5; + bullet[me].radius = 4.5; + bullet[me].maxRadius = 30; + bullet[me].restitution = 0.3; + bullet[me].minDmgSpeed = 0; + bullet[me].totalSpores = 8 + 2 * tech.isSporeFreeze + 5 * tech.isSporeColony + bullet[me].stuck = function () { }; + bullet[me].beforeDmg = function () { }; + bullet[me].do = function () { + function onCollide(that) { + that.collisionFilter.mask = 0; //non collide with everything + Matter.Body.setVelocity(that, { x: 0, y: 0 }); + that.do = that.grow; + } + const mobCollisions = Matter.Query.collides(this, mob) + if (mobCollisions.length) { + onCollide(this) + this.stuckTo = mobCollisions[0].bodyA + if (tech.isZombieMobs) this.stuckTo.isSoonZombie = true + if (this.stuckTo.isVerticesChange) { + this.stuckToRelativePosition = { x: 0, y: 0 } + } else { + //find the relative position for when the mob is at angle zero by undoing the mobs rotation + this.stuckToRelativePosition = Vector.rotate(Vector.sub(this.position, this.stuckTo.position), -this.stuckTo.angle) + } + this.stuck = function () { + if (this.stuckTo && this.stuckTo.alive) { + const rotate = Vector.rotate(this.stuckToRelativePosition, this.stuckTo.angle) //add in the mob's new angle to the relative position vector + Matter.Body.setPosition(this, Vector.add(Vector.add(rotate, this.stuckTo.velocity), this.stuckTo.position)) + Matter.Body.setVelocity(this, this.stuckTo.velocity); //so that it will move properly if it gets unstuck + } else { + this.collisionFilter.mask = cat.map; //non collide with everything but map + this.stuck = function () { + this.force.y += this.mass * 0.0006; + } + } + } + } else { + const bodyCollisions = Matter.Query.collides(this, body) + if (bodyCollisions.length) { + if (!bodyCollisions[0].bodyA.isNonStick) { + onCollide(this) + this.stuckTo = bodyCollisions[0].bodyA + //find the relative position for when the mob is at angle zero by undoing the mobs rotation + this.stuckToRelativePosition = Vector.rotate(Vector.sub(this.position, this.stuckTo.position), -this.stuckTo.angle) + } else { + this.do = this.grow; + } + this.stuck = function () { + if (this.stuckTo) { + const rotate = Vector.rotate(this.stuckToRelativePosition, this.stuckTo.angle) //add in the mob's new angle to the relative position vector + Matter.Body.setPosition(this, Vector.add(Vector.add(rotate, this.stuckTo.velocity), this.stuckTo.position)) + // Matter.Body.setVelocity(this, this.stuckTo.velocity); //so that it will move properly if it gets unstuck + } else { + this.force.y += this.mass * 0.0006; + } + } + } else { + if (Matter.Query.collides(this, map).length) { + onCollide(this) + } else { //if colliding with nothing just fall + this.force.y += this.mass * 0.0006; + simulation.mouseInGame.x + } + } + } + //draw green glow + ctx.fillStyle = "rgba(0,200,125,0.16)"; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.maxRadius, 0, 2 * Math.PI); + ctx.fill(); + } + bullet[me].grow = function () { + this.stuck(); //runs different code based on what the bullet is stuck to + let scale = 1.01 + if (tech.isSporeGrowth && !(simulation.cycle % 40)) { //release a spore + if (tech.isSporeFlea) { + if (!(simulation.cycle % 80)) { + const speed = 10 + 5 * Math.random() + const angle = 2 * Math.PI * Math.random() + b.flea(this.position, { + x: speed * Math.cos(angle), + y: speed * Math.sin(angle) + }) + } + } else if (tech.isSporeWorm) { + if (!(simulation.cycle % 80)) b.worm(this.position) + } else { + b.spore(this.position) + } + scale = 0.96 + if (this.stuckTo && this.stuckTo.alive) scale = 0.9 + Matter.Body.scale(this, scale, scale); + this.radius *= scale + } else { + if (this.stuckTo && this.stuckTo.alive) scale = 1.03 + Matter.Body.scale(this, scale, scale); + this.radius *= scale + if (this.radius > this.maxRadius) this.endCycle = 0; + } + //draw green glow + ctx.fillStyle = "rgba(0,200,125,0.16)"; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.maxRadius, 0, 2 * Math.PI); + ctx.fill(); + }; + //spawn bullets on end + bullet[me].onEnd = function () { + let count = 0 //used in for loop below + const things = [ + () => { //spore + b.spore(this.position) + }, + () => { //worm + count++ //count as 2 things + b.worm(this.position) + }, + () => { //flea + count++ //count as 2 things + const speed = 10 + 5 * Math.random() + const angle = 2 * Math.PI * Math.random() + b.flea(this.position, { + x: speed * Math.cos(angle), + y: speed * Math.sin(angle) + }) + }, + () => { // drones + b.drone(this.position) + }, + () => { // ice IX + b.iceIX(1, Math.random() * 2 * Math.PI, this.position) + }, + () => { //missile + count++ //count as 2 things + b.missile(this.position, -Math.PI / 2 + 0.5 * (Math.random() - 0.5), 0, 1) + }, + () => { //nail + b.targetedNail(this.position, 1, 39 + 6 * Math.random()) + }, + () => { //super ball + const speed = 36 + const angle = 2 * Math.PI * Math.random() + b.superBall(this.position, { + x: speed * Math.cos(angle), + y: speed * Math.sin(angle) + }, 11 * tech.bulletSize) + }, + ] + + for (len = this.totalSpores; count < len; count++) { + if (tech.isSporeColony && Math.random() < 0.33) { + things[Math.floor(Math.random() * things.length)]() + } else if (tech.isSporeFlea) { + things[2]() + } else if (tech.isSporeWorm) { + things[1]() + } else { + things[0]() //spores + } + } + // } else if (tech.isSporeFlea) { + // for (let i = 0, len = this.totalSpores; i < len; i++) things[2]() + // } else if (tech.isSporeWorm) { + // for (let i = 0, len = this.totalSpores; i < len; i++) things[1]() + // } else { + // for (let i = 0; i < this.totalSpores; i++) things[0]() + // } + if (tech.isStun) b.AoEStunEffect(this.position, 600, 270 + 120 * Math.random()); //AoEStunEffect(where, range, cycles = 120 + 60 * Math.random()) { + } + } + }, { + name: "drones", //7 + // description: `deploy autonomous drones that smash into mobs
and collect nearby power ups
16 drones per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `deploy autonomous drones that smash into mobs
drones collect nearby power ups
${this.ammoPack.toFixed(0)} drones per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 7.3, + defaultAmmoPack: 7.3, + have: false, + do() { }, + fire() { + if (tech.isDroneRadioactive) { + if (m.crouch) { + b.droneRadioactive({ + x: m.pos.x + 30 * Math.cos(m.angle) + 10 * (Math.random() - 0.5), + y: m.pos.y + 30 * Math.sin(m.angle) + 10 * (Math.random() - 0.5) + }, 45) + m.fireCDcycle = m.cycle + Math.floor(45 * b.fireCDscale); // cool down + } else { + b.droneRadioactive({ + x: m.pos.x + 30 * Math.cos(m.angle) + 10 * (Math.random() - 0.5), + y: m.pos.y + 30 * Math.sin(m.angle) + 10 * (Math.random() - 0.5) + }, 10) + m.fireCDcycle = m.cycle + Math.floor(25 * b.fireCDscale); // cool down + } + } else { + if (m.crouch) { + b.drone({ + x: m.pos.x + 30 * Math.cos(m.angle) + 5 * (Math.random() - 0.5), + y: m.pos.y + 30 * Math.sin(m.angle) + 5 * (Math.random() - 0.5) + }, 50) + m.fireCDcycle = m.cycle + Math.floor(7 * b.fireCDscale); // cool down + } else { + b.drone({ + x: m.pos.x + 30 * Math.cos(m.angle) + 10 * (Math.random() - 0.5), + y: m.pos.y + 30 * Math.sin(m.angle) + 10 * (Math.random() - 0.5) + }, 15) + m.fireCDcycle = m.cycle + Math.floor(4 * b.fireCDscale); // cool down + } + } + } + }, + { + name: "foam", //8 + descriptionFunction() { + return `spray bubbly foam that sticks to mobs
slows mobs and does damage over time
${this.ammoPack.toFixed(0)} bubbles per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 12.6, + defaultAmmoPack: 12.6, + have: false, + charge: 0, + isDischarge: false, + knockBack: 0.0005, //set in tech: cavitation + applyKnock(velocity) { + player.force.x -= this.knockBack * velocity.x + player.force.y -= 2 * this.knockBack * velocity.y + }, + chooseFireMethod() { + if (tech.isFoamPressure) { + this.do = this.doCharges + this.fire = this.fireCharges + } else { + this.do = this.doStream + this.fire = this.fireStream + } + }, + doStream() { }, + fireStream() { + const spread = (m.crouch ? + 0.04 * (Math.random() - 0.5) + 0.09 * Math.sin(m.cycle * 0.12) : + 0.23 * (Math.random() - 0.5) + 0.15 * Math.sin(m.cycle * 0.12) + ) + const radius = 5 + 8 * Math.random() + (tech.isAmmoFoamSize && this.ammo < 300) * 12 + const SPEED = (m.crouch ? 1.2 : 1) * Math.max(2, 14 - radius * 0.25) + const dir = m.angle + 0.15 * (Math.random() - 0.5) + const velocity = { + x: 0.7 * player.velocity.x + SPEED * Math.cos(dir), + y: 0.5 * player.velocity.y + SPEED * Math.sin(dir) + } + const position = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) } + b.foam(position, Vector.rotate(velocity, spread), radius) + // this.applyKnock(velocity) + m.fireCDcycle = m.cycle + Math.floor(1.5 * b.fireCDscale); + }, + doCharges() { + if (this.charge > 0) { + //draw charge level + ctx.fillStyle = "rgba(0,50,50,0.3)"; + ctx.beginPath(); + const radius = 5 * Math.sqrt(this.charge) + const mag = 11 + radius + ctx.arc(m.pos.x + mag * Math.cos(m.angle), m.pos.y + mag * Math.sin(m.angle), radius, 0, 2 * Math.PI); + ctx.fill(); + + if (this.isDischarge && m.cycle % 2) { + const spread = (m.crouch ? 0.04 : 0.5) * (Math.random() - 0.5) + const radius = 5 + 8 * Math.random() + (tech.isAmmoFoamSize && this.ammo < 300) * 12 + const SPEED = (m.crouch ? 1.2 : 1) * 10 - radius * 0.4 + Math.min(5, Math.sqrt(this.charge)); + const dir = m.angle + 0.15 * (Math.random() - 0.5) + const velocity = { + x: 0.7 * player.velocity.x + SPEED * Math.cos(dir), + y: 0.5 * player.velocity.y + SPEED * Math.sin(dir) + } + const position = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + } + b.foam(position, Vector.rotate(velocity, spread), radius) + // this.applyKnock(velocity) + this.charge -= 0.75 + m.fireCDcycle = m.cycle + 2; //disable firing and adding more charge until empty + } else if (!input.fire) { + this.isDischarge = true; + } + } else { + if (this.isDischarge) { + m.fireCDcycle = m.cycle + Math.floor(25 * b.fireCDscale); + } + this.isDischarge = false + } + }, + fireCharges() { + const spread = (m.crouch ? + 0.04 * (Math.random() - 0.5) + 0.09 * Math.sin(m.cycle * 0.12) : + 0.23 * (Math.random() - 0.5) + 0.15 * Math.sin(m.cycle * 0.12) + ) + const radius = 5 + 8 * Math.random() + (tech.isAmmoFoamSize && this.ammo < 300) * 12 + const SPEED = (m.crouch ? 1.2 : 1) * Math.max(2, 14 - radius * 0.25) + const dir = m.angle + 0.15 * (Math.random() - 0.5) + const velocity = { + x: 0.7 * player.velocity.x + SPEED * Math.cos(dir), + y: 0.5 * player.velocity.y + SPEED * Math.sin(dir) + } + const position = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) } + + b.foam(position, Vector.rotate(velocity, spread), radius) + // this.applyKnock(velocity) + m.fireCDcycle = m.cycle + Math.floor(1.5 * b.fireCDscale); + this.charge += 1 + tech.isCapacitor + }, + fire() { }, + do() { }, + }, + { + name: "harpoon", //9 + // description: `throw a self-steering harpoon that uses energy
to retract and refund its ammo cost
1-2 harpoons per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `throw a harpoon that uses energy to retract
harpoons refund ammo
${this.ammoPack.toFixed(1)} harpoons per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 0.77, //update this in railgun tech + defaultAmmoPack: 0.77, + have: false, + fire() { }, + do() { }, + chooseFireMethod() { + if (tech.isRailGun) { + this.do = this.railDo + this.fire = this.railFire + // } else if (tech.isGrapple) { + // this.do = () => { } + // this.fire = this.grappleFire + } else { + this.do = () => { } + this.fire = this.harpoonFire + } + }, + charge: 0, + railDo() { + if (this.charge > 0) { + const DRAIN = (tech.isRailEnergy ? 0 : 0.002) + //exit railgun charging without firing + if (m.energy < DRAIN) { + m.fireCDcycle = m.cycle + 120; // cool down if out of energy + this.endCycle = 0; + this.charge = 0 + b.refundAmmo() + return + } + //fire + if ((!input.fire && this.charge > 0.6)) { + const where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + } + const closest = { + distance: 10000, + target: null + } + //push away blocks and mobs + const range = 600 + 500 * this.charge + for (let i = 0, len = mob.length; i < len; ++i) { //push away mobs when firing + if (!mob[i].isUnblockable) { + const SUB = Vector.sub(mob[i].position, m.pos) + const DISTANCE = Vector.magnitude(SUB) + if (DISTANCE < range + mob[i].radius) { + const DEPTH = 100 + Math.min(range - DISTANCE + mob[i].radius, 1500) + const FORCE = Vector.mult(Vector.normalise(SUB), 0.0015 * Math.sqrt(DEPTH) * mob[i].mass) + mob[i].force.x += FORCE.x; + mob[i].force.y += FORCE.y; + + let dmg = m.dmgScale * (mob[i].isDropPowerUp ? 350 : 1100) * tech.harpoonDensity * this.charge + simulation.drawList.push({ //add dmg to draw queue + x: mob[i].position.x, + y: mob[i].position.y, + radius: Math.log(dmg + 1.1) * 40 * mob[i].damageReduction + 3, + color: 'rgba(100, 0, 200, 0.4)', + time: 15 + }); + mob[i].damage(dmg); + } + } + } + for (let i = 0, len = body.length; i < len; ++i) { //push away blocks when firing + const SUB = Vector.sub(body[i].position, m.pos) + const DISTANCE = Vector.magnitude(SUB) + if (DISTANCE < range) { + const DEPTH = Math.min(range - DISTANCE, 500) + const FORCE = Vector.mult(Vector.normalise(SUB), 0.003 * Math.sqrt(DEPTH) * body[i].mass) + body[i].force.x += FORCE.x; + body[i].force.y += FORCE.y - body[i].mass * simulation.g * 1.5; //kick up a bit to give them some arc + } + } + for (let i = 0, len = powerUp.length; i < len; ++i) { //push away blocks when firing + const SUB = Vector.sub(powerUp[i].position, m.pos) + const DISTANCE = Vector.magnitude(SUB) + if (DISTANCE < range) { + const DEPTH = Math.min(range - DISTANCE, 500) + const FORCE = Vector.mult(Vector.normalise(SUB), 0.002 * Math.sqrt(DEPTH) * powerUp[i].mass) + powerUp[i].force.x += FORCE.x; + powerUp[i].force.y += FORCE.y - powerUp[i].mass * simulation.g * 1.5; //kick up a bit to give them some arc + } + } + //draw little dots near the edge of range + for (let i = 0, len = 10 + 25 * this.charge; i < len; i++) { + const unit = Vector.rotate({ + x: 1, + y: 0 + }, 6.28 * Math.random()) + const where = Vector.add(m.pos, Vector.mult(unit, range * (0.6 + 0.3 * Math.random()))) + simulation.drawList.push({ + x: where.x, + y: where.y, + radius: 5 + 12 * Math.random(), + color: "rgba(100, 0, 200, 0.1)", + time: Math.floor(5 + 35 * Math.random()) + }); + } + + const recoil = Vector.mult(Vector.normalise(Vector.sub(where, m.pos)), m.crouch ? 0.03 : 0.06) + player.force.x -= recoil.x + player.force.y -= recoil.y + const harpoonSize = tech.isLargeHarpoon ? 1 + 0.07 * Math.sqrt(this.ammo) : 1 + const thrust = 0.15 * (this.charge) + if (tech.extraHarpoons) { + let targetCount = 0 + const SPREAD = 0.06 + 0.05 * (!m.crouch) + let angle = m.angle - SPREAD * tech.extraHarpoons / 2; + const dir = { + x: Math.cos(angle), + y: Math.sin(angle) + }; //make a vector for the player's direction of length 1; used in dot product + + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && !mob[i].isBadTarget && !mob[i].shield && Matter.Query.ray(map, m.pos, mob[i].position).length === 0 && !mob[i].isInvulnerable) { + const dot = Vector.dot(dir, Vector.normalise(Vector.sub(mob[i].position, m.pos))) //the dot product of diff and dir will return how much over lap between the vectors + const dist = Vector.magnitude(Vector.sub(where, mob[i].position)) + if (dot > 0.95 - Math.min(dist * 0.00015, 0.3)) { //lower dot product threshold for targeting then if you only have one harpoon //target closest mob that player is looking at and isn't too close to target + // if (this.ammo > -1) { + // this.ammo-- + b.harpoon(where, m.crouch ? null : mob[i], angle, harpoonSize, false, 35, false, thrust) //harpoon(where, target, angle = m.angle, harpoonSize = 1, isReturn = false, totalCycles = 35, isReturnAmmo = true, thrust = 0.1) { + angle += SPREAD + targetCount++ + if (targetCount > tech.extraHarpoons) break + // } + } + } + } + //if more harpoons and no targets left + if (targetCount < tech.extraHarpoons + 1) { + const num = tech.extraHarpoons + 1 - targetCount + for (let i = 0; i < num; i++) { + b.harpoon(where, null, angle, harpoonSize, false, 35, false, thrust) + angle += SPREAD + } + } + simulation.updateGunHUD(); + } else { + //look for closest mob in player's LoS + const dir = { + x: Math.cos(m.angle), + y: Math.sin(m.angle) + }; //make a vector for the player's direction of length 1; used in dot product + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && !mob[i].isBadTarget && Matter.Query.ray(map, m.pos, mob[i].position).length === 0 && !mob[i].isInvulnerable) { + const dot = Vector.dot(dir, Vector.normalise(Vector.sub(mob[i].position, m.pos))) //the dot product of diff and dir will return how much over lap between the vectors + const dist = Vector.magnitude(Vector.sub(where, mob[i].position)) + if (dist < closest.distance && dot > 0.98 - Math.min(dist * 0.00014, 0.3)) { //target closest mob that player is looking at and isn't too close to target + closest.distance = dist + closest.target = mob[i] + } + } + } + b.harpoon(where, closest.target, m.angle, harpoonSize, false, 35, false, thrust) + } + + this.charge = 0; + } else { //charging + if (tech.isFireMoveLock) { + Matter.Body.setVelocity(player, { + x: 0, + y: -55 * player.mass * simulation.g //undo gravity before it is added + }); + player.force.x = 0 + player.force.y = 0 + } + m.fireCDcycle = m.cycle + 10 //can't fire until mouse is released + // const previousCharge = this.charge + + //small b.fireCDscale = faster shots, b.fireCDscale=1 = normal shot, big b.fireCDscale = slower chot + // let smoothRate = tech.isCapacitor ? 0.85 : Math.min(0.998, 0.985 * (0.98 + 0.02 * b.fireCDscale)) + const rate = Math.sqrt(b.fireCDscale) * tech.railChargeRate * (tech.isCapacitor ? 0.6 : 1) * (m.crouch ? 0.8 : 1) + let smoothRate = Math.min(0.998, 0.94 + 0.05 * rate) + + + this.charge = 1 - smoothRate + this.charge * smoothRate + if (m.energy > DRAIN) m.energy -= DRAIN + + //draw magnetic field + const X = m.pos.x + const Y = m.pos.y + const unitVector = { + x: Math.cos(m.angle), + y: Math.sin(m.angle) + } + const unitVectorPerp = Vector.perp(unitVector) + + function magField(mag, arc) { + ctx.moveTo(X, Y); + ctx.bezierCurveTo( + X + unitVector.x * mag, Y + unitVector.y * mag, + X + unitVector.x * mag + unitVectorPerp.x * arc, Y + unitVector.y * mag + unitVectorPerp.y * arc, + X + unitVectorPerp.x * arc, Y + unitVectorPerp.y * arc) + ctx.bezierCurveTo( + X - unitVector.x * mag + unitVectorPerp.x * arc, Y - unitVector.y * mag + unitVectorPerp.y * arc, + X - unitVector.x * mag, Y - unitVector.y * mag, + X, Y) + } + ctx.fillStyle = `rgba(50,0,100,0.05)`; + const magSize = 8 * this.charge * tech.railChargeRate ** 3 + const arcSize = 6 * this.charge * tech.railChargeRate ** 3 + for (let i = 3; i < 7; i++) { + const MAG = magSize * i * i * (0.93 + 0.07 * Math.random()) + const ARC = arcSize * i * i * (0.93 + 0.07 * Math.random()) + ctx.beginPath(); + magField(MAG, ARC) + magField(MAG, -ARC) + ctx.fill(); + } + } + } + }, + railFire() { + m.fireCDcycle = m.cycle + 10 //can't fire until mouse is released + this.charge += 0.00001 + }, + // grappleFire() { + // const harpoonSize = (tech.isLargeHarpoon ? 1 + 0.1 * Math.sqrt(this.ammo) : 1) //* (m.crouch ? 0.7 : 1) + // const where = { + // x: m.pos.x + harpoonSize * 40 * Math.cos(m.angle), + // y: m.pos.y + harpoonSize * 40 * Math.sin(m.angle) + // } + // const num = Math.min(this.ammo, tech.extraHarpoons + 1) + // if (!m.crouch && num > 1) { //multiple harpoons + // const SPREAD = 0.06 + // let angle = m.angle - SPREAD * num / 2; + // for (let i = 0; i < num; i++) { + // if (this.ammo > 0) { + // this.ammo-- + // b.grapple(where, angle, true, harpoonSize) + // angle += SPREAD + // } + // } + // this.ammo++ //make up for the ammo used up in fire() + // simulation.updateGunHUD(); + // m.fireCDcycle = m.cycle + Math.floor(75 * b.fireCDscale) // cool down + // // } else if (m.crouch) { + // // b.harpoon(where, null, m.angle, harpoonSize, false, 70) + // } else { + // if (tech.crouchAmmoCount) tech.crouchAmmoCount = 1 + // b.grapple(where, m.angle, harpoonSize) + // } + // // m.fireCDcycle = m.cycle + Math.floor(75 * b.fireCDscale) // cool down + // m.fireCDcycle = m.cycle + 5 + 40 * b.fireCDscale + 60 * (m.energy < 0.05) + + // }, + harpoonFire() { + const where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + } + const closest = { + distance: 10000, + target: null + } + //look for closest mob in player's LoS + const harpoonSize = (tech.isLargeHarpoon ? 1 + 0.1 * Math.sqrt(this.ammo) : 1) //* (m.crouch ? 0.7 : 1) + const totalCycles = 6.5 * (tech.isFilament ? 1 + 0.013 * Math.min(110, this.ammo) : 1) * Math.sqrt(harpoonSize) + + if (tech.extraHarpoons && !m.crouch) { //multiple harpoons + const SPREAD = 0.2 + let angle = m.angle - SPREAD * tech.extraHarpoons / 2; + const dir = { x: Math.cos(angle), y: Math.sin(angle) }; //make a vector for the player's direction of length 1; used in dot product + const range = 450 * (tech.isFilament ? 1 + 0.012 * Math.min(110, this.ammo) : 1) + let targetCount = 0 + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && !mob[i].isBadTarget && !mob[i].shield && Matter.Query.ray(map, m.pos, mob[i].position).length === 0 && !mob[i].isInvulnerable) { + const dot = Vector.dot(dir, Vector.normalise(Vector.sub(mob[i].position, m.pos))) //the dot product of diff and dir will return how much over lap between the vectors + const dist = Vector.magnitude(Vector.sub(where, mob[i].position)) + if (dist < range && dot > 0.9) { //lower dot product threshold for targeting then if you only have one harpoon //target closest mob that player is looking at and isn't too close to target + if (this.ammo > 0) { + this.ammo-- + b.harpoon(where, mob[i], angle, harpoonSize, true, totalCycles) //Vector.angle(Vector.sub(where, mob[i].position), { x: 0, y: 0 }) + angle += SPREAD + targetCount++ + if (targetCount > tech.extraHarpoons) break + } + } + } + } + //if more harpoons and no targets left + if (targetCount < tech.extraHarpoons + 1) { + const num = tech.extraHarpoons - targetCount + const delay = 1 //Math.floor(Math.max(4, 8 - 0.5 * tech.extraHarpoons)) + let angle = m.angle - SPREAD * tech.extraHarpoons / 2; + let count = -1 + let harpoonDelay = () => { + if (simulation.paused) { + requestAnimationFrame(harpoonDelay) + } else { + count++ + if (!(count % delay) && this.ammo > 0) { + this.ammo-- + b.harpoon({ x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) }, null, angle, harpoonSize, true, totalCycles) + angle += SPREAD + } + if (count < num * delay && m.alive) requestAnimationFrame(harpoonDelay); + } + } + requestAnimationFrame(harpoonDelay) + } + this.ammo++ //make up for the ammo used up in fire() + simulation.updateGunHUD(); + + } else { //m.crouch makes a single harpoon with longer range + const dir = { + x: Math.cos(m.angle), + y: Math.sin(m.angle) + }; //make a vector for the player's direction of length 1; used in dot product + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && !mob[i].isBadTarget && Matter.Query.ray(map, m.pos, mob[i].position).length === 0 && !mob[i].isInvulnerable) { + const dot = Vector.dot(dir, Vector.normalise(Vector.sub(mob[i].position, m.pos))) //the dot product of diff and dir will return how much over lap between the vectors + const dist = Vector.magnitude(Vector.sub(where, mob[i].position)) + if (dist < closest.distance && dot > 0.98 - Math.min(dist * 0.00014, 0.3)) { //target closest mob that player is looking at and isn't too close to target + closest.distance = dist + closest.target = mob[i] + } + } + } + if (m.crouch && m.onGround) { + b.harpoon(where, null, m.angle, harpoonSize, true, 1.6 * totalCycles, (m.crouch && tech.crouchAmmoCount && (tech.crouchAmmoCount - 1) % 2) ? false : true) // harpoon(where, target, angle = m.angle, harpoonSize = 1, isReturn = false, totalCycles = 35, isReturnAmmo = true) { + } else { + b.harpoon(where, closest.target, m.angle, harpoonSize, true, totalCycles) + } + } + m.fireCDcycle = m.cycle + 5 + 35 * b.fireCDscale + 60 * (m.energy < 0.05) + tech.extraHarpoons // cool down is set when harpoon bullet returns to player + const recoil = Vector.mult(Vector.normalise(Vector.sub(where, m.pos)), m.crouch ? 0.015 : 0.035) + player.force.x -= recoil.x + player.force.y -= recoil.y + }, + }, { + name: "mine", //10 + // description: `toss a proximity mine that sticks to walls
refund undetonated mines on exiting a level
1-2 mines per ${powerUps.orb.ammo()}`, + descriptionFunction() { + return `toss a proximity mine that sticks to walls
refund undetonated mines on exiting a level
${this.ammoPack.toFixed(1)} mines per ${powerUps.orb.ammo()}` + }, + ammo: 0, + ammoPack: 0.77, + defaultAmmoPack: 0.77, + have: false, + nameString(suffix = "") { + if (tech.isFoamMine) { + return `foam` + } else if (tech.isSuperMine) { + return `super ball${suffix}` + } else { + return `nail${suffix}` + } + }, + do() { + if (!input.field && m.crouch && !tech.isLaserMine) { + const cycles = 60 //30 + const speed = 40 + const v = { + x: speed * Math.cos(m.angle), + y: speed * Math.sin(m.angle) + } //m.Vy / 2 + removed to make the path less jerky + ctx.strokeStyle = "rgba(68, 68, 68, 0.2)" //color.map + ctx.lineWidth = 2 + ctx.beginPath() + for (let i = 1.5, len = 19; i < len + 1; i++) { + const time = cycles * i / len + ctx.lineTo(m.pos.x + time * v.x, m.pos.y + time * v.y + 0.34 * time * time) + } + ctx.stroke() + } + }, + fire() { + if (m.crouch) { + if (tech.isLaserMine) { + const speed = 30 + const velocity = { + x: speed * Math.cos(m.angle), + y: speed * Math.sin(m.angle) + } + b.laserMine(m.pos, velocity) + m.fireCDcycle = m.cycle + Math.floor(65 * b.fireCDscale); // cool down + } else { + const pos = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + } + let speed = 36 + if (Matter.Query.point(map, pos).length > 0) speed = -2 //don't launch if mine will spawn inside map + b.mine(pos, { x: speed * Math.cos(m.angle), y: speed * Math.sin(m.angle) }, 0) + m.fireCDcycle = m.cycle + Math.floor(55 * b.fireCDscale); // cool down + } + } else { + const pos = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + } + let speed = 23 + if (Matter.Query.point(map, pos).length > 0) speed = -2 //don't launch if mine will spawn inside map + b.mine(pos, { x: speed * Math.cos(m.angle), y: speed * Math.sin(m.angle) }, 0) + m.fireCDcycle = m.cycle + Math.floor(35 * b.fireCDscale); // cool down + } + } + }, + { + name: "laser", //11 + descriptionFunction() { + return `emit a beam of collimated coherent light
reflects off map, blocks, and mobs ${(tech.isWideLaser || tech.isPulseLaser) ? 0 : tech.laserReflections} times
costs ${(tech.laserDrain * 6000).toFixed(1)} energy per second and 0 ammo` + }, + ammo: 0, + ammoPack: Infinity, + defaultAmmoPack: Infinity, + have: false, + charge: 0, + isStuckOn: false, + angle: 0, + isInsideArc(angle) { + const mod = (a, n) => { + return a - Math.floor(a / n) * n + } + let diff = mod(angle - this.angle + Math.PI, 2 * Math.PI) - Math.PI + return Math.abs(diff) < this.arcRange + }, + arcRange: 0.78, //1.57, + lensDamage: 1, + lensDamageOn: 0, //set in tech + lens() { + this.stuckOn(); + this.angle += 0.03 + if (this.isInsideArc(m.angle)) { + this.lensDamage = this.lensDamageOn + ctx.lineWidth = 6 + this.lensDamageOn + } else { + this.lensDamage = 1 + ctx.lineWidth = 2 + } + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 60, this.angle - this.arcRange, this.angle + this.arcRange); + ctx.strokeStyle = '#fff' //'rgba(255,255,255,0.9)' //'hsl(189, 100%, 95%)' + ctx.stroke(); + }, + stuckOn() { + if (tech.isStuckOn) { + if (this.isStuckOn) { + if (!input.fire) this.fire(); + if (m.energy < tech.laserDrain + 0.06) this.isStuckOn = false + } else if (input.fire) { + this.isStuckOn = true + } + // console.log(this.isStuckOn) + } + }, + do() { }, + fire() { }, + chooseFireMethod() { + this.lensDamage = 1 + if (tech.isLaserLens) { + this.do = this.lens + } else { + this.do = this.stuckOn + } + if (tech.isPulseLaser) { + this.fire = () => { + const drain = Math.min(0.9 * m.maxEnergy, 0.01 * (tech.isCapacitor ? 10 : 1) / b.fireCDscale) + if (m.energy > drain && this.charge < 50 * m.maxEnergy) { + m.energy -= drain + this.charge += drain * 100 + } + } + if (tech.historyLaser) { + const len = 1 + tech.historyLaser + const spacing = Math.ceil(30 - 2 * tech.historyLaser) + this.do = () => { + if (tech.isLaserLens) this.lens() + if (this.charge > 0) { + //draw charge level + const mag = 4.1 * Math.sqrt(this.charge) + ctx.beginPath(); + for (let i = 0; i < len; i++) { + const history = m.history[(m.cycle - i * spacing) % 600] + const off = history.yOff - 24.2859 + ctx.moveTo(history.position.x, history.position.y - off); + ctx.ellipse(history.position.x, history.position.y - off, mag, mag * 0.65, history.angle, 0, 2 * Math.PI) + } + ctx.fillStyle = `rgba(255,0,0,${0.09 * Math.sqrt(this.charge)})`; + ctx.fill(); + //fire + if (!input.fire) { + if (this.charge > 5) { + m.fireCDcycle = m.cycle + Math.floor(35 * b.fireCDscale); // cool down + for (let i = 0; i < len; i++) { + const history = m.history[(m.cycle - i * spacing) % 600] + const off = history.yOff - 24.2859 + b.pulse(1.65 * this.charge * this.lensDamage, history.angle, { + x: history.position.x, + y: history.position.y - off + }) + } + } + this.charge = 0; + } + } + }; + } else { + this.do = () => { + if (tech.isLaserLens) this.lens() + if (this.charge > 0) { + //draw charge level + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 4.2 * Math.sqrt(this.charge), 0, 2 * Math.PI); + // ctx.fillStyle = `rgba(255,0,0,${0.09 * Math.sqrt(this.charge)})`; + ctx.fillStyle = `rgba(255,0,0,${0.09 * Math.sqrt(this.charge)})`; + ctx.fill(); + //fire + if (!input.fire) { + if (this.charge > 5) { + m.fireCDcycle = m.cycle + Math.floor(35 * b.fireCDscale); // cool down + if (tech.beamSplitter) { + const divergence = m.crouch ? 0.15 : 0.35 + const angle = m.angle - tech.beamSplitter * divergence / 2 + for (let i = 0; i < 1 + tech.beamSplitter; i++) b.pulse(this.charge, angle + i * divergence) + } else { + b.pulse(1.8 * this.charge * this.lensDamage, m.angle) + } + } + this.charge = 0; + } + } + }; + } + + } else if (tech.beamSplitter) { + this.fire = this.fireSplit + } else if (tech.historyLaser) { + this.fire = this.fireHistory + } else if (tech.isWideLaser) { + this.fire = this.fireWideBeam + } else { + this.fire = this.fireLaser + } + // this.fire = this.firePhoton + }, + fireLaser() { + const drain = tech.laserDrain / b.fireCDscale + if (m.energy < drain) { + m.fireCDcycle = m.cycle + 100; // cool down if out of energy + } else { + m.fireCDcycle = m.cycle + m.energy -= drain + const where = { x: m.pos.x + 20 * Math.cos(m.angle), y: m.pos.y + 20 * Math.sin(m.angle) } + b.laser(where, { + x: where.x + 3000 * Math.cos(m.angle), + y: where.y + 3000 * Math.sin(m.angle) + }, tech.laserDamage / b.fireCDscale * this.lensDamage); + } + }, + firePulse() { }, + fireSplit() { + const drain = tech.laserDrain / b.fireCDscale + if (m.energy < drain) { + m.fireCDcycle = m.cycle + 100; // cool down if out of energy + } else { + m.fireCDcycle = m.cycle + m.energy -= drain + // const divergence = m.crouch ? 0.15 : 0.2 + // const scale = Math.pow(0.9, tech.beamSplitter) + // const pushScale = scale * scale + let dmg = tech.laserDamage / b.fireCDscale * this.lensDamage // * scale //Math.pow(0.9, tech.laserDamage) + const where = { x: m.pos.x + 20 * Math.cos(m.angle), y: m.pos.y + 20 * Math.sin(m.angle) } + const divergence = m.crouch ? 0.15 : 0.35 + const angle = m.angle - tech.beamSplitter * divergence / 2 + for (let i = 0; i < 1 + tech.beamSplitter; i++) { + b.laser(where, { + x: where.x + 3000 * Math.cos(angle + i * divergence), + y: where.y + 3000 * Math.sin(angle + i * divergence) + }, dmg, tech.laserReflections, false) + } + } + }, + fireWideBeam() { + const drain = tech.laserDrain / b.fireCDscale + if (m.energy < drain) { + m.fireCDcycle = m.cycle + 100; // cool down if out of energy + } else { + m.fireCDcycle = m.cycle + m.energy -= drain + const range = { + x: 5000 * Math.cos(m.angle), + y: 5000 * Math.sin(m.angle) + } + const rangeOffPlus = { + x: 7.5 * Math.cos(m.angle + Math.PI / 2), + y: 7.5 * Math.sin(m.angle + Math.PI / 2) + } + const rangeOffMinus = { + x: 7.5 * Math.cos(m.angle - Math.PI / 2), + y: 7.5 * Math.sin(m.angle - Math.PI / 2) + } + const dmg = 0.70 * tech.laserDamage / b.fireCDscale * this.lensDamage // 3.5 * 0.55 = 200% more damage + const where = { + x: m.pos.x + 30 * Math.cos(m.angle), + y: m.pos.y + 30 * Math.sin(m.angle) + } + const eye = { + x: m.pos.x + 15 * Math.cos(m.angle), + y: m.pos.y + 15 * Math.sin(m.angle) + } + ctx.strokeStyle = tech.laserColor; + ctx.lineWidth = 8 + ctx.globalAlpha = 0.5; + ctx.beginPath(); + if (Matter.Query.ray(map, eye, where).length === 0 && Matter.Query.ray(body, eye, where).length === 0) { + b.laser(eye, { + x: eye.x + range.x, + y: eye.y + range.y + }, dmg, 0, true, 0.3) + } + for (let i = 1; i < tech.wideLaser; i++) { + let whereOff = Vector.add(where, { + x: i * rangeOffPlus.x, + y: i * rangeOffPlus.y + }) + if (Matter.Query.ray(map, eye, whereOff).length === 0 && Matter.Query.ray(body, eye, whereOff).length === 0) { + ctx.moveTo(eye.x, eye.y) + ctx.lineTo(whereOff.x, whereOff.y) + b.laser(whereOff, { + x: whereOff.x + range.x, + y: whereOff.y + range.y + }, dmg, 0, true, 0.3) + } + whereOff = Vector.add(where, { + x: i * rangeOffMinus.x, + y: i * rangeOffMinus.y + }) + if (Matter.Query.ray(map, eye, whereOff).length === 0 && Matter.Query.ray(body, eye, whereOff).length === 0) { + ctx.moveTo(eye.x, eye.y) + ctx.lineTo(whereOff.x, whereOff.y) + b.laser(whereOff, { + x: whereOff.x + range.x, + y: whereOff.y + range.y + }, dmg, 0, true, 0.3) + } + } + ctx.stroke(); + if (tech.isLaserLens && b.guns[11].lensDamage !== 1) { + ctx.lineWidth = 20 + 3 * b.guns[11].lensDamageOn + ctx.globalAlpha = 0.3 + ctx.stroke(); + } + ctx.globalAlpha = 1; + } + }, + fireHistory() { + drain = tech.laserDrain / b.fireCDscale + if (m.energy < drain) { + m.fireCDcycle = m.cycle + 100; // cool down if out of energy + } else { + m.fireCDcycle = m.cycle + m.energy -= drain + const dmg = tech.laserDamage / b.fireCDscale * this.lensDamage + const spacing = Math.ceil(23 - tech.historyLaser) + ctx.beginPath(); + b.laser({ + x: m.pos.x + 20 * Math.cos(m.angle), + y: m.pos.y + 20 * Math.sin(m.angle) + }, { + x: m.pos.x + 3000 * Math.cos(m.angle), + y: m.pos.y + 3000 * Math.sin(m.angle) + }, dmg); + + for (let i = 1, len = 1 + tech.historyLaser; i < len; i++) { + const history = m.history[(m.cycle - i * spacing) % 600] + const off = history.yOff - 24.2859 + 2 * i + // ctx.globalAlpha = 0.13 + b.laser({ + x: history.position.x + 20 * Math.cos(history.angle), + y: history.position.y + 20 * Math.sin(history.angle) - off + }, { + x: history.position.x + 3000 * Math.cos(history.angle), + y: history.position.y + 3000 * Math.sin(history.angle) - off + }, 0.7 * dmg, tech.laserReflections, true); + } + // ctx.globalAlpha = 1 + ctx.strokeStyle = tech.laserColor; + ctx.lineWidth = 1 + ctx.stroke(); + if (tech.isLaserLens && b.guns[11].lensDamage !== 1) { + ctx.strokeStyle = tech.laserColor; + ctx.lineWidth = 10 + 2 * b.guns[11].lensDamageOn + ctx.globalAlpha = 0.2 + ctx.stroke(); //glow + ctx.globalAlpha = 1; + } + } + }, + }, + ], +}; \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/engine.js b/WebGames-master/WebGames-master/n-gon-master/js/engine.js new file mode 100644 index 00000000..dc9b6e3d --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/engine.js @@ -0,0 +1,290 @@ +//matter.js *********************************************************** +// module aliases +const Engine = Matter.Engine, + Events = Matter.Events, + Composites = Matter.Composites, + Composite = Matter.Composite, + Constraint = Matter.Constraint, + Vertices = Matter.Vertices, + Query = Matter.Query, + Body = Matter.Body, + Bodies = Matter.Bodies, + Vector = Matter.Vector; + +// create an engine +const engine = Engine.create(); +engine.world.gravity.scale = 0; //turn off gravity (it's added back in later) +// engine.velocityIterations = 100 +// engine.positionIterations = 100 +// engine.enableSleeping = true + +// matter events +function playerOnGroundCheck(event) { + //runs on collisions events + function enter() { + m.numTouching++; + if (!m.onGround) { + m.onGround = true; + if (m.crouch) { + if (m.checkHeadClear()) { + m.undoCrouch(); + } else { + m.yOffGoal = m.yOffWhen.crouch; + } + } else { + //sets a hard land where player stays in a crouch for a bit and can't jump + //crouch is forced in groundControl below + const momentum = player.velocity.y * player.mass //player mass is 5 so this triggers at 26 down velocity, unless the player is holding something + if (momentum > m.hardLanding) { + m.doCrouch(); + m.yOff = m.yOffWhen.jump; + m.hardLandCD = m.cycle + m.hardLandCDScale * Math.min(momentum / 6.5 - 6, 40) + //falling damage + if (tech.isFallingDamage && m.immuneCycle < m.cycle && momentum > 150) { + m.damage(Math.min(Math.sqrt(momentum - 133) * 0.01, 0.25)); + if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + } + } else { + m.yOffGoal = m.yOffWhen.stand; + } + } + } + } + + const pairs = event.pairs; + for (let i = 0, j = pairs.length; i != j; ++i) { + let pair = pairs[i]; + if (pair.bodyA === jumpSensor) { + m.standingOn = pair.bodyB; //keeping track to correctly provide recoil on jump + if (m.standingOn.alive !== true || m.immuneCycle > m.cycle) enter(); + } else if (pair.bodyB === jumpSensor) { + m.standingOn = pair.bodyA; //keeping track to correctly provide recoil on jump + if (m.standingOn.alive !== true || m.immuneCycle > m.cycle) enter(); + } + } + m.numTouching = 0; +} + +function playerOffGroundCheck(event) { + //runs on collisions events + const pairs = event.pairs; + for (let i = 0, j = pairs.length; i != j; ++i) { + if (pairs[i].bodyA === jumpSensor || pairs[i].bodyB === jumpSensor) { + if (m.onGround && m.numTouching === 0) { + m.onGround = false; + m.lastOnGroundCycle = m.cycle; + m.hardLandCD = 0 // disable hard landing + if (m.checkHeadClear()) { + if (m.crouch) { + m.undoCrouch(); + } + m.yOffGoal = m.yOffWhen.jump; + } + } + } + } +} + +function collisionChecks(event) { + const pairs = event.pairs; + for (let i = 0, j = pairs.length; i != j; i++) { + //mob + (player,bullet,body) collisions + for (let k = 0; k < mob.length; k++) { + if (mob[k].alive) { + if (pairs[i].bodyA === mob[k]) { + collideMob(pairs[i].bodyB); + break; + } else if (pairs[i].bodyB === mob[k]) { + collideMob(pairs[i].bodyA); + break; + } + + function collideMob(obj) { + //player + mob collision + if ( + m.immuneCycle < m.cycle && + (obj === playerBody || obj === playerHead) && + !mob[k].isSlowed && !mob[k].isStunned + ) { + let dmg = Math.min(Math.max(0.025 * Math.sqrt(mob[k].mass), 0.05), 0.3) * simulation.dmgScale; //player damage is capped at 0.3*dmgScale of 1.0 + // if (m.isCloak) dmg *= 0.5 + mob[k].foundPlayer(); + if (tech.isRewindAvoidDeath && m.energy > 0.85 * Math.min(1, m.maxEnergy) && dmg > 0.01) { //CPT reversal runs in m.damage, but it stops the rest of the collision code here too + m.damage(dmg); + return + } + m.damage(dmg); //normal damage + + if (tech.isCollisionRealitySwitch && m.alive) { + m.switchWorlds("Hilbert space") + simulation.trails(90) + simulation.inGameConsole(`simulation.amplitude = ${Math.random()}`); + } + if (tech.isPiezo) m.energy += 20.48 * level.isReducedRegen; + if (tech.isCouplingNoHit && m.coupling > 0) { + m.couplingChange(-3) + + const unit = Vector.rotate({ x: 1, y: 0 }, 6.28 * Math.random()) + let where = Vector.add(m.pos, Vector.mult(unit, 17)) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 22, + color: 'rgba(0, 171, 238, 0.33)', + time: 8 + }); + where = Vector.add(m.pos, Vector.mult(unit, 60)) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 18, + color: 'rgba(0, 171, 238, 0.5)', + time: 16 + }); + where = Vector.add(m.pos, Vector.mult(unit, 100)) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 14, + color: 'rgba(0, 171, 238, 0.6)', + time: 24 + }); + where = Vector.add(m.pos, Vector.mult(unit, 135)) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 10, + color: 'rgba(0, 171, 238, 0.7)', + time: 32 + }); + } + if (tech.isHarpoonDefense) { //fire harpoons at mobs after getting hit + const maxCount = 10 + 3 * tech.extraHarpoons //scale the number of hooks fired + let count = maxCount - 1 + const angle = Math.atan2(mob[k].position.y - player.position.y, mob[k].position.x - player.position.x); + const mass = 0.75 * ((tech.isLargeHarpoon) ? 1 + Math.min(0.05 * Math.sqrt(b.guns[9].ammo), 10) : 1) + b.harpoon(m.pos, mob[k], angle, mass, true, 7, false) // harpoon(where, target, angle = m.angle, harpoonSize = 1, isReturn = false, totalCycles = 35, isReturnAmmo = true, thrust = 0.1) { + bullet[bullet.length - 1].drain = 0 + for (; count > 0; count--) { + b.harpoon(m.pos, mob[k], angle + count * 2 * Math.PI / maxCount, mass, true, 7, false) + bullet[bullet.length - 1].drain = 0 + } + } + if (tech.isStimulatedEmission) powerUps.ejectTech() + if (mob[k].onHit) mob[k].onHit(); + if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + //extra kick between player and mob //this section would be better with forces but they don't work... + let angle = Math.atan2(player.position.y - mob[k].position.y, player.position.x - mob[k].position.x); + Matter.Body.setVelocity(player, { x: player.velocity.x + 8 * Math.cos(angle), y: player.velocity.y + 8 * Math.sin(angle) }); + Matter.Body.setVelocity(mob[k], { x: mob[k].velocity.x - 8 * Math.cos(angle), y: mob[k].velocity.y - 8 * Math.sin(angle) }); + if (tech.isAnnihilation && !mob[k].shield && !mob[k].isShielded && !mob[k].isBoss && mob[k].isDropPowerUp && m.energy > 0.1 && mob[k].damageReduction > 0) { + m.energy -= 0.1 //* Math.max(m.maxEnergy, m.energy) //0.33 * m.energy + if (m.immuneCycle === m.cycle + m.collisionImmuneCycles) m.immuneCycle = 0; //player doesn't go immune to collision damage + mob[k].death(); + simulation.drawList.push({ //add dmg to draw queue + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: Math.sqrt(dmg) * 500, + color: "rgba(255,0,255,0.2)", + time: simulation.drawTime + }); + } else { + simulation.drawList.push({ //add dmg to draw queue + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + } + // return; + // } + } else { + //mob + bullet collisions + if (obj.classType === "bullet" && obj.speed > obj.minDmgSpeed) { + obj.beforeDmg(mob[k]); //some bullets do actions when they hits things, like despawn //forces don't seem to work here + let dmg = m.dmgScale * (obj.dmg + 0.15 * obj.mass * Vector.magnitude(Vector.sub(mob[k].velocity, obj.velocity))) + if (tech.isCrit && mob[k].isStunned) dmg *= 4 + // console.log(dmg) //remove this + mob[k].damage(dmg); + if (mob[k].alive) mob[k].foundPlayer(); + if (mob[k].damageReduction) { + simulation.drawList.push({ //add dmg to draw queue + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: Math.log(dmg + 1.1) * 40 * mob[k].damageReduction + 3, + color: simulation.playerDmgColor, + time: simulation.drawTime + }); + } + if (tech.isLessDamageReduction && !mob[k].shield) mob[k].damageReduction *= mob[k].isBoss ? (mob[k].isFinalBoss ? 1.0005 : 1.0025) : 1.05 + return; + } + //mob + body collisions + if (obj.classType === "body" && obj.speed > 9) { + const v = Vector.magnitude(Vector.sub(mob[k].velocity, obj.velocity)); + if (v > 11) { + if (tech.blockDmg) { //electricity + Matter.Body.setVelocity(mob[k], { x: 0.5 * mob[k].velocity.x, y: 0.5 * mob[k].velocity.y }); + if (tech.isBlockRadiation && !mob[k].isShielded && !mob[k].isMobBullet) { + mobs.statusDoT(mob[k], tech.blockDmg * 0.42, 180) //200% increase -> x (1+2) //over 7s -> 360/30 = 12 half seconds -> 3/12 + } else { + mob[k].damage(tech.blockDmg * m.dmgScale) + simulation.drawList.push({ + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: 28 * mob[k].damageReduction + 3, + color: "rgba(255,0,255,0.8)", + time: 4 + }); + } + } + + let dmg = tech.blockDamage * m.dmgScale * v * obj.mass * (tech.isMobBlockFling ? 2.5 : 1) * (tech.isBlockRestitution ? 2.5 : 1) * ((m.fieldMode === 0 || m.fieldMode === 8) ? 1 + 0.05 * m.coupling : 1); + if (mob[k].isShielded) dmg *= 0.7 + + mob[k].damage(dmg, true); + if (tech.isBlockPowerUps && !mob[k].alive && mob[k].isDropPowerUp && Math.random() < 0.5) { + options = ["coupling", "boost", "heal", "research", "ammo"] + powerUps.spawn(mob[k].position.x, mob[k].position.y, options[Math.floor(Math.random() * options.length)]); + } + + const stunTime = dmg / Math.sqrt(obj.mass) + if (stunTime > 0.5 && mob[k].memory !== Infinity) mobs.statusStun(mob[k], 60 + 60 * Math.sqrt(stunTime)) + if (mob[k].alive && mob[k].distanceToPlayer2() < 1000000 && !m.isCloak) mob[k].foundPlayer(); + if (tech.fragments && obj.speed > 10 && !obj.hasFragmented) { + obj.hasFragmented = true; + b.targetedNail(obj.position, tech.fragments * 4) + } + if (mob[k].damageReduction) { + simulation.drawList.push({ + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: Math.log(dmg + 1.1) * 40 * mob[k].damageReduction + 3, + color: simulation.playerDmgColor, + time: simulation.drawTime + }); + } + return; + } + } + } + } + } + } + } +} + +//determine if player is on the ground +Events.on(engine, "collisionStart", function (event) { + playerOnGroundCheck(event); + // playerHeadCheck(event); + collisionChecks(event); +}); +Events.on(engine, "collisionActive", function (event) { + playerOnGroundCheck(event); + // playerHeadCheck(event); +}); +Events.on(engine, "collisionEnd", function (event) { + playerOffGroundCheck(event); +}); \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/index.js b/WebGames-master/WebGames-master/n-gon-master/js/index.js new file mode 100644 index 00000000..ec4aaa94 --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/index.js @@ -0,0 +1,2134 @@ +"use strict"; + +//convert text into numbers for seed +Math.hash = s => { + for (var i = 0, h = 9; i < s.length;) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9); + return h ^ h >>> 9 +} + +// const date1 = new Date() +// console.log(date1.getUTCHours()) +// document.getElementById("seed").placeholder = Math.initialSeed = String(date1.getUTCDate() * date1.getUTCFullYear()) // daily seed, day + year + +// document.getElementById("seed").placeholder = Math.initialSeed = Math.floor(Date.now() % 100000) //random every time: just the time in milliseconds UTC + +window.addEventListener('error', error => { + // simulation.inGameConsole(`ERROR: ${error.message} ${error.filename}:${error.lineno}`) + simulation.inGameConsole(`ERROR: ${(error.stack && error.stack.replace(/\n/g, "
")) || (error.message + ` ${error.filename}:${error.lineno}`)}`); + +}); + +document.getElementById("seed").placeholder = Math.initialSeed = String(Math.floor(Date.now() % 100000)) +Math.seed = Math.abs(Math.hash(Math.initialSeed)) //update randomizer seed in case the player changed it +Math.seededRandom = function (min = 0, max = 1) { // in order to work 'Math.seed' must NOT be undefined + Math.seed = (Math.seed * 9301 + 49297) % 233280; + return min + Math.seed / 233280 * (max - min); +} +//Math.seed is set to document.getElementById("seed").value in level.populate level at the start of runs +// console.log(Math.seed) + + +function shuffle(array) { + var currentIndex = array.length, + temporaryValue, + randomIndex; + // While there remain elements to shuffle... + while (0 !== currentIndex) { + // Pick a remaining element... + // randomIndex = Math.floor(Math.random() * currentIndex); + randomIndex = Math.floor(Math.seededRandom(0, currentIndex)) //Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + // And swap it with the current element. + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; + } + return array; +} +// function vertexCollision(v1, v1End, domain, best) { +// let results +// for (let i = 0; i < domain.length; ++i) { +// let vertices = domain[i].vertices; +// const len = vertices.length - 1; +// for (let j = 0; j < len; j++) { +// results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); +// if (results.onLine1 && results.onLine2) { +// const dx = v1.x - results.x; +// const dy = v1.y - results.y; +// const dist2 = dx * dx + dy * dy; +// if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) { +// best = { +// x: results.x, +// y: results.y, +// dist2: dist2, +// who: domain[i], +// v1: vertices[j], +// v2: vertices[j + 1] +// }; +// } +// } +// } +// results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); +// if (results.onLine1 && results.onLine2) { +// const dx = v1.x - results.x; +// const dy = v1.y - results.y; +// const dist2 = dx * dx + dy * dy; +// if (dist2 < best.dist2) { +// best = { +// x: results.x, +// y: results.y, +// dist2: dist2, +// who: domain[i], +// v1: vertices[0], +// v2: vertices[len] +// }; +// } +// } +// } +// return best +// } +//this function is used for finding the point where a ray hits things, used for lasers mostly +function vertexCollision(v1, v1End, domains) { //= [map, body, [playerBody, playerHead]] //m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]] + let results + let best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + for (let j = 0; j < domains.length; j++) { + let domain = domains[j] + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) { + best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[j], + v2: vertices[j + 1] + }; + } + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) { + best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[0], + v2: vertices[len] + }; + } + } + } + } + return best +} + +// prompts to reload and exit for JUNK tech named "beforeunload" +function beforeUnloadEventListener(event) { + event.preventDefault(); + if (tech.isExitPrompt) { + tech.damage *= 1.25 + // simulation.inGameConsole(`damage *= ${1.25}`) + simulation.inGameConsole(`tech.damage *= ${1.25} //beforeunload`); + if (Math.random() < 0.25) { + removeEventListener('beforeunload', beforeUnloadEventListener); + } + } +} +// addEventListener('beforeunload', beforeUnloadEventListener); + + +//collision groups +// cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet | cat.mobShield | cat.phased +const cat = { + player: 0x1, + map: 0x10, + body: 0x100, + bullet: 0x1000, + powerUp: 0x10000, + mob: 0x100000, + mobBullet: 0x1000000, + mobShield: 0x10000000, + phased: 0x100000000, +} + +let color = { //light + // background: "#ddd", // used instead: document.body.style.backgroundColor + block: "rgba(140,140,140,0.85)", + blockS: "#222", + map: "#444", + bullet: "#000" +} + +// const color = { //dark +// background: "#333", +// block: "#444", +// blockS: "#aab", +// map: "#556", +// bullet: "#fff" +// } + +// const color = { //dark +// background: "#999", +// block: "#888", +// blockS: "#111", +// map: "#444", +// } + +// shrink power up selection menu +// if (screen.height < 800) { +// document.getElementById("choose-grid").style.fontSize = "1em"; //1.3em is normal +// if (screen.height < 600) document.getElementById("choose-grid").style.fontSize = "0.8em"; //1.3em is normal +// } + + +//********************************************************************** +// check for URL parameters to load an experimental game +//********************************************************************** + +//example https://landgreen.github.io/n-gon/index.html? +// &gun1=minigun&gun2=laser +// &tech1=laser-bot&tech2=mass%20driver&tech3=overcharge&tech4=laser-bot&tech5=laser-bot&field=phase%20decoherence%20field&difficulty=2 +//add ? to end of url then for each power up add +// &gun1=name&gun2=name +// &tech1=laser-bot&tech2=mass%20driver&tech3=overcharge&tech4=laser-bot&tech5=laser-bot +// &field=phase%20decoherence%20field +// &difficulty=2 +//use %20 for spaces +//difficulty is 0 easy, 1 normal, 2 hard, 4 why +function getUrlVars() { + let vars = {}; + window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, k, v) { + vars[k] = v; + }); + return vars; +} +window.addEventListener('load', () => { + const set = getUrlVars() + if (Object.keys(set).length !== 0) { + // build.populateGrid() //trying to solve a bug with this, but maybe it doesn't help + openExperimentMenu(); + //add experimental selections based on url + for (const property in set) { + set[property] = set[property].replace(/%20/g, " ") + set[property] = set[property].replace(/%27/g, "'") + set[property] = set[property].replace(/%CE%A8/g, "Ψ") + if (property === "field") { + let found = false + let index + for (let i = 0; i < m.fieldUpgrades.length; i++) { + if (set[property] === m.fieldUpgrades[i].name) { + index = i; + found = true; + break; + } + } + if (found) build.choosePowerUp(index, 'field') + } + if (property.substring(0, 3) === "gun") { + let found = false + let index + for (let i = 0; i < b.guns.length; i++) { + if (set[property] === b.guns[i].name) { + index = i; + found = true; + break; + } + } + if (found) build.choosePowerUp(index, 'gun') + } + if (property.substring(0, 4) === "tech") { + for (let i = 0; i < tech.tech.length; i++) { + if (set[property] === tech.tech[i].name) { + build.choosePowerUp(i, 'tech', true) + break; + } + } + } + + // if (property === "difficulty") { + // simulation.difficultyMode = Number(set[property]) + // lore.setTechGoal() + // document.getElementById("difficulty-select-experiment").value = Number(set[property]) + // } + if (property === "molMode") { + simulation.molecularMode = Number(set[property]) + const i = 4 //update experiment text + m.fieldUpgrades[i].description = m.fieldUpgrades[i].setDescription() + document.getElementById(`field-${i}`).innerHTML = `
+
  ${build.nameLink(m.fieldUpgrades[i].name)}
+ ${m.fieldUpgrades[i].description}
` + } + // if (property === "seed") { + // document.getElementById("seed").placeholder = Math.initialSeed = String(set[property]) + // Math.seed = Math.abs(Math.hash(Math.initialSeed)) + // level.populateLevels() + // } + requestAnimationFrame(() => { build.sortTech('have', true) }); + + } + } else if (localSettings.isTrainingNotAttempted && localSettings.runCount < 30) { //make training button more obvious for new players + // document.getElementById("training-button").style.border = "0px #333 solid"; + // document.getElementById("training-button").style.fill = "rgb(0, 150, 235)" //"#fff"; + // document.getElementById("training-button").style.background = "rgb(0, 200, 255)"; + + //css classes not working for some reason + // document.getElementById("training-button").classList.add('lore-text'); + + let myanim = document.createElementNS("http://www.w3.org/2000/svg", 'animate'); + myanim.setAttribute("id", "myAnimation"); + myanim.setAttribute("attributeType", "XML"); + myanim.setAttribute("attributeName", "fill"); + // myanim.setAttribute("values", "#f55;#cc5;#5c5;#5dd;#66f;#5dd;#5c5;#cc5;#f55"); //rainbow + myanim.setAttribute("values", "#5dd;#66f;#5dd"); + // myanim.setAttribute("values", "#333;rgb(0, 170, 255);#333"); + myanim.setAttribute("dur", "3s"); + myanim.setAttribute("repeatCount", "indefinite"); + document.getElementById("training-button").appendChild(myanim); + document.getElementById("myAnimation").beginElement(); + } +}); + + +//********************************************************************** +//set up canvas +//********************************************************************** +const canvas = document.getElementById("canvas"); +//using "const" causes problems in safari when an ID shares the same name. +const ctx = canvas.getContext("2d"); +// const ctx = canvas.getContext('2d', { alpha: false }); //optimization, this works if you wipe with the background color of each level + +document.body.style.backgroundColor = "#fff"; + +//disable pop up menu on right click +document.oncontextmenu = function () { + return false; +} + +function setupCanvas() { + canvas.width = window.innerWidth; + canvas.height = window.innerHeight; + canvas.width2 = canvas.width / 2; //precalculated because I use this often (in mouse look) + canvas.height2 = canvas.height / 2; + ctx.font = "25px Arial"; + ctx.lineJoin = "round"; + ctx.lineCap = "round"; + simulation.setZoom(); + + if (simulation.isInvertedVertical) { + ctx.translate(0, canvas.height); // Move the origin down to the bottom + ctx.scale(1, -1); // Flip vertically + } +} +setupCanvas(); +window.onresize = () => { + setupCanvas(); +}; + +//********************************************************************** +// experimental build grid display and pause +//********************************************************************** +//set wikipedia link +for (let i = 0, len = tech.tech.length; i < len; i++) { + if (!tech.tech[i].link) tech.tech[i].link = `${tech.tech[i].name}` +} +const build = { + pixelDraw() { + let count = 0 + let imgData = ctx.getImageData(0, 0, canvas.width, canvas.height); + let data = imgData.data; + + function loop() { + count++ + if (!(count % 2)) { + for (let y = 0; y < canvas.height; ++y) { + for (let x = 0; x < canvas.width; x += 1) { + const index = (y * canvas.width + x) * 4; + // let mag = 0; + // for (let j = 0, len = who.length; j < len; j++) { + // const dx = who[j].position.x - x; + // const dy = who[j].position.y - y; + // mag -= who[j].charge / (Math.sqrt(dx * dx + dy * dy) + 1); + // } + + //get dark + // data[index + 0] *= 0.96 + // data[index + 1] *= 0.96 + // data[index + 2] *= 0.96 + // data[index + 3] -= 1; // alpha + + //invert + data[index + 0] = 255 - data[index + 0] // red + data[index + 1] = 255 - data[index + 1] // green + data[index + 2] = 255 - data[index + 2] // blue + } + } + + // fade alpha for all pixels + // for (let i = 0; i < data.length; i += 4) { + // if (data[i + 3] > 0) { + // data[i + 3]--; + // } + // } + + //add random speckles + // for (let i = 0, len = Math.floor(data.length / 15000); i < len; ++i) { + // const index = Math.floor((Math.random() * data.length) / 4) * 4; + // data[index + 0] = 255; // red + // data[index + 1] = 255; // green + // data[index + 2] = 255; // blue + // data[index + 3] = Math.floor(Math.random() * Math.random() * 155); // alpha + // } + + // ctx.putImageData(imgData, 0, 1); //pixels fall because of the 1 in third parameter + ctx.putImageData(imgData, 0, 0); + } + if (simulation.paused && m.alive) requestAnimationFrame(loop); + } + requestAnimationFrame(loop); + }, + showImages(from) { //on click event: from all 3 different places to hide / show images + localSettings.isHideImages = !localSettings.isHideImages + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + if (from === 'experiment') { + build.reset(); + } else if (from === 'pause') { + build.unPauseGrid() + build.pauseGrid() //redraw pause text with images + } + if (localSettings.isHideImages) { + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + } else { + document.getElementById("choose-grid").classList.add('choose-grid'); + document.getElementById("choose-grid").classList.remove('choose-grid-no-images'); + } + document.getElementById("hide-images").checked = localSettings.isHideImages + // console.log(localSettings.isHideImages, from) + }, + hideHUD() { + if (simulation.isTraining) { + localSettings.isHideHUD = false + } else { + localSettings.isHideHUD = !localSettings.isHideHUD + } + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + document.getElementById("hide-hud").checked = localSettings.isHideHUD + document.getElementById("hide-hud").classList.toggle("ticked") + simulation.removeEphemera("dmgDefBars") + if (!localSettings.isHideHUD) { + simulation.ephemera.push({ + name: "dmgDefBars", count: 0, do() { + if (!(m.cycle % 15)) { //4 times a second + const defense = m.defense() //update defense bar + if (m.lastCalculatedDefense !== defense) { + document.getElementById("defense-bar").style.width = Math.floor(300 * m.maxHealth * (1 - defense)) + "px"; + m.lastCalculatedDefense = defense + } + const damage = tech.damageFromTech() //update damage bar + if (m.lastCalculatedDamage !== damage) { + document.getElementById("damage-bar").style.height = Math.floor((Math.atan(0.25 * damage - 0.25) + 0.25) * 0.53 * canvas.height) + "px"; + m.lastCalculatedDamage = damage + } + } + }, + }) + } + }, + pauseGrid() { + build.generatePauseLeft() //makes the left side of the pause menu with the tech + build.generatePauseRight() //makes the right side of the pause menu with the tech + // build.sortTech('') //sorts tech into the order the player got them using tech.tech[i].cycle = m.cycle + document.getElementById("right-HUD").style.display = "none" + document.getElementById("guns").style.display = "none" + document.getElementById("field").style.display = "none" + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + document.getElementById("defense-bar").style.display = "none" + document.getElementById("damage-bar").style.display = "none" + //show in game console + simulation.lastLogTime = m.cycle //hide in game console + }, + generatePauseLeft() { + //left side + let botText = "" + if (tech.nailBotCount) botText += `
nail-bots ${tech.nailBotCount}` + if (tech.orbitBotCount) botText += `
orbital-bots ${tech.orbitBotCount}` + if (tech.boomBotCount) botText += `
boom-bots ${tech.boomBotCount}` + if (tech.laserBotCount) botText += `
laser-bots ${tech.laserBotCount}` + if (tech.foamBotCount) botText += `
foam-bots ${tech.foamBotCount}` + if (tech.soundBotCount) botText += `
sound-bots ${tech.soundBotCount}` + if (tech.dynamoBotCount) botText += `
dynamo-bots ${tech.dynamoBotCount}` + if (tech.plasmaBotCount) botText += `
plasma-bots ${tech.plasmaBotCount}` + if (tech.missileBotCount) botText += `
missile-bots ${tech.missileBotCount}` + + // ${b.activeGun === null || b.activeGun === undefined ? "undefined" : b.guns[b.activeGun].name} (${b.activeGun === null || b.activeGun === undefined ? "0" : b.guns[b.activeGun].ammo}) + + //
+ // + // + + let text = `
+PAUSED +press ${input.key.pause} to resume +
+ + + +
+ +
+
+simulation variables +
+damage ${((tech.damageFromTech())).toPrecision(4)}x +level ${((m.dmgScale)).toPrecision(4)}x +
damage taken ${(m.defense()).toPrecision(4)}x +level ${(simulation.dmgScale).toPrecision(4)}x +
health (${(m.health * 100).toFixed(0)} / ${(m.maxHealth * 100).toFixed(0)}) +${powerUps.research.count} ${powerUps.orb.research()} +
energy (${(m.energy * 100).toFixed(0)} / ${(m.maxEnergy * 100).toFixed(0)}) + (${(m.fieldRegen * 6000 * level.isReducedRegen).toFixed(0)}/s) +${tech.totalCount} ${powerUps.orb.tech()} +
fire rate ${(1 / b.fireCDscale).toFixed(2)}x +mass ${player.mass.toFixed(1)} +${m.coupling ? `
` + m.couplingDescription(m.coupling) + ` from ${(m.coupling).toFixed(0)} ${powerUps.orb.coupling(1)}` : ""} +
duplication ${(tech.duplicationChance() * 100).toFixed(0)}% +JUNK ${(100 * (tech.junkChance + level.junkAdded)).toFixed(0)}% +${botText} +
+
${level.levelAnnounce()} +position (${player.position.x.toFixed(0)}, ${player.position.y.toFixed(0)}) +
seed ${Math.initialSeed} +mouse (${simulation.mouseInGame.x.toFixed(0)}, ${simulation.mouseInGame.y.toFixed(0)}) +
cycles ${m.cycle} +velocity (${player.velocity.x.toFixed(2)}, ${player.velocity.y.toFixed(2)}) +
mobs ${mob.length} (${spawn.pickList[0]}, ${spawn.pickList[1]}) +blocks ${body.length} +
bullets ${bullet.length} +power ups ${powerUp.length} + +${simulation.isCheating ? "

lore disabled" : ""} +
+
+
` + text += `
+
+difficulty parameters +
+ ${simulation.difficultyMode > 0 ? `
0.85x damage per level
1.25x damage taken per level
` : " "} + ${simulation.difficultyMode > 1 ? `
spawn more mobs
mobs move faster
` : " "} + ${simulation.difficultyMode > 2 ? `
spawn a 2nd boss each level
bosses spawn 0.5x power ups
` : " "} + ${simulation.difficultyMode > 3 ? `
0.85x damage per level
1.25x damage taken per level
` : " "} + ${simulation.difficultyMode > 4 ? `
+1 random constraint each level
fewer initial power ups
` : " "} + ${simulation.difficultyMode > 5 ? `
0.5x initial damage
2x initial damage taken
` : " "} + ${simulation.difficultyMode > 6 ? `
+1 random constraint each level
fewer ${powerUps.orb.tech()} spawn
` : " "} +
+
+${simulation.difficultyMode > 4 ? `
active constraints
${level.constraintDescription1}
${level.constraintDescription2}
` : ""} +
` + if (!localSettings.isHideHUD) text += `
+
+console log +
+
${document.getElementById("text-log").innerHTML}
+
+
+
` + if ((tech.isPauseSwitchField || simulation.testing)) { //&& !simulation.isChoosing + // const fieldNameP = m.fieldUpgrades[m.fieldMode > 1 ? m.fieldMode - 1 : m.fieldUpgrades.length - 1].name + // const fieldNameN = m.fieldUpgrades[m.fieldMode === m.fieldUpgrades.length - 2 ? 1 : m.fieldMode + 1].name + //button above for previous + text += `
+
↑
↑
` + //button for current + const style = localSettings.isHideImages ? `style="height:auto;"` : `style="background-image: url('img/field/${m.fieldUpgrades[m.fieldMode].name}${m.fieldMode === 0 ? m.fieldUpgrades[0].imageNumber : ""}.webp');"` + text += `
+
+
  ${build.nameLink(m.fieldUpgrades[m.fieldMode].name)}
+ ${m.fieldUpgrades[m.fieldMode].description}
` + //button below for next + text += `
+
↓
↓
` + + + } else { + const style = localSettings.isHideImages ? `style="height:auto;"` : `style="background-image: url('img/field/${m.fieldUpgrades[m.fieldMode].name}${m.fieldMode === 0 ? m.fieldUpgrades[0].imageNumber : ""}.webp');"` + text += `
+
+
  ${build.nameLink(m.fieldUpgrades[m.fieldMode].name)}
+ ${m.fieldUpgrades[m.fieldMode].description}
` + } + // for (let i = 0, len = b.inventory.length; i < len; i++) { + // text += `
  ${build.nameLink(b.guns[b.inventory[i]].name)} - ${b.guns[b.inventory[i]].ammo}
${b.guns[b.inventory[i]].description}
` + // } + for (let i = 0, len = b.inventory.length; i < len; i++) { + const style = localSettings.isHideImages ? `style="height:auto;"` : `style="background-image: url('img/gun/${b.guns[b.inventory[i]].name}.webp');"` + text += `
+
+
  ${build.nameLink(b.guns[b.inventory[i]].name)} - ${b.guns[b.inventory[i]].ammo}
+ ${b.guns[b.inventory[i]].descriptionFunction()}
` + } + let el = document.getElementById("pause-grid-left") + el.style.display = "grid" + el.innerHTML = text + requestAnimationFrame(() => { + if (localSettings.isAllowed) { + document.getElementById("simulation-variables-details").open = localSettings.pauseMenuDetailsOpen[0] + document.getElementById("difficulty-parameters-details").open = localSettings.pauseMenuDetailsOpen[1] + document.getElementById("console-log-details").open = localSettings.pauseMenuDetailsOpen[2] + if (document.getElementById("constraints-details")) document.getElementById("constraints-details").open = localSettings.pauseMenuDetailsOpen[3] + } + }); + }, + generatePauseRight() { + let text = `
+ + + + + + + + +
`; + const ejectClass = (tech.isPauseEjectTech && !simulation.isChoosing) ? 'pause-eject' : '' + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].count > 0) { + const style = (localSettings.isHideImages || tech.tech[i].isJunk || tech.tech[i].isLore) ? `style="height:auto;"` : `style = "background-image: url('img/${tech.tech[i].name}.webp');"` + const techCountText = tech.tech[i].count > 1 ? `(${tech.tech[i].count}x)` : ""; + if (tech.tech[i].isInstant) { + // text += `
${tech.tech[i].link} ${techCountText}
${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + } else if (tech.tech[i].isFieldTech) { + text += `
` + text += build.fieldTechText(i) + "
" + } else if (tech.tech[i].isGunTech) { + text += `
` + text += build.gunTechText(i) + "
" + } else if (tech.tech[i].isSkin) { + text += `
` + text += build.skinTechText(i) + "
" + } else if (tech.tech[i].isJunk) { + text += `
` + text += build.junkTechText(i) + "
" + } else { + text += `
` + text += build.techText(i) + "
" + } + } else if (tech.tech[i].isLost) { + text += `
${tech.tech[i].link}
${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + } + } + const el = document.getElementById("pause-grid-right") + el.style.display = "grid" + el.innerHTML = text + + //add event listener for pressing enter key when in sort + function pressEnterSort(event) { + if (event.key === 'Enter') { + requestAnimationFrame(() => { document.getElementById("sort-input").focus(); }); + // event.preventDefault(); // Prevent the default action to avoid form submission or any other default action + build.sortTech('input') + } + } + document.getElementById("sort-input").addEventListener('keydown', pressEnterSort); + // requestAnimationFrame(() => { document.getElementById("sort-input").focus(); }); + }, + sortTech(find, isExperiment = false) { + const sortKeyword = (a, b) => { + let aHasKeyword = (a.descriptionFunction ? a.descriptionFunction() : a.description).includes(find) || a.name.includes(find) + let bHasKeyword = (b.descriptionFunction ? b.descriptionFunction() : b.description).includes(find) || b.name.includes(find) + if ((aHasKeyword) && !bHasKeyword) return -1; + if (!aHasKeyword && bHasKeyword) return 1; + return 0; + } + + // if (find === '') { + // tech.tech.sort((a, b) => { //sorts tech into the order the player got them using tech.tech[i].cycle = m.cycle + // console.log(a.cycle, b.cycle) + // if (a.cycle === undefined && b.cycle !== undefined) return -1; + // if (a.cycle !== undefined && b.cycle === undefined) return 1; + // if (a.cycle === undefined && b.cycle === undefined) return 0; + // if (a.cycle !== b.cycle) return a.cycle - b.cycle; + // }); + // } else + if (find === 'guntech') { + tech.tech.sort((a, b) => { + if (a.isGunTech && b.isGunTech) { + return (a.allowed() === b.allowed()) ? 0 : a.allowed() ? -1 : 1; + } + if (a.isGunTech && !b.isGunTech) return -1; //sort to the top + if (!a.isGunTech && b.isGunTech) return 1; //sort to the bottom + return 0; + }); + } else if (find === 'fieldtech') { + tech.tech.sort((a, b) => { + if (a.isFieldTech && b.isFieldTech) { + return (a.allowed() === b.allowed()) ? 0 : a.allowed() ? -1 : 1; + } + if (a.isFieldTech && !b.isFieldTech) return -1; //sort to the top + if (!a.isFieldTech && b.isFieldTech) return 1; //sort to the bottom + return 0; + }); + } else if (find === 'allowed') { + // tech.tech.sort((a, b) => { + // if (a.allowed() > !b.allowed()) return -1; //sort to the top + // if (!a.allowed() < b.allowed()) return 1; //sort to the bottom + // return 0; + // }); + tech.tech.sort((a, b) => { + return (a.allowed() === b.allowed()) ? 0 : a.allowed() ? -1 : 1; + }); + } else if (find === 'have') { + tech.tech.sort((a, b) => { + return (a.allowed() === b.allowed()) ? 0 : a.allowed() ? -1 : 1; + return 0; + }); + } else if (find === 'heal') { + tech.tech.sort((a, b) => { + if (a.isHealTech && b.isHealTech) { + return (a.allowed() === b.allowed()) ? 0 : a.allowed() ? -1 : 1; + } + if (a.isHealTech && !b.isHealTech) return -1; //sort to the top + if (!a.isHealTech && b.isHealTech) return 1; //sort to the bottom + return 0; + }); + } else if (find === 'bot') { + tech.tech.sort((a, b) => { + if (a.isBotTech && b.isBotTech) { + return (a.allowed() === b.allowed()) ? 0 : a.allowed() ? -1 : 1; + } + if (a.isBotTech && !b.isBotTech) return -1; //sort to the top + if (!a.isBotTech && b.isBotTech) return 1; //sort to the bottom + return 0; + }); + } else if (document.getElementById("sort-input").value === 'skin') { + tech.tech.sort((a, b) => { + if (a.isSkin && b.isSkin) { + return (a.allowed() === b.allowed()) ? 0 : a.allowed() ? -1 : 1; + } + if (a.isSkin && !b.isSkin) return -1; //sort to the top + if (!a.isSkin && b.isSkin) return 1; //sort to the bottom + return 0; + }); + } else if (document.getElementById("sort-input").value === 'junk') { + tech.tech.sort((a, b) => { + if (a.isJunk && !b.isJunk) return -1; //sort to the top + if (!a.isJunk && b.isJunk) return 1; //sort to the bottom + return 0; + }); + } else if (find === 'damage') { + tech.tech.sort(sortKeyword); + } else if (find === 'damage taken') { + tech.tech.sort(sortKeyword); + } else if (find === 'defense') { + tech.tech.sort(sortKeyword); + } else if (find === 'energy') { + tech.tech.sort(sortKeyword); + } else if (find === 'input') { + find = document.getElementById("sort-input").value.toLowerCase(); + tech.tech.sort(sortKeyword); + } + if (isExperiment) { + build.populateGrid() + // build.updateExperimentText() + document.getElementById("tech-0").scrollIntoView(); //scroll to the first tech after sorting + } else { + build.generatePauseRight() //makes the right side of the pause menu with the tech + } + document.getElementById("sort-input").value = find; //make the sorted string display in the keyword search input field + simulation.updateTechHUD(); + }, + unPauseGrid() { + if (localSettings.isAllowed) { + //save details open/close state + if (document.getElementById("simulation-variables-details")) localSettings.pauseMenuDetailsOpen[0] = document.getElementById("simulation-variables-details").open + if (document.getElementById("difficulty-parameters-details")) localSettings.pauseMenuDetailsOpen[1] = document.getElementById("difficulty-parameters-details").open + if (document.getElementById("console-log-details")) localSettings.pauseMenuDetailsOpen[2] = document.getElementById("console-log-details").open + if (document.getElementById("constraints-details")) localSettings.pauseMenuDetailsOpen[3] = document.getElementById("constraints-details").open + localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + + document.getElementById("guns").style.display = "inline" + document.getElementById("field").style.display = "inline" + if (tech.isEnergyHealth) { + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + } else if (!level.isHideHealth) { + document.getElementById("health").style.display = "inline" + document.getElementById("health-bg").style.display = "inline" + } + if (!localSettings.isHideHUD) { + document.getElementById("right-HUD").style.display = "inline" + document.getElementById("defense-bar").style.display = "inline" + document.getElementById("damage-bar").style.display = "inline" + } + // document.body.style.overflow = "hidden" + document.getElementById("pause-grid-left").style.display = "none" + document.getElementById("pause-grid-right").style.display = "none" + document.getElementById("pause-grid-right").style.opacity = "1" + document.getElementById("pause-grid-left").style.opacity = "1" + window.scrollTo(0, 0); + }, + isExperimentSelection: false, + isExperimentRun: false, + techText(i) { + return `
+
  ${build.nameLink(tech.tech[i].name)} ${tech.tech[i].count > 1 ? `(${tech.tech[i].count}x)` : ""}
+ ${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + }, + instantTechText(i) { + // + return `
+
  ${build.nameLink(tech.tech[i].name)} ${tech.tech[i].count > 1 ? `(${tech.tech[i].count}x)` : ""}
+ ${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + }, + skinTechText(i) { + return `
+ +
+
+
        ${build.nameLink(tech.tech[i].name)} ${tech.tech[i].count > 1 ? `(${tech.tech[i].count}x)` : ""}
+ ${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + }, + gunTechText(i) { + return `
+ +
+
+
          ${build.nameLink(tech.tech[i].name)} ${tech.tech[i].count > 1 ? `(${tech.tech[i].count}x)` : ""}
+ ${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + }, + fieldTechText(i) { + return `
+ +
+
+
          ${build.nameLink(tech.tech[i].name)} ${tech.tech[i].count > 1 ? `(${tech.tech[i].count}x)` : ""}
+ ${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + }, + junkTechText(i) { + return `
+
  ${build.nameLink(tech.tech[i].name)} ${tech.tech[i].count > 1 ? `(${tech.tech[i].count}x)` : ""}
+ ${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + }, + choosePowerUp(index, type, isAllowed = false) { + if (type === "gun") { + let isDeselect = false + for (let i = 0, len = b.inventory.length; i < len; i++) { //look for selection in inventory + if (b.guns[b.inventory[i]].name === b.guns[index].name) { //if already clicked, remove gun + isDeselect = true + document.getElementById("gun-" + b.inventory[i]).classList.remove("build-gun-selected"); + //remove gun + b.inventory.splice(i, 1) + b.guns[index].count = 0; + b.guns[index].have = false; + if (b.guns[index].ammo != Infinity) b.guns[index].ammo = 0; + if (b.inventory.length === 0) { + b.activeGun = null; + b.inventoryGun = 0; + } + simulation.makeGunHUD(); + break + } + } + if (!isDeselect) { //add gun + document.getElementById("gun-" + index).classList.add("build-gun-selected"); + b.giveGuns(index) + } + } else if (type === "field") { + if (m.fieldMode !== index) { + document.getElementById("field-" + m.fieldMode).classList.remove("build-field-selected"); + m.setField(index) + document.getElementById("field-" + index).classList.add("build-field-selected"); + document.getElementById("tech-150").focus(); + } else if (m.fieldMode === 4) { + const i = 4 //update experiment text + simulation.molecularMode++ + if (simulation.molecularMode > i - 1) simulation.molecularMode = 0 + m.fieldUpgrades[i].description = m.fieldUpgrades[i].setDescription() + // document.getElementById(`field-${i}`).innerHTML = `
  ${build.nameLink(m.fieldUpgrades[i].name)}
${m.fieldUpgrades[i].description}` + + document.getElementById(`field-${i}`).innerHTML = `
+
  ${build.nameLink(m.fieldUpgrades[i].name)}
+ ${m.fieldUpgrades[i].description}
` + } + } else if (type === "tech") { + if (tech.tech[index].count < tech.tech[index].maxCount) { + // if (!tech.tech[index].isLore && !tech.tech[index].isInstant && !who.classList.contains("build-tech-selected")) who.classList.add("build-tech-selected"); + if (!document.getElementById("tech-" + index).classList.contains("build-tech-selected")) document.getElementById("tech-" + index).classList.add("build-tech-selected"); + tech.giveTech(index) + } else if (!tech.tech[index].isInstant) { + // tech.totalCount -= tech.tech[index].count + document.getElementById("tech-" + index).classList.remove("build-tech-selected"); + tech.removeTech(index); + } else { + // for non refundable tech this makes it flash off for a second, but return to on to show that it can't be set off + document.getElementById("tech-" + index).classList.remove("build-tech-selected") + setTimeout(() => { document.getElementById("tech-" + index).classList.add("build-tech-selected") }, 50); + } + } + build.updateExperimentText(isAllowed) + }, + updateExperimentText(isAllowed = false) { + for (let i = 0, len = tech.tech.length; i < len; i++) { + const techID = document.getElementById("tech-" + i) + if ((!tech.tech[i].isJunk || localSettings.isJunkExperiment) && !tech.tech[i].isLore) { + if (tech.tech[i].allowed() || isAllowed || tech.tech[i].count > 0) { + if (tech.tech[i].isFieldTech) { + techID.classList.remove('experiment-grid-hide'); + techID.innerHTML = build.fieldTechText(i) + } else if (tech.tech[i].isGunTech) { + techID.classList.remove('experiment-grid-hide'); + techID.innerHTML = build.gunTechText(i) + } else if (tech.tech[i].isJunk) { + techID.innerHTML = build.junkTechText(i) + // `
  ${tech.tech[i].link} ${techCountText}
${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}` + } else if (tech.tech[i].isSkin) { + techID.classList.remove('experiment-grid-hide'); + techID.innerHTML = build.skinTechText(i) + } else if (tech.tech[i].isInstant) { + techID.innerHTML = build.instantTechText(i) + } else { + techID.innerHTML = build.techText(i) + } + //deselect selected tech options if you don't have the tech any more // for example: when bot techs are converted after a bot upgrade tech is taken + if (tech.tech[i].count === 0 && techID.classList.contains("build-tech-selected")) techID.classList.remove("build-tech-selected"); + if (techID.classList.contains("experiment-grid-disabled")) { + techID.classList.remove("experiment-grid-disabled"); + techID.setAttribute("onClick", `javascript: build.choosePowerUp(${i},'tech')`); + } + } else { //disabled color for disabled tech + techID.innerHTML = `
${tech.tech[i].name}
${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}` + if (!techID.classList.contains("experiment-grid-disabled")) { + techID.classList.add("experiment-grid-disabled"); + techID.onclick = null + } + if (tech.tech[i].count > 0) tech.removeTech(i) + if (techID.classList.contains("build-tech-selected")) techID.classList.remove("build-tech-selected"); + if (tech.tech[i].isFieldTech) { + techID.innerHTML = build.fieldTechText(i) + } else if (tech.tech[i].isGunTech) { + techID.innerHTML = build.gunTechText(i) + } else if (tech.tech[i].isJunk) { + techID.innerHTML = build.junkTechText(i) + } else if (tech.tech[i].isSkin) { + techID.innerHTML = build.skinTechText(i) + } else if (tech.tech[i].isInstant) { + techID.innerHTML = build.instantTechText(i) + } else { + techID.innerHTML = build.techText(i) + } + } + } + } + }, + //
+ // + //     + // + // + //
+ + // + // + populateGrid() { //background-color:var(--build-bg-color); + let text = ` +
+
+ + + + + + + + +
+
+
+
+ + + start + + +
+
+ + + reset + + +
+
+ + + share + + +
+
+
+
` + const hideStyle = `style="height:auto; border: none; background-color: transparent;"` + for (let i = 0, len = m.fieldUpgrades.length; i < len; i++) { + const style = localSettings.isHideImages ? hideStyle : `style="background-image: url('img/field/${m.fieldUpgrades[i].name}${i === 0 ? m.fieldUpgrades[0].imageNumber : ""}.webp');"` + text += `
+
+
  ${build.nameLink(m.fieldUpgrades[i].name)}
+ ${m.fieldUpgrades[i].description}
` + } + for (let i = 0, len = b.guns.length; i < len; i++) { + const style = localSettings.isHideImages ? hideStyle : `style="background-image: url('img/gun/${b.guns[i].name}.webp');"` + text += `
+
+
  ${build.nameLink(b.guns[i].name)}
+ ${b.guns[i].descriptionFunction()}
` + } + for (let i = 0, len = tech.tech.length; i < len; i++) { + if ((!tech.tech[i].isJunk || localSettings.isJunkExperiment) && !tech.tech[i].isLore) { + const style = (localSettings.isHideImages || tech.tech[i].isJunk) ? hideStyle : `style="background-image: url('img/${tech.tech[i].name}.webp');"` + if ((tech.tech[i].allowed() || tech.tech[i].count > 0) && (!tech.tech[i].isInstant || localSettings.isJunkExperiment)) { // || tech.tech[i].name === "+1 cardinality") { //|| tech.tech[i].name === "leveraged investment" + text += `
` + } else { //disabled + text += `
` + } + + if (tech.tech[i].isFieldTech) { + text += build.fieldTechText(i) + } else if (tech.tech[i].isGunTech) { + text += build.gunTechText(i) + } else if (tech.tech[i].isSkin) { + text += build.skinTechText(i) + } else if (tech.tech[i].isJunk) { + text += build.junkTechText(i) + } else if (tech.tech[i].isInstant) { + text += build.instantTechText(i) + } else { + text += build.techText(i) + } + text += '
' + } + } + document.getElementById("experiment-grid").innerHTML = text + + + //add event listener for pressing enter key when in sort + function pressEnterSort(event) { + if (event.key === 'Enter') { + // event.preventDefault(); // Prevent the default action to avoid form submission or any other default action + build.sortTech('input', true) + } + } + document.getElementById("sort-input").addEventListener('keydown', pressEnterSort); + + //add tooltips + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (document.getElementById(`tech-${i}`)) { + document.getElementById(`tech-${i}`).setAttribute('data-descr', tech.tech[i].requires); //add tooltip + // document.getElementById(`tech-${i}`).setAttribute('title', tech.tech[i].requires); //add tooltip + } + } + + requestAnimationFrame(() => { document.getElementById("sort-input").focus(); }); + }, + nameLink(text) { //converts text into a clickable wikipedia search + return `${text}` + }, + reset() { + build.isExperimentSelection = true; + build.isExperimentRun = true; + simulation.startGame(true); //starts game, but pauses it + build.isExperimentSelection = true; + build.isExperimentRun = true; + simulation.paused = true; + b.inventory = []; //removes guns and ammo + for (let i = 0, len = b.guns.length; i < len; ++i) { + b.guns[i].count = 0; + b.guns[i].have = false; + if (b.guns[i].ammo != Infinity) b.guns[i].ammo = 0; + } + b.activeGun = null; + b.inventoryGun = 0; + simulation.makeGunHUD(); + tech.resetAllTech(); + build.populateGrid(); + document.getElementById("field-0").classList.add("build-field-selected"); + document.getElementById("experiment-grid").style.display = "grid" + }, + shareURL(isCustom = false) { + let url = "https://landgreen.github.io/n-gon/index.html?" + url += `&seed=${Math.initialSeed}` + let count = 0; + for (let i = 0; i < b.inventory.length; i++) { + if (b.guns[b.inventory[i]].have) { + url += `&gun${count}=${encodeURIComponent(b.guns[b.inventory[i]].name.trim())}` + count++ + } + } + count = 0; + for (let i = 0; i < tech.tech.length; i++) { + for (let j = 0; j < tech.tech[i].count; j++) { + if (!tech.tech[i].isLore && !tech.tech[i].isJunk && !tech.tech[i].isInstant) { + url += `&tech${count}=${encodeURIComponent(tech.tech[i].name.trim())}` + count++ + } + } + } + url += `&molMode=${encodeURIComponent(simulation.molecularMode)}` + // if (property === "molMode") { + // simulation.molecularMode = Number(set[property]) + // m.fieldUpgrades[i].description = m.fieldUpgrades[i].setDescription() + // document.getElementById(`field-${i}`).innerHTML = `
  ${build.nameLink(m.fieldUpgrades[i].name)}
${m.fieldUpgrades[i].description}` + // } + + url += `&field=${encodeURIComponent(m.fieldUpgrades[m.fieldMode].name.trim())}` + url += `&difficulty=${simulation.difficultyMode}` + if (isCustom) { + // url += `&level=${Math.abs(Number(document.getElementById("starting-level").value))}` + // alert('n-gon build URL copied to clipboard.\nPaste into browser address bar.') + } else { + simulation.inGameConsole("n-gon build URL copied to clipboard.
Paste into browser address bar.") + } + console.log('n-gon build URL copied to clipboard.\nPaste into browser address bar.') + console.log(url) + navigator.clipboard.writeText(url).then(function () { + /* clipboard successfully set */ + if (isCustom) { + setTimeout(function () { + alert('n-gon build URL copied to clipboard.\nPaste into browser address bar.') + }, 300); + } + }, function () { + /* clipboard write failed */ + if (isCustom) { + setTimeout(function () { + alert('copy failed') + }, 300); + } + console.log('copy failed') + }); + + }, + hasExperimentalMode: false, + startExperiment() { //start playing the game after exiting the experiment menu + build.isExperimentSelection = false; + spawn.setSpawnList(); //gives random mobs, not starter mobs + if (b.inventory.length > 0) { + b.activeGun = b.inventory[0] //set first gun to active gun + b.inventoryGun = 0; + simulation.makeGunHUD(); + } + for (let i = 0; i < bullet.length; ++i) Matter.Composite.remove(engine.world, bullet[i]); + bullet = []; //remove any bullets that might have spawned from tech + build.hasExperimentalMode = false + if (!simulation.isCheating) { + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].count > 0 && !tech.tech[i].isLore) simulation.isCheating = true; + } + if (b.inventory.length !== 0 || m.fieldMode !== 0) simulation.isCheating = true; + } + if (simulation.isCheating) { //if you are cheating remove any lore you might have gotten + lore.techCount = 0; + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isLore) { + tech.tech[i].frequency = 0; //remove lore power up chance + tech.tech[i].count = 0; //remove lore power up chance + } + } + simulation.updateTechHUD(); + } else { //if you have no tech (not cheating) remove all power ups that might have spawned from tech + for (let i = 0; i < powerUp.length; ++i) Matter.Composite.remove(engine.world, powerUp[i]); + powerUp = []; + } + document.body.style.cursor = "none"; + document.body.style.overflow = "hidden" + document.getElementById("experiment-grid").style.display = "none" + simulation.paused = false; + requestAnimationFrame(cycle); + } +} + +function openExperimentMenu() { + document.getElementById("experiment-button").style.display = "none"; + document.getElementById("training-button").style.display = "none"; + document.getElementById("start-button").style.display = "none"; + const el = document.getElementById("experiment-grid") + el.style.display = "grid" + document.body.style.overflowY = "scroll"; + document.body.style.overflowX = "hidden"; + document.getElementById("info").style.display = 'none' + build.reset(); +} + +//record settings so they can be reproduced in the experimental menu +document.getElementById("experiment-button").addEventListener("click", () => { //setup build run + // let field = 0; + // let inventory = []; + // let techList = []; + // if (!simulation.firstRun) { + // field = m.fieldMode + // inventory = [...b.inventory] + // for (let i = 0; i < tech.tech.length; i++) { + // techList.push(tech.tech[i].count) + // } + // } + openExperimentMenu(); +}); + + +// ************************************************************************************************ +// inputs +// ************************************************************************************************ +const input = { + fire: false, // left mouse + field: false, // right mouse + up: false, // jump + down: false, // crouch + left: false, + right: false, + isPauseKeyReady: true, + key: { + fire: "KeyF", + field: "Space", + up: "KeyW", // jump + down: "KeyS", // crouch + left: "KeyA", + right: "KeyD", + pause: "KeyP", + nextGun: "KeyE", + previousGun: "KeyQ", + testing: "KeyT" + }, + setDefault() { + input.key = { + fire: "KeyF", + field: "Space", + up: "KeyW", // jump + down: "KeyS", // crouch + left: "KeyA", + right: "KeyD", + pause: "KeyP", + nextGun: "KeyE", + previousGun: "KeyQ", + testing: "KeyT" + } + input.controlTextUpdate() + }, + controlTextUpdate() { + function cleanText(text) { + return text.replace('Key', '').replace('Digit', '') + } + if (!input.key.fire) input.key.fire = "KeyF" + document.getElementById("key-fire").innerHTML = cleanText(input.key.fire) + document.getElementById("key-field").innerHTML = cleanText(input.key.field) + document.getElementById("key-up").innerHTML = cleanText(input.key.up) + document.getElementById("key-down").innerHTML = cleanText(input.key.down) + document.getElementById("key-left").innerHTML = cleanText(input.key.left) + document.getElementById("key-right").innerHTML = cleanText(input.key.right) + document.getElementById("key-pause").innerHTML = cleanText(input.key.pause) + document.getElementById("key-next-gun").innerHTML = cleanText(input.key.nextGun) + document.getElementById("key-previous-gun").innerHTML = cleanText(input.key.previousGun) + document.getElementById("key-testing").innerHTML = cleanText(input.key.testing) //if (localSettings.loreCount > 0) + + document.getElementById("splash-up").innerHTML = cleanText(input.key.up)[0] + document.getElementById("splash-down").innerHTML = cleanText(input.key.down)[0] + document.getElementById("splash-left").innerHTML = cleanText(input.key.left)[0] + document.getElementById("splash-right").innerHTML = cleanText(input.key.right)[0] + document.getElementById("splash-next-gun").innerHTML = cleanText(input.key.nextGun)[0] + document.getElementById("splash-previous-gun").innerHTML = cleanText(input.key.previousGun)[0] + + localSettings.key = input.key + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + }, + focus: null, + setTextFocus() { + const backgroundColor = "#fff" + document.getElementById("key-fire").style.background = backgroundColor + document.getElementById("key-field").style.background = backgroundColor + document.getElementById("key-up").style.background = backgroundColor + document.getElementById("key-down").style.background = backgroundColor + document.getElementById("key-left").style.background = backgroundColor + document.getElementById("key-right").style.background = backgroundColor + document.getElementById("key-pause").style.background = backgroundColor + document.getElementById("key-next-gun").style.background = backgroundColor + document.getElementById("key-previous-gun").style.background = backgroundColor + document.getElementById("key-testing").style.background = backgroundColor + if (input.focus) input.focus.style.background = 'rgb(0, 200, 255)'; + document.getElementById("key-num").style.background = backgroundColor //always not highlighted + }, + setKeys(event) { + //check for duplicate keys + if (event.code && !( + event.code === "ArrowRight" || + event.code === "ArrowLeft" || + event.code === "ArrowUp" || + event.code === "ArrowDown" || + event.code === input.key.fire || + event.code === input.key.field || + event.code === input.key.up || + event.code === input.key.down || + event.code === input.key.left || + event.code === input.key.right || + event.code === input.key.pause || + // event.code === "Escape" || + event.code === input.key.nextGun || + event.code === input.key.previousGun || + event.code === input.key.testing || + event.code === "Digit1" || event.code === "Digit2" || event.code === "Digit3" || event.code === "Digit4" || event.code === "Digit5" || event.code === "Digit6" || event.code === "Digit7" || event.code === "Digit8" || event.code === "Digit9" || event.code === "Digit0" || event.code === "Minus" || event.code === "Equal" + )) { + switch (input.focus.id) { + case "key-fire": + input.key.fire = event.code + break; + case "key-field": + input.key.field = event.code + break; + case "key-up": + input.key.up = event.code + break; + case "key-down": + input.key.down = event.code + break; + case "key-left": + input.key.left = event.code + break; + case "key-right": + input.key.right = event.code + break; + case "key-pause": + input.key.pause = event.code + break; + case "key-next-gun": + input.key.nextGun = event.code + break; + case "key-previous-gun": + input.key.previousGun = event.code + break; + case "key-testing": + input.key.testing = event.code + break; + } + } + input.controlTextUpdate() + input.endKeySensing() + }, + endKeySensing() { + window.removeEventListener("keydown", input.setKeys); + input.focus = null + input.setTextFocus() + } +} + +document.getElementById("control-table").addEventListener('click', (event) => { + if (event.target.className === 'key-input') { + input.focus = event.target + input.setTextFocus() + window.addEventListener("keydown", input.setKeys); + } +}); +document.getElementById("control-details").addEventListener("toggle", function () { + input.controlTextUpdate() + input.endKeySensing(); +}) + +document.getElementById("control-reset").addEventListener('click', input.setDefault); + +window.addEventListener("keyup", function (event) { + switch (event.code) { + case input.key.right: + case "ArrowRight": + input.right = false + break; + case input.key.left: + case "ArrowLeft": + input.left = false + break; + case input.key.up: + case "ArrowUp": + input.up = false + break; + case input.key.down: + case "ArrowDown": + input.down = false + break; + case input.key.fire: + input.fire = false + break + case input.key.field: + input.field = false + break + } +}); + +window.addEventListener("keydown", function (event) { + // console.log(event.code) + switch (event.code) { + case input.key.right: + case "ArrowRight": + input.right = true + break; + case input.key.left: + case "ArrowLeft": + input.left = true + break; + case input.key.up: + case "ArrowUp": + input.up = true + break; + case input.key.down: + case "ArrowDown": + input.down = true + break; + case input.key.fire: + input.fire = true + break + case input.key.field: + input.field = true + break + case input.key.nextGun: + simulation.nextGun(); + break + case input.key.previousGun: + simulation.previousGun(); + break + case input.key.pause: + if (input.isPauseKeyReady && m.alive && !build.isExperimentSelection) { + input.isPauseKeyReady = false + setTimeout(function () { input.isPauseKeyReady = true }, 300); + if (simulation.isChoosing) { + + build.pauseGrid() + + } else if (simulation.paused) { + if (document.activeElement !== document.getElementById('sort-input')) { + build.unPauseGrid() + simulation.paused = false; + // level.levelAnnounce(); + document.body.style.cursor = "none"; + requestAnimationFrame(cycle); + } + } else { //if (!tech.isNoDraftPause) + simulation.paused = true; + build.pauseGrid() + document.body.style.cursor = "auto"; + + if (tech.isPauseSwitchField || simulation.testing) { + document.getElementById("pause-field-previous").addEventListener("click", () => { + const energy = m.energy //save current energy + if (m.fieldMode === 4 && simulation.molecularMode > 0) { + simulation.molecularMode-- + m.fieldUpgrades[4].description = m.fieldUpgrades[4].setDescription() + } else { + m.setField((m.fieldMode < 2) ? m.fieldUpgrades.length - 1 : m.fieldMode - 1) //cycle to previous field, skip field emitter + if (m.fieldMode === 4) { + simulation.molecularMode = 3 + m.fieldUpgrades[4].description = m.fieldUpgrades[4].setDescription() + } + } + m.energy = energy //return to current energy + document.getElementById("pause-field").style.backgroundImage = `url('img/field/${m.fieldUpgrades[m.fieldMode].name}${m.fieldMode === 0 ? Math.floor(Math.random() * 10) : ""}.webp')` + document.getElementById("pause-field").innerHTML = `
  ${build.nameLink(m.fieldUpgrades[m.fieldMode].name)}
${m.fieldUpgrades[m.fieldMode].description}
` + }); + + document.getElementById("pause-field-next").addEventListener("click", () => { + const energy = m.energy //save current energy + if (m.fieldMode === 4 && simulation.molecularMode < 3) { + simulation.molecularMode++ + m.fieldUpgrades[4].description = m.fieldUpgrades[4].setDescription() + } else { + m.setField((m.fieldMode === m.fieldUpgrades.length - 1) ? 1 : m.fieldMode + 1) //cycle to next field, skip field emitter + if (m.fieldMode === 4) { + simulation.molecularMode = 0 + m.fieldUpgrades[4].description = m.fieldUpgrades[4].setDescription() + } + } + m.energy = energy //return to current energy + // document.getElementById("pause-field").innerHTML = `
  ${m.fieldUpgrades[m.fieldMode].name}
${m.fieldUpgrades[m.fieldMode].description}` + document.getElementById("pause-field").style.backgroundImage = `url('img/field/${m.fieldUpgrades[m.fieldMode].name}${m.fieldMode === 0 ? Math.floor(Math.random() * 10) : ""}.webp')` + document.getElementById("pause-field").innerHTML = `
  ${build.nameLink(m.fieldUpgrades[m.fieldMode].name)}
${m.fieldUpgrades[m.fieldMode].description}
` + }); + } + } + } + break + case input.key.testing: + if (m.alive && localSettings.loreCount > 0 && !simulation.paused && !build.isExperimentSelection) { + if (simulation.difficultyMode > 5) { + simulation.inGameConsole("testing mode disabled for this difficulty"); + break + } + if (simulation.testing) { + simulation.testing = false; + simulation.loop = simulation.normalLoop + if (simulation.isConstructionMode) document.getElementById("construct").style.display = 'none' + simulation.inGameConsole("", 0); + } else { + simulation.testing = true; + simulation.loop = simulation.testingLoop + if (simulation.testing) tech.setCheating(); + if (simulation.isConstructionMode) { + document.getElementById("construct").style.display = 'inline' + } else { + simulation.inGameConsole( + ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Ttoggle testing
Rteleport to mouse
Fcycle field
Gall guns
H+100% defense
Bdamage, research
Nfill health, energy
Yrandom tech
Unext level
Jclear mobs
I/Ozoom in / out
1-8spawn things
⇧Xrestart
`, Infinity); + } + } + } + break + } + if (b.inventory.length > 1 && !simulation.testing && !(tech.isGunChoice || tech.isGunCycle)) { + switch (event.code) { + case "Digit1": + simulation.switchToGunInInventory(0); + break + case "Digit2": + simulation.switchToGunInInventory(1); + break + case "Digit3": + simulation.switchToGunInInventory(2); + break + case "Digit4": + simulation.switchToGunInInventory(3); + break + case "Digit5": + simulation.switchToGunInInventory(4); + break + case "Digit6": + simulation.switchToGunInInventory(5); + break + case "Digit7": + simulation.switchToGunInInventory(6); + break + case "Digit8": + simulation.switchToGunInInventory(7); + break + case "Digit9": + simulation.switchToGunInInventory(8); + break + case "Digit0": + simulation.switchToGunInInventory(9); + break + case "Minus": + simulation.switchToGunInInventory(10); + break + case "Equal": + simulation.switchToGunInInventory(11); + break + } + } + + if (simulation.testing) { + if (event.key === "X") m.death(); //only uppercase + switch (event.key.toLowerCase()) { + case "o": + // simulation.isAutoZoom = false; + // simulation.zoomScale /= 0.9; + // simulation.setZoom(); + simulation.zoomTransition(simulation.zoomScale / 0.9) + break; + case "i": + // simulation.isAutoZoom = false; + // simulation.zoomScale *= 0.9; + // simulation.setZoom(); + simulation.zoomTransition(simulation.zoomScale * 0.9) + break + case "`": + powerUps.directSpawn(simulation.mouseInGame.x, simulation.mouseInGame.y, "research"); + break + case "1": + powerUps.directSpawn(simulation.mouseInGame.x, simulation.mouseInGame.y, "heal"); + break + case "2": + powerUps.directSpawn(simulation.mouseInGame.x, simulation.mouseInGame.y, "ammo"); + break + case "3": + powerUps.directSpawn(simulation.mouseInGame.x, simulation.mouseInGame.y, "gun"); + break + case "4": + powerUps.directSpawn(simulation.mouseInGame.x, simulation.mouseInGame.y, "field"); + break + case "5": + powerUps.directSpawn(simulation.mouseInGame.x, simulation.mouseInGame.y, "tech"); + break + case "6": + spawn.bodyRect(simulation.mouseInGame.x, simulation.mouseInGame.y, 50, 50); + break + case "7": + const pick = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]; + spawn[pick](simulation.mouseInGame.x, simulation.mouseInGame.y); + break + case "8": + spawn.randomLevelBoss(simulation.mouseInGame.x, simulation.mouseInGame.y); + break + case "f": + const mode = (m.fieldMode === m.fieldUpgrades.length - 1) ? 0 : m.fieldMode + 1 + m.setField(mode) + break + case "g": + b.giveGuns("all", 1000) + break + case "h": + // m.health = Infinity + if (m.immuneCycle === Infinity) { + m.immuneCycle = 0 //you can't take damage + } else { + m.immuneCycle = Infinity //you can't take damage + } + + // m.energy = Infinity + // document.getElementById("health").style.display = "none" + // document.getElementById("health-bg").style.display = "none" + break + case "n": + m.addHealth(Infinity) + m.energy = m.maxEnergy + break + case "y": + tech.giveTech() + break + case "b": + tech.isRerollDamage = true + powerUps.research.changeRerolls(1000000) + break + case "r": + m.resetHistory(); + Matter.Body.setPosition(player, simulation.mouseInGame); + Matter.Body.setVelocity(player, { x: 0, y: 0 }); + // move bots to player + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + break + case "u": + level.nextLevel(); + break + case "j": + for (let i = 0, len = mob.length; i < len; ++i) mob[i].damage(Infinity, true) + setTimeout(() => { + for (let i = 0, len = mob.length; i < len; ++i) mob[i].damage(Infinity, true) + }, 100); + setTimeout(() => { + for (let i = 0, len = mob.length; i < len; ++i) mob[i].damage(Infinity, true) + }, 200); + break + case "l": + document.getElementById("field").style.display = "none" + document.getElementById("guns").style.display = "none" + document.getElementById("right-HUD").style.display = "none" + break + } + } +}); +//mouse move input +function mouseMoveDefault(e) { + simulation.mouse.x = e.clientX; + simulation.mouse.y = e.clientY; +} +let mouseMove = mouseMoveDefault +document.body.addEventListener("mousemove", (e) => { + mouseMove(e) +}); + +document.body.addEventListener("mouseup", (e) => { + // input.fire = false; + // console.log(e) + if (e.button === 0) { + input.fire = false; + } else if (e.button === 2) { + input.field = false; + } +}); + +document.body.addEventListener("mousedown", (e) => { + if (e.button === 0) { + input.fire = true; + } else if (e.button === 2) { + input.field = true; + } +}); + +document.body.addEventListener("mouseenter", (e) => { //prevents mouse getting stuck when leaving the window + if (e.button === 1) { + input.fire = true; + } else { + input.fire = false; + } + + if (e.button === 3) { + input.field = true; + } else { + input.field = false; + } +}); +document.body.addEventListener("mouseleave", (e) => { //prevents mouse getting stuck when leaving the window + if (e.button === 1) { + input.fire = true; + } else { + input.fire = false; + } + + if (e.button === 3) { + input.field = true; + } else { + input.field = false; + } +}); + +document.body.addEventListener("wheel", (e) => { + if (!simulation.paused) { + if (e.deltaY > 0) { + simulation.nextGun(); + } else { + simulation.previousGun(); + } + } +}, { + passive: true +}); + +//********************************************************************** +// local storage +//********************************************************************** +let localSettings + +function localStorageCheck() { + try { + return 'localStorage' in window && window['localStorage'] !== null; + } catch (e) { + return false; + } + +} +if (localStorageCheck()) { + localSettings = JSON.parse(localStorage.getItem("localSettings")) + if (localSettings) { + console.log('localStorage is enabled') + localSettings.isAllowed = true + localSettings.isEmpty = false + } else { + console.log('localStorage is enabled, local settings empty') + localSettings = { + isAllowed: true, + isEmpty: true + } + } +} else { + console.log("localStorage is disabled") + localSettings = { + isAllowed: false + } +} + +if (localSettings.isAllowed && !localSettings.isEmpty) { + console.log('restoring previous settings') + + if (localSettings.key) { + input.key = localSettings.key + } else { + input.setDefault() + } + + if (localSettings.loreCount === undefined) { + localSettings.loreCount = 0 + localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + + simulation.isCommunityMaps = localSettings.isCommunityMaps + document.getElementById("community-maps").checked = localSettings.isCommunityMaps + + if (localSettings.fpsCapDefault === undefined) localSettings.fpsCapDefault = 'max' + if (localSettings.personalSeeds === undefined) localSettings.personalSeeds = []; + if (localSettings.fpsCapDefault === 'max') { + simulation.fpsCapDefault = 999999999; + } else { + simulation.fpsCapDefault = Number(localSettings.fpsCapDefault) + } + document.getElementById("fps-select").value = localSettings.fpsCapDefault + + if (!localSettings.banList) localSettings.banList = "" + if (localSettings.banList.length === 0 || localSettings.banList === "undefined") { + localSettings.banList = "" + localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + document.getElementById("banned").value = localSettings.banList + + if (!localSettings.isLoreDoesNotNeedReset) { + localSettings.isLoreDoesNotNeedReset = true + localSettings.loreCount = 0; //this sets what conversation is heard + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + if (localSettings.isHideImages === undefined) localSettings.isHideImages = true //default to hide images + document.getElementById("hide-images").checked = localSettings.isHideImages + // localSettings.isHideImages = true //no images + + if (localSettings.isHideHUD === undefined) localSettings.isHideHUD = true + document.getElementById("hide-hud").checked = localSettings.isHideHUD + + if (localSettings.difficultyCompleted === undefined) { + localSettings.difficultyCompleted = [null, false, false, false, false, false, false, false] //null because there isn't a difficulty zero + localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + + if (localSettings.difficultyMode === undefined) localSettings.difficultyMode = "2" + simulation.difficultyMode = localSettings.difficultyMode + lore.setTechGoal() + + if (localSettings.pauseMenuDetailsOpen === undefined) { + localSettings.pauseMenuDetailsOpen = [true, false, false, true] + localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } +} else { + console.log('setting default localSettings') + const isAllowed = localSettings.isAllowed //don't overwrite isAllowed value + localSettings = { + banList: "", + isAllowed: isAllowed, + personalSeeds: [], + isJunkExperiment: false, + isCommunityMaps: false, + difficultyMode: '2', + difficultyCompleted: [null, false, false, false, false, false, false, false], + fpsCapDefault: 'max', + runCount: 0, + isTrainingNotAttempted: true, + levelsClearedLastGame: 0, + loreCount: 0, + isLoreDoesNotNeedReset: false, + isHuman: false, + key: undefined, + isHideImages: true, //default to hide images + isHideHUD: false, + pauseMenuDetailsOpen: [true, false, false, true] + }; + input.setDefault() + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + document.getElementById("community-maps").checked = localSettings.isCommunityMaps + simulation.isCommunityMaps = localSettings.isCommunityMaps + document.getElementById("hide-images").checked = localSettings.isHideImages + document.getElementById("fps-select").value = localSettings.fpsCapDefault + document.getElementById("banned").value = localSettings.banList +} +document.getElementById("control-testing").style.visibility = (localSettings.loreCount === 0) ? "hidden" : "visible" +// document.getElementById("experiment-button").style.visibility = (localSettings.loreCount === 0) ? "hidden" : "visible" +input.controlTextUpdate() + + +//********************************************************************** +// settings +//********************************************************************** + + +// difficulty-select-experiment event listener is set in build.makeGrid +// document.getElementById("difficulty-select").addEventListener("input", () => { +// simulation.difficultyMode = Number(document.getElementById("difficulty-select").value) +// lore.setTechGoal() +// localSettings.difficultyMode = simulation.difficultyMode +// localSettings.levelsClearedLastGame = 0 //after changing difficulty, reset run history +// localSettings.entanglement = undefined //after changing difficulty, reset stored tech +// if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage +// }); + + +document.getElementById("fps-select").addEventListener("input", () => { + let value = document.getElementById("fps-select").value + if (value === 'max') { + simulation.fpsCapDefault = 999999999; + } else { + simulation.fpsCapDefault = Number(value) + } + localSettings.fpsCapDefault = value + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage +}); + +document.getElementById("banned").addEventListener("input", () => { + localSettings.banList = document.getElementById("banned").value + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage +}); + +document.getElementById("community-maps").addEventListener("input", () => { + simulation.isCommunityMaps = document.getElementById("community-maps").checked + localSettings.isCommunityMaps = simulation.isCommunityMaps + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage +}); + +document.getElementById("updates").addEventListener("toggle", function () { + function loadJSON(path, success, error) { //generic function to get JSON + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function () { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + if (success) + success(JSON.parse(xhr.responseText)); + } else { + if (error) + error(xhr); + } + } + }; + xhr.open("GET", path, true); + xhr.send(); + } + let text = `
n-gon: todo list and complete change-log
` + document.getElementById("updates-div").innerHTML = text + + /// https://api.github.com/repos/landgreen/n-gon/stats/commit_activity + loadJSON('https://api.github.com/repos/landgreen/n-gon/commits', + function (data) { + // console.log(data[0].sha) //unique code for most recent commit + for (let i = 0, len = 20; i < len; i++) { + text += "" + data[i].commit.author.date.substr(0, 10) + " - "; //+ "
" + text += data[i].commit.message + if (i < len - 1) text += "
" + } + text += "
" + document.getElementById("updates-div").innerHTML = text.replace(/\n/g, "
") + }, + function (xhr) { + console.error(xhr); + } + ); +}) +const sound = { + tone(frequency, end = 1000, gain = 0.05) { + const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); //setup audio context + const oscillator = audioCtx.createOscillator(); + const gainNode = audioCtx.createGain(); + gainNode.gain.value = gain; //controls volume + oscillator.connect(gainNode); + gainNode.connect(audioCtx.destination); + oscillator.type = "sine"; // 'sine' 'square', 'sawtooth', 'triangle' and 'custom' + oscillator.frequency.value = frequency; // value in hertz + oscillator.start(); + setTimeout(() => { + audioCtx.suspend() + audioCtx.close() + }, end) + // return audioCtx + }, + portamento(frequency, end = 1000, shiftRate = 10, gain = 0.05) { + const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); //setup audio context + const oscillator = audioCtx.createOscillator(); + const gainNode = audioCtx.createGain(); + gainNode.gain.value = gain; //controls volume + oscillator.connect(gainNode); + gainNode.connect(audioCtx.destination); + oscillator.type = "sine"; // 'sine' 'square', 'sawtooth', 'triangle' and 'custom' + oscillator.frequency.value = frequency; // value in hertz + oscillator.start(); + for (let i = 0, len = end * 0.1; i < len; i++) oscillator.frequency.setValueAtTime(frequency + i * shiftRate, audioCtx.currentTime + i * 0.01); + setTimeout(() => { + audioCtx.suspend() + audioCtx.close() + }, end) + // return audioCtx + } +} + +// preload images so they load cleaner +// MDN Scripting and preloads - https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload +// if (!localSettings.isHideImages) { +// for (let i = 0, len = b.guns.length; i < len; i++) { +// const preloadLink = document.createElement("link"); +// preloadLink.href = "img/gun/" + b.guns[i].name + ".webp"; +// preloadLink.rel = "preload"; +// preloadLink.as = "image"; +// document.head.appendChild(preloadLink); +// } +// for (let i = 1, len = m.fieldUpgrades.length; i < len; i++) { +// const preloadLink = document.createElement("link"); +// preloadLink.href = "img/field/" + m.fieldUpgrades[i].name + ".webp"; +// preloadLink.rel = "preload"; +// preloadLink.as = "image"; +// document.head.appendChild(preloadLink); +// } +// for (let i = 0, len = tech.tech.length; i < len; i++) { +// if (!tech.tech[i].isJunk) { +// const preloadLink = document.createElement("link"); +// preloadLink.href = "img/" + tech.tech[i].name + ".webp"; +// preloadLink.rel = "preload"; +// preloadLink.as = "image"; +// document.head.appendChild(preloadLink); +// } +// } +// } + + +//preload images early +if (!localSettings.isHideImages) { + addEventListener("load", () => { + let urls = new Array() + for (let i = 0, len = b.guns.length; i < len; i++) urls.push("img/gun/" + b.guns[i].name + ".webp") + for (let i = 1, len = m.fieldUpgrades.length; i < len; i++) urls.push("img/field/" + m.fieldUpgrades[i].name + ".webp") + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (!tech.tech[i].isJunk && !tech.tech[i].isLore) urls.push("img/" + tech.tech[i].name + ".webp") + } + let images = new Array() + for (let i = 0; i < urls.length; i++) { + images[i] = new Image() + images[i].src = urls[i] + } + // console.log(urls, images) + }); + document.getElementById("choose-grid").classList.add('choose-grid'); +} else { + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); +} + + +//********************************************************************** +// main loop +//********************************************************************** +simulation.loop = simulation.normalLoop; + +function cycle() { + if (!simulation.paused) requestAnimationFrame(cycle); + const now = Date.now(); + const elapsed = now - simulation.then; // calc elapsed time since last loop + if (elapsed > simulation.fpsInterval) { // if enough time has elapsed, draw the next frame + simulation.then = now - (elapsed % simulation.fpsInterval); // Get ready for next frame by setting then=now. Also, adjust for fpsInterval not being multiple of 16.67 + + simulation.cycle++; //tracks game cycles + m.cycle++; //tracks player cycles //used to alow time to stop for everything, but the player + if (simulation.clearNow) { + simulation.clearNow = false; + simulation.clearMap(); + level.start(); + } + simulation.loop(); + } +} + +// function cycle() { +// if (!simulation.paused) requestAnimationFrame(cycle); +// const now = Date.now(); +// const elapsed = now - simulation.then; // calc elapsed time since last loop +// if (elapsed > simulation.fpsInterval) { // if enough time has elapsed, draw the next frame +// simulation.then = now - (elapsed % simulation.fpsInterval); // Get ready for next frame by setting then=now. Also, adjust for fpsInterval not being multiple of 16.67 + +// simulation.cycle++; //tracks game cycles +// m.cycle++; //tracks player cycles //used to alow time to stop for everything, but the player +// if (simulation.clearNow) { +// simulation.clearNow = false; +// simulation.clearMap(); +// level.start(); +// } +// simulation.loop(); +// } +// } + +// let timeStart = performance.now() +// //0, 16.6666666666, 33.333333333333, 50.000000000 +// function cycle(timestamp) { +// if (!simulation.paused) requestAnimationFrame(cycle); +// if (timestamp - timeStart > 0) { //simulation.fpsInterval) { // if enough time has elapsed, draw the next frame +// console.log(timestamp - timeStart) +// timeStart = timestamp +// simulation.cycle++; //tracks game cycles +// m.cycle++; //tracks player cycles //used to alow time to stop for everything, but the player +// if (simulation.clearNow) { +// simulation.clearNow = false; +// simulation.clearMap(); +// level.start(); +// } +// simulation.loop(); +// } +// } + +// let count = 1 +// let timeStart = performance.now() +// const cycle = (timestamp) => { +// // if (timeStart === undefined) timeStart = timestamp +// // console.log(timestamp, timeStart) +// if (timestamp - timeStart > tech.brainStormDelay * count) { +// count++ +// powerUps.tech.effect(); +// document.getElementById("choose-grid").style.pointerEvents = "auto"; //turn off the normal 500ms delay +// document.body.style.cursor = "auto"; +// document.getElementById("choose-grid").style.transitionDuration = "0s"; +// } +// if (count < 5 && simulation.isChoosing) { +// requestAnimationFrame(cycle); +// } else { +// tech.isBrainstormActive = false +// } +// } +// requestAnimationFrame(cycle); \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/level.js b/WebGames-master/WebGames-master/n-gon-master/js/level.js new file mode 100644 index 00000000..13083688 --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/level.js @@ -0,0 +1,39026 @@ +let body = []; //non static bodies +let map = []; //all static bodies +let cons = []; //all constraints between a point and a body +let consBB = []; //all constraints between two bodies +let composite = [] //rotors and other map elements that don't fit +const level = { + fallMode: "", + defaultZoom: 1400, + onLevel: -1, + levelsCleared: 0, + isFlipped: false, + uniqueLevels: ["initial", "reservoir", "factory", "interferometer", "reactor", "subway", "final"], //see level.populateLevels: (initial, ... , (reservoir, factory, or interferometer), reactor, ... , subway, final) added later + playableLevels: ["labs", "rooftops", "skyscrapers", "warehouse", "highrise", "office", "aerie", "satellite", "sewers", "testChamber", "pavilion", "lock", "towers", "flocculation", "gravitron", "substructure", "corridor"], + communityLevels: ["gauntlet", "stronghold", "basement", "crossfire", "vats", "run", "ngon", "house", "perplex", "coliseum", "tunnel", "islands", "temple", "dripp", "biohazard", "stereoMadness", "yingYang", "staircase", "fortress", "commandeer", "clock", "buttonbutton", "downpour", "superNgonBros", "underpass", "cantilever", "tlinat", "ruins", "ace", "crimsonTowers", "LaunchSite", "shipwreck", "unchartedCave", "dojo", "arena", "soft", "flappyGon", "rings", "trial"], + trainingLevels: ["walk", "crouch", "jump", "hold", "throw", "throwAt", "deflect", "heal", "fire", "nailGun", "shotGun", "superBall", "matterWave", "missile", "stack", "mine", "grenades", "harpoon"], + levels: [], + start() { + if (level.levelsCleared === 0) { //this code only runs on the first level + // simulation.enableConstructMode() //tech.giveTech('motion sickness') //used to build maps in testing mode + // simulation.isHorizontalFlipped = true + // spawn.setSpawnList(); //picks a couple mobs types for a themed random mob spawns + // spawn.setSpawnList(); //picks a couple mobs types for a themed random mob spawns + // level.levelsCleared = 10 + // level.updateDifficulty() + // tech.giveTech("performance") + // m.maxHealth = m.health = 100000000 + // m.maxEnergy = m.energy = 10000000 + // tech.isRerollDamage = true + // powerUps.research.changeRerolls(99999) + // m.immuneCycle = Infinity //you can't take damage + // tech.tech[297].frequency = 100 + // tech.addJunkTechToPool(0.5) + // m.couplingChange(10) + // m.setField("time dilation") //1 standing wave 2 perfect diamagnetism 3 negative mass 4 molecular assembler 5 plasma torch 6 time dilation 7 metamaterial cloaking 8 pilot wave 9 wormhole 10 grappling hook + // m.energy = 0 + // powerUps.research.count = 3 + // tech.isHookWire = true + // m.energy = 0 + // simulation.molecularMode = 2 + // m.damage(0.1); + // b.giveGuns("nail gun") //0 nail gun 1 shotgun 2 super balls 3 wave 4 missiles 5 grenades 6 spores 7 drones 8 foam 9 harpoon 10 mine 11 laser + // b.giveGuns("harpoon") //0 nail gun 1 shotgun 2 super balls 3 wave 4 missiles 5 grenades 6 spores 7 drones 8 foam 9 harpoon 10 mine 11 laser + // b.giveGuns("laser") //0 nail gun 1 shotgun 2 super balls 3 wave 4 missiles 5 grenades 6 spores 7 drones 8 foam 9 harpoon 10 mine 11 laser + // tech.laserColor = "#fff" + // tech.laserColorAlpha = "rgba(255, 255, 255, 0.5)" + + // b.guns[8].ammo = 100000000 + // requestAnimationFrame(() => { tech.giveTech("non-renewables") }); + // tech.giveTech("dark matter") + // tech.addJunkTechToPool(0.5) + // for (let i = 0; i < 1; ++i) tech.giveTech("pigeonhole principle") + // for (let i = 0; i < 1; ++i) tech.giveTech("generalist") + // m.skin.egg(); + + // for (let i = 0; i < 1; ++i) tech.giveTech("many-worlds") + // requestAnimationFrame(() => { for (let i = 0; i < 1; i++) tech.giveTech("quasiparticles") }); + // requestAnimationFrame(() => { for (let i = 0; i < 1; i++) tech.giveTech("interest") }); + // for (let i = 0; i < 1; i++) tech.giveTech("interest") + // m.lastKillCycle = m.cycle + // for (let i = 0; i < 1; i++) powerUps.directSpawn(450, -50, "warp"); + // for (let i = 0; i < 7; i++) powerUps.directSpawn(m.pos.x + 200, m.pos.y - 250, "research", false); + // spawn.bodyRect(575, -700, 150, 150); //block mob line of site on testing + // level.corridor(); + + level[simulation.isTraining ? "walk" : "initial"]() //normal starting level ************************************************** + + + // for (let i = 0; i < 1; ++i) spawn.powerUpBossBaby(1900, -500) + // for (let i = 0; i < 1; i++) spawn.mantisBoss(1900, -500) + + // for (let i = 0; i < 1; ++i) powerUps.directSpawn(m.pos.x + 50 * Math.random(), m.pos.y + 50 * Math.random(), "entanglement"); + // for (let i = 0; i < 2; ++i) powerUps.directSpawn(m.pos.x + 450, m.pos.y + 50 * Math.random(), "boost"); + // for (let i = 0; i < 100; ++i) powerUps.directSpawn(m.pos.x + 50 * Math.random(), m.pos.y + 50 * Math.random(), "ammo"); + // for (let i = 0; i < 2; i++) powerUps.spawn(player.position.x + Math.random() * 50, player.position.y - Math.random() * 50, "field", false); + //lore testing + // localSettings.isTrainingNotAttempted = true + // simulation.isCheating = false //true; + // for (let i = 0; i < 5; i++) tech.giveTech("undefined") + // lore.techCount = 1 + // level.levelsCleared = 10 + // localSettings.loreCount = 1 //this sets what conversation is heard + // localSettings.levelsClearedLastGame = 10 + // if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + // level.onLevel = -1 //this sets level.levels[level.onLevel] = undefined which is required to run the conversation + // level.null() + // localSettings.isHuman = true + // tech.isNoDraftPause = false //disable pause + // mobs.mobDeaths = 200 //to prevent pacifist mode + // for (let i = 0; i < 13; i++) level.nextLevel(); //jump to final boss + // lore.unlockTesting(); + // tech.giveTech("tinker"); //show junk tech in experiment mode + // m.storeTech() + // powerUps.spawn(m.pos.x, m.pos.y, "entanglement", false); + // for (let i = 0; i < 4; i++) localSettings.difficultyCompleted[i] = true + // localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } else { + spawn.setSpawnList(); //picks a couple mobs types for a themed random mob spawns + // spawn.pickList = ["focuser", "focuser"] + level[level.levels[level.onLevel]](); //picks the current map from the the levels array + if (!simulation.isCheating && !build.isExperimentRun && !simulation.isTraining) { + localSettings.runCount += level.levelsCleared //track the number of total runs locally + localSettings.levelsClearedLastGame = level.levelsCleared + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + } + setupCanvas() + simulation.setupCamera(player.position); + simulation.setZoom(); + level.addToWorld(); //add bodies to game engine + simulation.draw.setPaths(); + b.respawnBots(); + m.resetHistory(); + + if (tech.isForeverDrones) { + if (tech.isDroneRadioactive) { + for (let i = 0; i < tech.isForeverDrones * 0.25; i++) { + b.droneRadioactive({ x: m.pos.x + 30 * (Math.random() - 0.5), y: m.pos.y + 30 * (Math.random() - 0.5) }, 5) + bullet[bullet.length - 1].endCycle = Infinity + } + } else { + for (let i = 0; i < tech.isForeverDrones; i++) { + b.drone({ x: m.pos.x + 30 * (Math.random() - 0.5), y: m.pos.y + 30 * (Math.random() - 0.5) }, 5) + bullet[bullet.length - 1].endCycle = Infinity + } + } + } + if (tech.isDarkMatter) spawn.darkMatter() + for (let i = 0; i < tech.wimpCount; i++) { + spawn.WIMP() + mob[mob.length - 1].isDecoupling = true //so you can find it to remove + for (let j = 0, len = 4; j < len; j++) powerUps.spawn(level.exit.x + 100 * (Math.random() - 0.5), level.exit.y - 100 + 100 * (Math.random() - 0.5), "research", false) + } + + if (m.plasmaBall) m.plasmaBall.fire() + if (localSettings.entanglement && localSettings.entanglement.levelName === level.levels[level.onLevel]) { + const flip = localSettings.entanglement.isHorizontalFlipped === simulation.isHorizontalFlipped ? 1 : -1 + powerUps.directSpawn(flip * localSettings.entanglement.position.x, localSettings.entanglement.position.y, "entanglement", false); + } + level.newLevelOrPhase() + if (simulation.isTraining) { + simulation.difficultyMode = 1 + } else { + simulation.inGameConsole(`level.onLevel = "${level.levels[level.onLevel]}"`); + document.title = "n-gon: " + level.levelAnnounce(); + } + + level.setConstraints() + if (!localSettings.isHideHUD) { + requestAnimationFrame(() => { + //grow and get bright + document.getElementById("right-HUD-constraint").style.opacity = 1 + document.getElementById("right-HUD-constraint").style.fontSize = "23px" + document.getElementById("right-HUD-constraint").style.top = simulation.difficultyMode > 6 ? "6px" : "9px" + setTimeout(() => { + if (m.alive) { + //fade to background + document.getElementById("right-HUD-constraint").style.opacity = 0.35 + document.getElementById("right-HUD-constraint").style.fontSize = "20px" + document.getElementById("right-HUD-constraint").style.top = "12px" + } + }, 5000); + }); + } + }, + newLevelOrPhase() { //runs on each new level but also on final boss phases + //used for generalist and pigeonhole principle + tech.cancelTechCount = 0 + tech.tokamakHealCount = 0 + tech.buffedGun++ + if (tech.buffedGun > b.inventory.length - 1) tech.buffedGun = 0; + if ((tech.isGunCycle || tech.isGunChoice) && (b.activeGun !== null && b.activeGun !== undefined) && b.inventory.length) { + b.inventoryGun = tech.buffedGun; + simulation.switchGun(); + } + // if (tech.isGunChoice && Number.isInteger(tech.buffedGun) && b.inventory.length) { + // var gun = b.guns[b.inventory[tech.buffedGun]].name + // simulation.inGameConsole(`pigeonhole principle: ${(1 + 0.4 * Math.max(0, b.inventory.length)).toFixed(2)}x damage for ${gun}`, 600); + // } + if (tech.isSwitchReality && level.levelsCleared !== 0) { + simulation.inGameConsole(`simulation.amplitude = ${Math.random()}`); + m.switchWorlds("many-worlds") + simulation.trails() + powerUps.spawn(player.position.x + 50, player.position.y - Math.random() * 50, "tech", false); + } + if (tech.isHealLowHealth) { + const len = tech.isEnergyHealth ? 5 * Math.max(0, m.maxEnergy - m.energy) : 5 * Math.max(0, m.maxHealth - m.health) + for (let i = 0; i < len; i++) powerUps.spawn(player.position.x + 90 * (Math.random() - 0.5), player.position.y + 90 * (Math.random() - 0.5), "heal", false); + } + if (tech.interestRate > 0) { + // const rate = ((level[level.levels[level.onLevel]].name === "final" || level[level.levels[level.onLevel]].name === "subway") ? 1 / 3 : 1) * tech.interestRate //this effect triggers extra times on these final levels + let rate = tech.interestRate + if (level.onLevel < level.levels.length - 1) {//make sure it's not on the lore level which has an undefined name + const levelName = level.levels[level.onLevel] + if (levelName === "final" || levelName === "subway") rate *= 1 / 3 + } + + let ammoSum = 0 + for (let i = 0; i < b.inventory.length; i++) { + if (b.guns[b.inventory[i]].ammo !== Infinity) ammoSum += b.guns[b.inventory[i]].ammo / b.guns[b.inventory[i]].ammoPack + } + if (ammoSum > 0 && b.inventory.length > 0) { + const amount = Math.ceil(rate * ammoSum / b.inventory.length) + powerUps.spawnDelay("ammo", amount, 4); + simulation.inGameConsole(`${(rate * 100).toFixed(0)}% interest on ammo = ${amount > 20 ? amount + powerUps.orb.ammo(1) : powerUps.orb.ammo(amount)}`) + } + + // if (b.activeGun !== null && b.activeGun !== undefined && b.guns[b.activeGun].ammo !== Infinity) { + // const ammoPerOrb = b.guns[b.activeGun].ammoPack + // const a = Math.ceil(rate * b.guns[b.activeGun].ammo / ammoPerOrb) + // powerUps.spawnDelay("ammo", a, 4); + // simulation.inGameConsole(`${(rate * 100).toFixed(0)}% interest on ammo = ${a > 20 ? a + powerUps.orb.ammo(1) : powerUps.orb.ammo(a)}`) + // } + if (powerUps.research.count > 0) { + const r = Math.ceil(rate * powerUps.research.count) + simulation.inGameConsole(`${(rate * 100).toFixed(0)}% interest on research = ${r > 20 ? r + powerUps.orb.research(1) : powerUps.orb.research(r)}`) + powerUps.spawnDelay("research", r, 4); + } + if (m.coupling > 0) { + const c = Math.ceil(rate * m.coupling) + powerUps.spawnDelay("coupling", c, 4); + simulation.inGameConsole(`${(rate * 100).toFixed(0)}% interest on coupling = ${c > 20 ? c + powerUps.orb.coupling(1) : powerUps.orb.coupling(c)}`) + } + const healPerOrb = (powerUps.heal.size() / 40 / (simulation.healScale ** 0.25)) ** 2 + const h = Math.ceil(rate * m.health / healPerOrb) + powerUps.spawnDelay("heal", h, 4); + simulation.inGameConsole(`${(rate * 100).toFixed(0)}% interest on health = ${h > 20 ? h + powerUps.orb.heal(1) : powerUps.orb.heal(h)}`) + + // trying to spawn smaller heals + // const healPerOrb = (powerUps.heal.size() / 40 / (simulation.healScale ** 0.25)) ** 2 + // console.log(healPerOrb) + // let h = tech.interestRate * m.health / healPerOrb + // console.log(tech.interestRate, m.health, healPerOrb, h) + // const overHeal = h - Math.floor(h) + // powerUps.spawn(m.pos.x, m.pos.y, "heal", true, null, Math.max(0.25, overHeal) * 40 * (simulation.healScale ** 0.25)) + // if (h > healPerOrb) powerUps.spawnDelay("heal", h); + // simulation.inGameConsole(`${(Math.ceil(tech.interestRate * 100)).toFixed(0)}% interest on health = ${h > 20 ? h + powerUps.orb.heal(1) : powerUps.orb.heal(h)}`) + } + if (tech.isEjectOld) { + let index = null //find oldest tech that you have + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].count > 0 && !tech.tech[i].isInstant) { + index = i + } + } + if (index) { //eject it + const effect = Math.pow(1.1, tech.tech[index].count) + simulation.inGameConsole(`${(effect).toFixed(2)}x damage //from obsolescence`, 360) + tech.damage *= effect + powerUps.ejectTech(index) + } + } + }, + trainingText(say) { + simulation.lastLogTime = 0; //clear previous messages + simulation.isTextLogOpen = true + simulation.inGameConsole(`supervised.learning(${(Date.now() / 1000).toFixed(0)} s):
${say}
`, Infinity) + simulation.isTextLogOpen = false + }, + trainingBackgroundColor: "#e1e1e1", + custom() { }, + customTopLayer() { }, + updateDifficulty() { + simulation.difficulty = level.levelsCleared * simulation.difficultyMode + if (simulation.isTraining) { + simulation.difficulty = 1 + simulation.difficultyMode = 1 + m.dmgScale = 1 + simulation.dmgScale = 1//Math.max(0.1, 0.25 * level.levelsCleared * scale) //damage done by mobs scales with total levels //a bigger number means the player takes more damage + } else { + const scale = simulation.difficultyMode > 3 ? 2 : 1 + m.dmgScale = Math.pow(0.85, level.levelsCleared * scale) + simulation.dmgScale = Math.max(0.1, 0.25 * level.levelsCleared * scale) //damage done by mobs scales with total levels //a bigger number means the player takes more damage + if (simulation.difficultyMode > 5) { + m.dmgScale *= 0.5 + simulation.dmgScale *= 2 + } + } + simulation.healScale = 1 / (1 + simulation.difficulty * 0.043) //a higher denominator makes for lower heals // m.health += heal * simulation.healScale; + if (simulation.difficultyMode === 1) { + simulation.accelScale = 1.1 + simulation.CDScale = 0.9 + } else { + simulation.accelScale = Math.min(6, Math.pow(1.024, simulation.difficulty)) + simulation.CDScale = Math.max(0.15, Math.pow(0.964, simulation.difficulty)) + } + }, + constraintIndex: 0, + setConstraints() { + //populate array with possible constraints and reset constraints + level.constraintDescription1 = level.constraintDescription2 = "" + const possible = [] + for (let i = 0; i < level.constraint.length; i++) { + level.constraint[i].remove() + possible.push(i) + } + if (level.levels[level.onLevel] !== "final" && level.levels[level.onLevel] !== "null" && level.levels[level.onLevel] !== "initial" && !simulation.isTraining && m.alive && level.levelsCleared) { + if (simulation.difficultyMode > 4 && possible.length) { + //choose a random constraint from possible array and remove it from that array + // level.constraintIndex = 0 //REMOVE THIS FROM LIVE GAME + level.constraint[level.constraintIndex].effect() + possible.splice(level.constraintIndex, 1) + //generate text to describe the active constraints for the pause menu + level.constraintDescription1 = level.constraint[level.constraintIndex].description + level.constraintIndex++ + if (level.constraintIndex > level.constraint.length - 1) level.constraintIndex = 0 + + if (simulation.difficultyMode > 6 && possible.length) { + level.constraint[level.constraintIndex].effect() + possible.splice(level.constraintIndex, 1) + level.constraintDescription2 += level.constraint[level.constraintIndex].description + level.constraintIndex++ + if (level.constraintIndex > level.constraint.length - 1) level.constraintIndex = 0 + } + document.getElementById("right-HUD-constraint").style.display = "block"; + } else { + document.getElementById("right-HUD-constraint").style.display = "none"; + } + } else { + document.getElementById("right-HUD-constraint").style.display = "none"; + } + //update HUD with constraints + let text = `${level.constraintDescription1}` + if (level.constraintDescription1) simulation.inGameConsole(`constraint: ${level.constraintDescription1}`) + if (simulation.difficultyMode > 6 && level.constraintDescription2) { + text += `
${level.constraintDescription2}` + if (level.constraintDescription2) simulation.inGameConsole(`constraint: ${level.constraintDescription2}`) + } + document.getElementById("right-HUD-constraint").innerHTML = text + + if (level.constraintDescription1) { + if (level.constraintDescription2) { + document.getElementById("right-HUD").style.top = "80px"; + } else { + document.getElementById("right-HUD").style.top = "57px"; //make room for tech list in "right-HUD" + } + } else { + document.getElementById("right-HUD").style.top = "15px"; + } + }, + constraintDescription1: "", //used in pause menu and console + constraintDescription2: "", + constraint: [ + { + description: "0.5x healing", + effect() { + level.isLowHeal = true + }, + remove() { + level.isLowHeal = false + } + }, + { + description: "no pause while choosing", + effect() { + level.isNoPause = true + }, + remove() { + level.isNoPause = false + } + }, + { + description: "no health bars", + effect() { + mobs.healthBar = () => { } + level.isHideHealth = true + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + }, + remove() { + mobs.healthBar = mobs.defaultHealthBar + level.isHideHealth = false + if (tech.isEnergyHealth) { + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + } else if (!level.isHideHealth) { + document.getElementById("health").style.display = "inline" + document.getElementById("health-bg").style.display = "inline" + } + } + }, + { + description: "0.5x energy regen", + effect() { + level.isReducedRegen = 0.5 + }, + remove() { + level.isReducedRegen = 1 + } + }, + { + description: "0.5x max health", + effect() { + level.isReducedHealth = true + m.setMaxHealth() + }, + remove() { + if (level.isReducedHealth) { + level.isReducedHealth = false + m.setMaxHealth() + m.addHealth(level.reducedHealthLost); + level.reducedHealthLost = 0 + } else { + level.isReducedHealth = false + } + + } + }, + { + description: "after 40 seconds spawn WIMPs", + effect() { + simulation.ephemera.push({ + name: "WIMPS", + time: 0, + levelName: level.levels[level.onLevel], + do() { + this.time++ + if (level.levels[level.onLevel] === this.levelName) { + if (this.time > 2400 && !(this.time % 420)) spawn.WIMP(level.enter.x, level.enter.y) + } else { + simulation.removeEphemera(this.name); + } + }, + }) + }, + remove() { + + } + }, + { + description: "0.3x damage after getting power ups", + effect() { + level.isNoDamage = true + level.noDamageCycle = 0 + }, + remove() { + level.isNoDamage = false + level.noDamageCycle = 0 + } + }, + { + description: "mobs heal after you take damage", + effect() { + level.isMobHealPlayerDamage = true + }, + remove() { + level.isMobHealPlayerDamage = false + } + }, + { + description: "mob death heals nearby mobs", + effect() { + level.isMobDeathHeal = true + }, + remove() { + level.isMobDeathHeal = false + } + }, + // { + // description: "full damage taken after boss dies", + // // description: "after boss dies damage taken = 1", + // effect() { + // level.noDefenseSetting = 1 //defense goes to zero once equal to 2 + // }, + // remove() { + // level.noDefenseSetting = 0 + // } + // }, + { + description: "4x shielded mobs", + effect() { + level.isMobShields = true + }, + remove() { + level.isMobShields = false + } + }, + { + description: "40% JUNK chance", + effect() { + level.junkAdded = 0.4 + }, + remove() { + level.junkAdded = 0 + } + }, + { + description: "-1 choice", + effect() { + level.fewerChoices = true + }, + remove() { + level.fewerChoices = false + } + }, + { + description: "power ups in stasis", + effect() { + level.isNextLevelPowerUps = true + //remove all current power ups + for (let i = powerUp.length - 1; i > -1; i--) { + powerUps.powerUpStorage.push({ name: powerUp[i].name, size: powerUp[i].size }) + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1) + } + }, + remove() { + level.isNextLevelPowerUps = false + if (powerUps.powerUpStorage.length) { + const delay = 5 + let i = 0 + let cycle = () => { + if (powerUps.powerUpStorage.length && m.alive && powerUp.length < 300) { + requestAnimationFrame(cycle); + if (!simulation.paused && !simulation.isChoosing) { + if (!(simulation.cycle % delay)) { + const where = { x: m.pos.x + 70 * (Math.random() - 0.5), y: m.pos.y + 70 * (Math.random() - 0.5) } + powerUps.directSpawn(where.x, where.y, powerUps.powerUpStorage[i].name, true, powerUps.powerUpStorage[i].size); + powerUps.powerUpStorage.splice(i, 1); + } + } + } else { + powerUps.powerUpStorage = [] + } + } + requestAnimationFrame(cycle); + } + } + }, + { + description: "33% of mobs respawn", + effect() { + level.isMobRespawn = true + }, + remove() { + level.isMobRespawn = false + } + }, + { + description: "0 duplication", + effect() { + level.isNoDuplicate = true + }, + remove() { + level.isNoDuplicate = false + } + }, + { + description: "2x ammo cost", + effect() { + level.is2xAmmo = true + }, + remove() { + level.is2xAmmo = false + } + }, + { + description: "0.5x max energy", + effect() { + level.isReducedEnergy = true + m.setMaxEnergy() + }, + remove() { + if (level.isReducedEnergy) { + level.isReducedEnergy = false + m.setMaxEnergy() + } else { + level.isReducedEnergy = false + } + + } + }, + { + description: "slow bots", + effect() { + level.isSlowBots = true + b.clearPermanentBots(); + b.respawnBots(); + }, + remove() { + if (level.isSlowBots) { + level.isSlowBots = false + b.clearPermanentBots(); + b.respawnBots(); + } else { + level.isSlowBots = false + } + + } + }, + ], + isMobShields: false, + junkAdded: 0, + isNextLevelPowerUps: false, + isMobRespawn: false, + fewerChoices: false, + isNoDuplicate: false, + is2xAmmo: false, + isReducedEnergy: false, + isSlowBots: false, + // noDefenseSetting: 0, + isMobDeathHeal: false, + isMobHealPlayerDamage: false, + isNoDamage: false, + noDamageCycle: 0, + reducedHealthLost: 0, + isReducedHealth: false, + isReducedRegen: 1, + isHideHealth: false, + isNoPause: false, + isLowHeal: false, + levelAnnounce() { + const cheating = simulation.isCheating ? "(testing)" : "" + if (level.levelsCleared === 0) { + return `initial ${cheating}`; + } else { + return `${level.levelsCleared} ${level.levels[level.onLevel]} ${cheating}` + } + }, + announceMobTypes() { + simulation.inGameConsole(`spawn.${spawn.pickList[0]}(x,y)`) + simulation.inGameConsole(`spawn.${spawn.pickList[1]}(x,y)`) + }, + disableExit: false, + nextLevel() { + if (!level.disableExit) { + level.levelsCleared++; + level.onLevel++; //cycles map to next level + level.updateDifficulty() + + if (simulation.isTraining) { + if (level.onLevel > level.levels.length - 1) { //if all training levels are completed + level.disableExit = true + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + document.getElementById("defense-bar").style.display = "none" + document.getElementById("damage-bar").style.display = "none" + document.getElementById("text-log").style.display = "none" + document.getElementById("fade-out").style.opacity = 1; //slowly fades out + setTimeout(function () { + simulation.paused = true; + level.disableExit = false; + engine.world.bodies.forEach((body) => { + Matter.Composite.remove(engine.world, body) + }) + Engine.clear(engine); + simulation.splashReturn(); + }, 6000); + return + } + } else { + if (level.onLevel > level.levels.length - 1) level.onLevel = 0; + } + //reset lost tech display + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].isLost) tech.tech[i].isLost = false; + } + tech.isDeathAvoidedThisLevel = false; + simulation.updateTechHUD(); + simulation.clearNow = true; //triggers in simulation.clearMap to remove all physics bodies and setup for new map + + //pop up new level info screen for a few seconds //|| level.levels[level.onLevel] === "subway" + if (!localSettings.isHideHUD && m.alive && (level.levels[level.onLevel] === "final" || level.levels[level.onLevel] === "reactor")) { + // if (!localSettings.isHideHUD && m.alive) { + //pause + if (!simulation.paused) { + simulation.paused = true; + simulation.isChoosing = true; //stops p from un pausing on key down + } + //build level info + document.getElementById("choose-grid").style.gridTemplateColumns = "250px" + //onclick="level.unPause()" + // if (level.levels[level.onLevel] === "final") { //|| level.levels[level.onLevel] === "reactor" + let text = `
` + for (let i = 0; i < level.levels.length; i++) { + if (i < level.levelsCleared) { + text += `
${level.levels[i]}
` + } else if (i === level.levelsCleared) { + // text += `
${level.levels[i]}
` + text += `
${level.levels[i]}
` + } else { + text += `
${level.levels[i]}
` //blurry text + // ???????? text + // text += `
` + // for (let j = 0; j < level.levels[i].length; j++) text += `?` + // text += `
` + } + } + text += `
` + + document.getElementById("choose-grid").innerHTML = text + //show level info + document.getElementById("choose-grid").style.opacity = "1" + document.getElementById("choose-grid").style.transitionDuration = "0.25s"; //how long is the fade in on + document.getElementById("choose-grid").style.visibility = "visible" + // } + simulation.draw.cons(); + simulation.draw.body(); + level.customTopLayer(); + let count = countMax = simulation.testing ? 0 : 240 + let newLevelDraw = () => { + count-- + if (count > 0) { + requestAnimationFrame(newLevelDraw); + } else { //unpause + // document.body.style.cursor = "none"; + if (m.immuneCycle < m.cycle + 15) m.immuneCycle = m.cycle + 30; //player is immune to damage for 30 cycles + if (simulation.paused) requestAnimationFrame(cycle); + if (m.alive) simulation.paused = false; + simulation.isChoosing = false; //stops p from un pausing on key down + build.unPauseGrid() + document.getElementById("choose-grid").style.opacity = "0" + setTimeout(() => { + document.getElementById("choose-grid").style.visibility = "hidden" + }, 1000); + } + //draw + simulation.wipe(); + m.look(); + simulation.camera(); + const scale = 15 + ctx.setLineDash([scale * (countMax - count), scale * count]); + simulation.draw.wireFrame(); + ctx.setLineDash([]); + ctx.restore(); + simulation.drawCursor(); + } + requestAnimationFrame(newLevelDraw); + } + } + }, + unPause() { + if (m.immuneCycle < m.cycle + 15) m.immuneCycle = m.cycle + 30; //player is immune to damage for 30 cycles + if (simulation.paused) requestAnimationFrame(cycle); + if (m.alive) simulation.paused = false; + simulation.isChoosing = false; //stops p from un pausing on key down + build.unPauseGrid() + document.getElementById("choose-grid").style.opacity = "0" + document.getElementById("choose-grid").style.visibility = "hidden" + // setTimeout(() => { + // }, 1000); + }, + populateLevels() { //run a second time if URL is loaded + if (document.getElementById("banned").value) { //remove levels from ban list in settings + const banList = document.getElementById("banned").value.replace(/,/g, ' ').replace(/\s\s+/g, ' ').replace(/[^\w\s]/g, '') //replace commas with spaces, replace double spaces with single, remove strange symbols + const remove = banList.split(" "); + // console.log('remove these', remove) + // console.log('community levels before', level.communityLevels) + for (let i = 0; i < remove.length; i++) { + const index = level.communityLevels.indexOf(remove[i]) + if (index !== -1) { + level.communityLevels.splice(index, 1); + // console.log('removed level:', remove[i]) + requestAnimationFrame(() => { simulation.inGameConsole(`banned level: ${remove[i]}`); }); + } + } + // console.log('community levels after', level.communityLevels) + // console.log('Landgreen levels before', level.playableLevels) + for (let i = 0; i < remove.length; i++) { + if (level.playableLevels.length + level.communityLevels.length * simulation.isCommunityMaps < 10) break //can't remove too many levels + const index = level.playableLevels.indexOf(remove[i]) + if (index !== -1) { + level.playableLevels.splice(index, 1); + // console.log('removed level:', remove[i]) + requestAnimationFrame(() => { simulation.inGameConsole(`banned level: ${remove[i]}`); }); + } + } + // console.log('Landgreen levels after', level.playableLevels) + } + + if (document.getElementById("seed").value) { //check for player entered seed in settings + Math.initialSeed = String(document.getElementById("seed").value) + Math.seed = Math.abs(Math.hash(Math.initialSeed)) //update randomizer seed in case the player changed it + } + + if (simulation.isTraining) { + simulation.isHorizontalFlipped = false + level.levels = level.trainingLevels.slice(0) //copy array, not by just by assignment + if (simulation.isCommunityMaps) level.trainingLevels.push("diamagnetism") + } else { //add remove and shuffle levels for the normal game (not training levels) + level.levels = level.playableLevels.slice(0) //copy array, not by just by assignment + if (simulation.isCommunityMaps) { + level.levels = level.levels.concat(level.communityLevels) + simulation.isHorizontalFlipped = false; + } else { + simulation.isHorizontalFlipped = (Math.seededRandom() < 0.5) ? true : false //if true, some maps are flipped horizontally + } + level.levels = shuffle(level.levels); //shuffles order of maps with seeded random + level.levels.length = 9 //remove any extra levels past 9 + pick = ["interferometer", "factory", "reservoir"] + level.levels.splice(Math.floor(Math.seededRandom(level.levels.length * 0.6, level.levels.length)), 0, pick[Math.floor(Math.random() * pick.length)]); //add level to the back half of the randomized levels list + + level.levels.splice(Math.floor(Math.seededRandom(level.levels.length * 0.6, level.levels.length)), 0, "reactor"); //add level to the back half of the randomized levels list + if (!build.isExperimentSelection || (build.hasExperimentalMode && !simulation.isCheating)) { //experimental mode is endless, unless you only have an experiment Tech + level.levels.unshift("initial"); //add level to the start of the randomized levels list + level.levels.push("subway"); //add level to the end of the randomized levels list + level.levels.push("final"); //add level to the end of the randomized levels list + } + } + //set seeded random lists of mobs and bosses + spawn.mobTypeSpawnOrder = [] + for (let i = 0; i < level.levels.length; i++) spawn.mobTypeSpawnOrder.push(spawn.fullPickList[Math.floor(Math.seededRandom(0, spawn.fullPickList.length))]) + spawn.bossTypeSpawnOrder = [] + for (let i = 0; i < level.levels.length * 2; i++) spawn.bossTypeSpawnOrder.push(spawn.randomBossList[Math.floor(Math.seededRandom(0, spawn.randomBossList.length))]) + }, + flipHorizontal() { + const flipX = (who) => { + for (let i = 0, len = who.length; i < len; i++) { + Matter.Body.setPosition(who[i], { + x: -who[i].position.x, + y: who[i].position.y + }) + } + } + flipX(map) + flipX(body) + flipX(mob) + flipX(powerUp) + for (let i = 0, len = cons.length; i < len; i++) { + cons[i].pointA.x *= -1 + cons[i].pointB.x *= -1 + } + for (let i = 0, len = consBB.length; i < len; i++) { + consBB[i].pointA.x *= -1 + consBB[i].pointB.x *= -1 + } + level.exit.x = -level.exit.x - 100 //minus the 100 because of the width of the graphic + }, + flipVertical() { + const flipY = (who) => { + for (let i = 0, len = who.length; i < len; i++) { + Matter.Body.setPosition(who[i], { x: who[i].position.x, y: -who[i].position.y - player.position.y }) + } + } + flipY(map) + flipY(body) + flipY(mob) + flipY(powerUp) + Matter.Body.setPosition(player, { x: player.position.x, y: -2 * player.position.y }) + + // for (let i = 0, len = cons.length; i < len; i++) { + // cons[i].pointA.x *= -1 + // cons[i].pointB.x *= -1 + // } + // for (let i = 0, len = consBB.length; i < len; i++) { + // consBB[i].pointA.x *= -1 + // consBB[i].pointB.x *= -1 + // } + // level.exit.x = -level.exit.x - 100 //minus the 100 because of the width of the graphic + }, + exitCount: 0, + setPosToSpawn(xPos, yPos) { + m.spawnPos.x = m.pos.x = xPos; + m.spawnPos.y = m.pos.y = yPos; + level.enter.x = m.spawnPos.x - 50; + level.enter.y = m.spawnPos.y + 20; + m.transX = m.transSmoothX = canvas.width2 - m.pos.x; + m.transY = m.transSmoothY = canvas.height2 - m.pos.y; + m.Vx = m.spawnVel.x; + m.Vy = m.spawnVel.y; + player.force.x = 0; + player.force.y = 0; + Matter.Body.setPosition(player, m.spawnPos); + Matter.Body.setVelocity(player, m.spawnVel); + //makes perfect diamagnetism tech: Lenz's law show up in the right spot at the start of a level + m.fieldPosition = { + x: m.pos.x, + y: m.pos.y + } + m.fieldAngle = m.angle + }, + enter: { + x: 0, + y: 0, + draw() { + ctx.beginPath(); + ctx.moveTo(level.enter.x, level.enter.y + 30); + ctx.lineTo(level.enter.x, level.enter.y - 80); + ctx.bezierCurveTo(level.enter.x, level.enter.y - 170, level.enter.x + 100, level.enter.y - 170, level.enter.x + 100, level.enter.y - 80); + ctx.lineTo(level.enter.x + 100, level.enter.y + 30); + ctx.lineTo(level.enter.x, level.enter.y + 30); + ctx.fillStyle = "#ccc"; + ctx.fill(); + } + }, + exit: { + x: 0, + y: 0, + drawAndCheck() { + if ( //check + player.position.x > level.exit.x && + player.position.x < level.exit.x + 100 && + player.position.y > level.exit.y - 150 && + player.position.y < level.exit.y - 0 && + player.velocity.y < 0.15 + ) { + // level.exitCount += input.down ? 8 : 2 + level.exitCount += 3 + } else if (level.exitCount > 0) { + level.exitCount -= 3 + } + + ctx.beginPath(); + ctx.moveTo(level.exit.x, level.exit.y + 30); + ctx.lineTo(level.exit.x, level.exit.y - 80); + ctx.bezierCurveTo(level.exit.x, level.exit.y - 170, level.exit.x + 100, level.exit.y - 170, level.exit.x + 100, level.exit.y - 80); + ctx.lineTo(level.exit.x + 100, level.exit.y + 30); + ctx.lineTo(level.exit.x, level.exit.y + 30); + ctx.fillStyle = "#0ff"; + ctx.fill(); + + if (level.exitCount > 0) { //stroke outline of door from 2 sides, grows with count + ctx.beginPath(); + ctx.moveTo(level.exit.x, level.exit.y + 40); + ctx.lineTo(level.exit.x, level.exit.y - 80); + ctx.bezierCurveTo(level.exit.x, level.exit.y - 148, level.exit.x + 50, level.exit.y - 148, level.exit.x + 50, level.exit.y - 148); + ctx.moveTo(level.exit.x + 100, level.exit.y + 40); + ctx.lineTo(level.exit.x + 100, level.exit.y - 80); + ctx.bezierCurveTo(level.exit.x + 100, level.exit.y - 148, level.exit.x + 50, level.exit.y - 148, level.exit.x + 50, level.exit.y - 148); + ctx.setLineDash([200, 200]); + ctx.lineDashOffset = Math.max(-15, 185 - 2.1 * level.exitCount) + ctx.strokeStyle = "#444" + ctx.lineWidth = 2 + ctx.stroke(); + ctx.setLineDash([0, 0]); + + if (level.exitCount > 100) { + level.exitCount = 0 + + //prompt an option to do the training levels or continue to the normal game + if (!simulation.isChoosing && m.alive && !simulation.isTraining && !simulation.isCheating && b.inventory.length === 0 && level.levelsCleared === 0 && localSettings.isTrainingNotAttempted) { + //pause + if (!simulation.paused) { + simulation.paused = true; + simulation.isChoosing = true; //stops p from un pausing on key down + + document.body.style.cursor = "auto"; + document.getElementById("choose-grid").style.pointerEvents = "auto"; + document.getElementById("choose-grid").style.transitionDuration = "0s"; + } + //build level info + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + document.getElementById("choose-grid").style.gridTemplateColumns = "350px" + let text = ` +
+

training

+ Begin the guided tutorial that shows you how to use your ${powerUps.orb.field()} and ${powerUps.orb.gun()}. +
+
+

play

+ Begin the standard game where you progress through 13 random levels and beat the final boss. +
` + document.getElementById("choose-grid").innerHTML = text + //show level info + document.getElementById("choose-grid").style.opacity = "1" + document.getElementById("choose-grid").style.transitionDuration = "0.25s"; //how long is the fade in on + document.getElementById("choose-grid").style.visibility = "visible" + document.getElementById("choose-training").addEventListener("click", () => { + level.unPause() + document.body.style.cursor = "none"; + simulation.isTraining = true + level.levelsCleared--; + level.onLevel-- + simulation.isHorizontalFlipped = false + level.levels = level.trainingLevels.slice(0) //copy array, not by just by assignment + level.nextLevel() + //reset hide image style + if (localSettings.isHideImages) { + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + } else { + document.getElementById("choose-grid").classList.add('choose-grid'); + document.getElementById("choose-grid").classList.remove('choose-grid-no-images'); + } + }); + document.getElementById("choose-unPause").addEventListener("click", () => { + level.unPause() + document.body.style.cursor = "none"; + level.nextLevel() + //reset hide image style + if (localSettings.isHideImages) { + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + } else { + document.getElementById("choose-grid").classList.add('choose-grid'); + document.getElementById("choose-grid").classList.remove('choose-grid-no-images'); + } + }); + requestAnimationFrame(() => { + ctx.fillStyle = `rgba(150,150,150,0.9)`; //`rgba(221,221,221,0.6)`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + }); + } else { //advance to next level + level.nextLevel() + } + } + } + }, + // draw() { + // ctx.beginPath(); + // ctx.moveTo(level.exit.x, level.exit.y + 30); + // ctx.lineTo(level.exit.x, level.exit.y - 80); + // ctx.bezierCurveTo(level.exit.x, level.exit.y - 170, level.exit.x + 100, level.exit.y - 170, level.exit.x + 100, level.exit.y - 80); + // ctx.lineTo(level.exit.x + 100, level.exit.y + 30); + // ctx.lineTo(level.exit.x, level.exit.y + 30); + // ctx.fillStyle = "#0ff"; + // ctx.fill(); + // } + }, + addToWorld() { //needs to be run to put bodies into the world + for (let i = 0; i < map.length; i++) { + map[i].collisionFilter.category = cat.map; + map[i].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(map[i], true); //make static + Composite.add(engine.world, map[i]); //add to world + } + }, + spinner(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0) { + x += width / 2 + y += height / 2 + const who = body[body.length] = Bodies.rectangle(x, y, width, height, { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + isNotHoldable: true, + frictionAir: frictionAir, + friction: 1, + frictionStatic: 1, + restitution: 0, + }); + Matter.Body.setAngle(who, angle) + Matter.Body.setAngularVelocity(who, angularVelocity); + Matter.Body.setDensity(who, density) + Composite.add(engine.world, who); //add to world + who.classType = "body" + + const constraint = Constraint.create({ //fix rotor in place, but allow rotation + pointA: { + x: who.position.x, + y: who.position.y + }, + bodyB: who, + stiffness: 1, + damping: 1 + }); + Composite.add(engine.world, constraint); + return constraint + }, + rotor(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + x += width / 2 + y += height / 2 + const who = body[body.length] = Bodies.rectangle(x, y, width, height, { + isRotor: true, + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + isNotHoldable: true, + frictionAir: frictionAir, + friction: 1, + frictionStatic: 1, + restitution: 0, + rotationForce: rotationForce, + }); + Matter.Body.setAngle(who, angle) + Matter.Body.setAngularVelocity(who, angularVelocity); + + Matter.Body.setDensity(who, density) + const constraint = Constraint.create({ //fix rotor in place, but allow rotation + pointA: { + x: who.position.x, + y: who.position.y + }, + bodyB: who, + stiffness: 1, + damping: 1 + }); + Composite.add(engine.world, constraint); + who.center = { + x: who.position.x, + y: who.position.y + } + who.rotate = function () { + if (!m.isTimeDilated) { + Matter.Body.applyForce(this, { + x: this.position.x + 100, + y: this.position.y + 100 + }, { + x: this.rotationForce * this.mass, + y: 0 + }) + } else { + Matter.Body.setAngularVelocity(this, 0); + } + } + // if (rotate) { + // rotor.rotate = function() { + // if (!m.isTimeDilated) { + // Matter.Body.applyForce(rotor, { + // x: rotor.position.x + 100, + // y: rotor.position.y + 100 + // }, { + // x: rotate * rotor.mass, + // y: 0 + // }) + // } else { + // Matter.Body.setAngularVelocity(rotor, 0); + // } + // } + // } + + Composite.add(engine.world, who); //add to world + who.classType = "body" + + return who + }, + boost(x, y, speed = 1000, angle = Math.PI / 2) { //height is how high the player will be flung above y + if (angle !== Math.PI / 2) { //angle !== 3 * Math.PI / 2 + angle *= -1 + who = map[map.length] = Matter.Bodies.fromVertices(x + 50, y + 35, Vertices.fromPath("80 40 -80 40 -50 -40 50 -40"), { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + query() { + // check for collisions + const rayVector = Vector.add(this.position, Vector.rotate({ x: 100, y: 0 }, angle)) + query = (who) => { + const list = Matter.Query.ray(who, this.position, rayVector, 100) + if (list.length > 0) { + Matter.Body.setVelocity(list[0].bodyA, Vector.rotate({ x: 1.21 * Math.sqrt(Math.abs(speed)), y: 0 }, angle)); + } + } + query(body) + query(mob) + query(bullet) + query(powerUp) + //player collision + const list = Matter.Query.ray([player], this.position, rayVector, 100) + if (list.length > 0) { + Matter.Body.setVelocity(player, Vector.rotate({ x: 1.21 * Math.sqrt(Math.abs(speed)), y: 0 }, angle)); + m.buttonCD_jump = 0; // reset short jump counter to prevent short jumps on boosts + m.hardLandCD = 0 // disable hard landing + } + + //draw + const v1 = this.vertices[0] + const v2 = this.vertices[1] + let unit = Vector.rotate({ x: 60, y: 0 }, angle) + let v3 = Vector.add(v2, unit) + let v4 = Vector.add(v1, unit) + ctx.beginPath(); + ctx.moveTo(v1.x, v1.y) + ctx.lineTo(v2.x, v2.y) + ctx.lineTo(v3.x, v3.y) + ctx.lineTo(v4.x, v4.y) + ctx.fillStyle = "rgba(200,0,255,0.05)"; + ctx.fill() + unit = Vector.rotate({ x: 20, y: 0 }, angle) + v3 = Vector.add(v2, unit) + v4 = Vector.add(v1, unit) + ctx.beginPath(); + ctx.moveTo(v1.x, v1.y) + ctx.lineTo(v2.x, v2.y) + ctx.lineTo(v3.x, v3.y) + ctx.lineTo(v4.x, v4.y) + ctx.fillStyle = "rgba(200,0,255,0.15)"; + ctx.fill() + }, + }); + Matter.Body.rotate(who, angle + Math.PI / 2); + return who + } else { + who = map[map.length] = Matter.Bodies.fromVertices(x + 50, y + 35, Vertices.fromPath("120 40 -120 40 -50 -40 50 -40"), { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + boostBounds: { + min: { + x: x, + y: y - 20 + }, + max: { + x: x + 100, + y: y + } + }, + query() { + // check for collisions + query = (who) => { + if (Matter.Query.region(who, this.boostBounds).length > 0) { + list = Matter.Query.region(who, this.boostBounds) + Matter.Body.setVelocity(list[0], { + x: list[0].velocity.x + (Math.random() - 0.5) * 2.5, //add a bit of horizontal drift to reduce endless bounces + y: -1.21 * Math.sqrt(Math.abs(speed)) //give a upwards velocity + }); + } + } + query(body) + query(mob) + query(bullet) + query(powerUp) + //player collision + if (Matter.Query.region([player], this.boostBounds).length > 0 && !input.down) { + m.buttonCD_jump = 0; // reset short jump counter to prevent short jumps on boosts + m.hardLandCD = 0 // disable hard landing + if (player.velocity.y > 26) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: -15 //gentle bounce if coming down super fast + }); + } else { + Matter.Body.setVelocity(player, { + x: player.velocity.x + (Math.random() - 0.5) * 2.5, + y: -1.21 * Math.sqrt(Math.abs(speed)) //give an upwards velocity that will put the player that the height desired + }); + } + } + + //draw + ctx.fillStyle = "rgba(200,0,255,0.15)"; + ctx.fillRect(this.boostBounds.min.x, this.boostBounds.min.y - 10, 100, 30); + ctx.fillStyle = "rgba(200,0,255,0.05)"; + ctx.fillRect(this.boostBounds.min.x, this.boostBounds.min.y - 50, 100, 70); + }, + }); + return who + } + }, + elevator(x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }, isAtTop = false) { + x += width / 2 + y += height / 2 + maxHeight += height / 2 + const yTravel = maxHeight - y + force += simulation.g + const who = body[body.length] = Bodies.rectangle(x, isAtTop ? maxHeight : y, width, height, { + collisionFilter: { + category: cat.body, //cat.map, + mask: cat.player | cat.body | cat.bullet | cat.mob | cat.mobBullet //| cat.powerUp + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 1, + frictionStatic: 1, + restitution: 0, + frictionAir: 0.001, + holdX: x, + move() { + if (!m.isTimeDilated) { + if (this.isUp) { //moving up still with high air friction + this.force.y -= force * this.mass //hard force propels up, even with high friction + + if (this.position.y < maxHeight) { //switch to down mode + this.isUp = false + this.frictionAir = friction.down + //adds a hard jerk at the top of vertical motion because it's fun + Matter.Body.setPosition(this, { x: this.holdX, y: maxHeight }); + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + } + } else if (this.position.y + 10 * this.velocity.y > y) { //free falling down, with only air friction + Matter.Body.setVelocity(this, { //slow down early to avoid a jerky stop that can pass through blocks + x: 0, + y: this.velocity.y * 0.7 + }); + if (this.position.y + this.velocity.y > y) { //switch to up mode + this.isUp = true + this.frictionAir = friction.up + } + } + Matter.Body.setVelocity(this, { x: 0, y: this.velocity.y }); + } + //edge limits + if (this.position.y < maxHeight) { + Matter.Body.setPosition(this, { x: this.holdX, y: maxHeight }); + } else if (this.position.y > y) { + Matter.Body.setPosition(this, { x: this.holdX, y: y }); + } + // hold horizontal position + Matter.Body.setPosition(this, { x: this.holdX, y: this.position.y }); + }, + moveOnTouch() { + if (!m.isTimeDilated) { + if (this.isUp) { //moving up still with high air friction + this.force.y -= force * this.mass //hard force propels up, even with high friction + + if (this.position.y < maxHeight) { //switch to down mode + this.isUp = false + this.frictionAir = friction.down + //adds a hard jerk at the top of vertical motion because it's fun + Matter.Body.setPosition(this, { x: this.holdX, y: maxHeight }); + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + } + } else if (this.position.y + 10 * this.velocity.y > y) { //free falling down, with only air friction + //slow down early to avoid a jerky stop that can pass through blocks + Matter.Body.setVelocity(this, { x: 0, y: this.velocity.y * 0.7 }); + //switch to up mode + // if (this.position.y + this.velocity.y > y) { + // this.isUp = true + // this.frictionAir = friction.up + // } + } + Matter.Body.setVelocity(this, { x: 0, y: this.velocity.y }); + } + //draw line to show how far to will extend + ctx.beginPath(); + ctx.moveTo(x, y + height / 2); + ctx.lineTo(x, maxHeight - height / 2); + ctx.strokeStyle = `rgba(0,0,0,0.2)` + ctx.lineWidth = "2" + ctx.stroke(); + + //draw body + ctx.beginPath(); + ctx.moveTo(this.vertices[0].x, this.vertices[0].y); + for (let j = 1; j < this.vertices.length; j++) { + ctx.lineTo(this.vertices[j].x, this.vertices[j].y); + } + ctx.lineTo(this.vertices[0].x, this.vertices[0].y); + ctx.lineWidth = "2" + ctx.strokeStyle = `#333` + ctx.fillStyle = `rgba(200,200,200,1)` + //edge limits + if (this.position.y < maxHeight) { + Matter.Body.setPosition(this, { x: this.holdX, y: maxHeight }); + } else if (this.position.y > y) { + ctx.fillStyle = `rgba(255,255,255,${0.5 + 0.15 * Math.random()})` + Matter.Body.setPosition(this, { x: this.holdX, y: y }); + //undoing force of gravity + this.force.y -= this.mass * simulation.g; + if (Matter.Query.collides(this, [player]).length) { + this.isUp = true + this.frictionAir = friction.up + } + } + ctx.fill(); + ctx.stroke(); + // hold horizontal position + Matter.Body.setPosition(this, { x: this.holdX, y: this.position.y }); + }, + off() { + Matter.Body.setPosition(this, { x: this.holdX, y: this.position.y }); + Matter.Body.setVelocity(this, { x: 0, y: this.velocity.y }); + }, + constraint: this.null, + addConstraint() { + this.constraint = Constraint.create({ + pointA: { + x: this.position.x, + y: this.position.y + }, + bodyB: this, + stiffness: 0.01, + damping: 0.3 + }); + Composite.add(engine.world, this.constraint); + }, + removeConstraint() { + Composite.remove(engine.world, this.constraint, true) + }, + drawTrack() { + ctx.fillStyle = "#ccc" + ctx.fillRect(this.holdX, y, 5, yTravel) + } + }); + Matter.Body.setDensity(who, 0.01) //10x density for added stability + Composite.add(engine.world, who); //add to world + who.classType = "body" + return who + }, + // spring(x, y, v = "-100 0 100 0 70 40 0 50 -70 40", force = 0.01, distance = 300, angle = 0) { + // const who = body[body.length] = Matter.Bodies.fromVertices(x, y, Vertices.fromPath(v), { + // collisionFilter: { + // category: cat.body, + // mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + // }, + // inertia: Infinity, //prevents rotation + // isNotHoldable: true, + // friction: 1, + // frictionStatic: 1, + // restitution: 0, + // frictionAir: 1, + // density: 0.1, + // isReady: true, + // isResetting: false, + // query() { + // if (this.isReady) { + // if (Matter.Query.collides(this, [player]).length) { + // this.isReady = false + // this.constraint.stiffness = 0 + // this.constraint.damping = 0 //0.3 + // this.frictionAir = 0 + // Matter.Body.setVelocity(this, { x: 0, y: 0 }); + // //show graphically being ready? + // } + // } else { + // if (this.isResetting) { + // this.constraint.stiffness += 0.0005 + // if (this.constraint.stiffness > 0.1) { + // this.isResetting = false + // this.isReady = true + // } + // } else { + // if (Vector.magnitudeSquared(Vector.sub(this.position, { + // x: x, + // y: y + // })) < distance * distance) { + // this.force.y -= force * this.mass + // } else { + // this.constraint.damping = 1 + // this.frictionAir = 1 + // this.isResetting = true + // Matter.Body.setVelocity(this, { + // x: 0, + // y: 0 + // }); + // } + // } + // } + // } + // }); + // who.constraint = Constraint.create({ + // pointA: { + // x: who.position.x, + // y: who.position.y + // }, + // bodyB: who, + // stiffness: 1, + // damping: 1 + // }); + // Composite.add(engine.world, who.constraint); + // return who + // }, + // rotor(x, y, rotate = 0, radius = 800, width = 40, density = 0.0005) { + // const rotor1 = Matter.Bodies.rectangle(x, y, width, radius, { + // density: density, + // isNotHoldable: true, + // isNonStick: true, + // collisionFilter: { + // category: cat.map, + // mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + // }, + // }); + // const rotor2 = Matter.Bodies.rectangle(x, y, width, radius, { + // angle: Math.PI / 2, + // density: density, + // isNotHoldable: true, + // isNonStick: true, + // collisionFilter: { + // category: cat.map, + // mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + // }, + // }); + // rotor = Body.create({ //combine rotor1 and rotor2 + // parts: [rotor1, rotor2], + // restitution: 0, + // collisionFilter: { + // category: cat.map, + // mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + // }, + // }); + // Matter.Body.setPosition(rotor, { + // x: x, + // y: y + // }); + // Composite.add(engine.world, [rotor]); + // body[body.length] = rotor1 + // body[body.length] = rotor2 + + // // setTimeout(function() { + // // rotor.collisionFilter.category = cat.body; + // // rotor.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mob | cat.mobBullet //| cat.map + // // }, 1000); + + // const constraint = Constraint.create({ //fix rotor in place, but allow rotation + // pointA: { + // x: x, + // y: y + // }, + // bodyB: rotor + // }); + // Composite.add(engine.world, constraint); + + // if (rotate) { + // rotor.rotate = function() { + // if (!m.isTimeDilated) { + // Matter.Body.applyForce(rotor, { + // x: rotor.position.x + 100, + // y: rotor.position.y + 100 + // }, { + // x: rotate * rotor.mass, + // y: 0 + // }) + // } else { + // Matter.Body.setAngularVelocity(rotor, 0); + // } + // } + // } + // composite[composite.length] = rotor + // return rotor + // }, + toggle(x, y, isOn = false, isLockOn = false) { + spawn.mapVertex(x + 65, y + 2, "70 10 -70 10 -40 -10 40 -10"); //toggle platform + map[map.length - 1].restitution = 0; + map[map.length - 1].friction = 1; // + map[map.length - 1].frictionStatic = 1; + const width = 120 + const height = 15 + body[body.length] = Bodies.rectangle(x + width / 2, y + height / 2, width, height, { friction: 0.05, frictionAir: 0.01 }); + let flip = body[body.length - 1]; + flip.collisionFilter.category = cat.body + flip.collisionFilter.mask = cat.player | cat.body + flip.isNotHoldable = true + flip.restitution = 0 + Matter.Body.setDensity(flip, 0.003) + if (isOn) { + Matter.Body.setAngle(flip, (0.25 - 0.5) * Math.PI) + } else { + Matter.Body.setAngle(flip, (-0.25 - 0.5) * Math.PI) + } + cons[cons.length] = Constraint.create({ + pointA: { + x: x + 65, + y: y - 5 + }, + bodyB: flip, + stiffness: 1, + length: 0 + }); + Composite.add(engine.world, [cons[cons.length - 1]]); + Composite.add(engine.world, flip); //add to world + flip.classType = "body" + return { + flip: flip, + isOn: isOn, + query() { + const limit = { + right: (-0.25 - 0.5) * Math.PI, + left: (0.25 - 0.5) * Math.PI + } + if (flip.angle < limit.right) { + Matter.Body.setAngle(flip, limit.right) + Matter.Body.setAngularVelocity(flip, 0); + if (!isLockOn) this.isOn = false + } else if (flip.angle > limit.left) { + Matter.Body.setAngle(flip, limit.left) + Matter.Body.setAngularVelocity(flip, 0); + this.isOn = true + } + if (this.isOn) { + ctx.beginPath(); + ctx.moveTo(flip.vertices[0].x, flip.vertices[0].y); + for (let j = 1; j < flip.vertices.length; j++) { + ctx.lineTo(flip.vertices[j].x, flip.vertices[j].y); + } + ctx.lineTo(flip.vertices[0].x, flip.vertices[0].y); + ctx.fillStyle = "#3df" + ctx.fill(); + ctx.lineWidth = 1; + ctx.strokeStyle = color.blockS; + ctx.stroke(); + } + }, + } + }, + button(x, y, width = 126, isSpawnBase = true, isInvertedVertical = false, color = "hsl(0, 100%, 70%)") { + if (isSpawnBase) { + if (isInvertedVertical) { + spawn.mapVertex(x + 65, y - 3, "100 -10 -100 -10 -70 10 70 10"); + } else { + spawn.mapVertex(x + 65, y + 2, "100 10 -100 10 -70 -10 70 -10"); + } + map[map.length - 1].restitution = 0; + map[map.length - 1].friction = 1; + map[map.length - 1].frictionStatic = 1; + } + // const buttonSensor = Bodies.rectangle(x + 35, y - 1, 70, 20, { + // isSensor: true + // }); + if (isInvertedVertical) { + return { + isUp: false, + min: { + x: x + 2, + y: y - 1 + }, + max: { + x: x + width, + y: y + }, + width: width, + height: 20, + query() { + if (Matter.Query.region(body, this).length === 0 && Matter.Query.region([player], this).length === 0) { + this.isUp = true; + } else { + if (this.isUp === true) { + const list = Matter.Query.region(body, this) //are any blocks colliding with this + if (list.length > 0) { + if (list[0].bounds.max.x - list[0].bounds.min.x < 150 && list[0].bounds.max.y - list[0].bounds.min.y < 150) { //not too big of a block + Matter.Body.setPosition(list[0], { //teleport block to the center of the button + x: this.min.x + width / 2, + y: list[0].position.y + }) + } + Matter.Body.setVelocity(list[0], { x: 0, y: 0 }); + } + } + this.isUp = false; + } + }, + queryRemove() { + if (Matter.Query.region(body, this).length === 0 && Matter.Query.region([player], this).length === 0) { + this.isUp = true; + } else { + if (this.isUp === true) { + const list = Matter.Query.region(body, this) //are any blocks colliding with this + if (list.length > 0) { + Matter.Composite.remove(engine.world, list[0]); + for (let i = 0; i < body.length; i++) { + if (body[i] === list[0]) { + body.splice(i, 1); + break + } + } + Matter.Body.setVelocity(list[0], { x: 0, y: 0 }); + } + } + this.isUp = false; + } + }, + queryPlayer() { + if (Matter.Query.region([player], this).length === 0) { + this.isUp = true; + } else { + this.isUp = false; + } + }, + draw() { + ctx.fillStyle = color + if (this.isUp) { + ctx.fillRect(this.min.x, this.min.y, this.width, 20) + } else { + ctx.fillRect(this.min.x, this.min.y - 12, this.width, 25) + } + } + } + } else { + return { + isUp: false, + min: { + x: x + 2, + y: y - 11 + }, + max: { + x: x + width, + y: y - 10 + }, + width: width, + height: 20, + query() { + if (Matter.Query.region(body, this).length === 0 && Matter.Query.region([player], this).length === 0) { + this.isUp = true; + } else { + if (this.isUp === true) { + const list = Matter.Query.region(body, this) //are any blocks colliding with this + if (list.length > 0) { + if (list[0].bounds.max.x - list[0].bounds.min.x < 150 && list[0].bounds.max.y - list[0].bounds.min.y < 150) { //not too big of a block + Matter.Body.setPosition(list[0], { //teleport block to the center of the button + x: this.min.x + width / 2, + y: list[0].position.y + }) + } + Matter.Body.setVelocity(list[0], { x: 0, y: 0 }); + } + } + this.isUp = false; + } + }, + queryRemove() { + if (Matter.Query.region(body, this).length === 0 && Matter.Query.region([player], this).length === 0) { + this.isUp = true; + } else { + if (this.isUp === true) { + const list = Matter.Query.region(body, this) //are any blocks colliding with this + if (list.length > 0) { + //delete triggering block + Matter.Composite.remove(engine.world, list[0]); + for (let i = 0; i < body.length; i++) { + if (body[i] === list[0]) { + body.splice(i, 1); + break + } + } + Matter.Body.setVelocity(list[0], { x: 0, y: 0 }); + } + } + this.isUp = false; + } + }, + queryPlayer() { + if (Matter.Query.region([player], this).length === 0) { + this.isUp = true; + } else { + this.isUp = false; + } + }, + draw() { + ctx.fillStyle = color + if (this.isUp) { + ctx.fillRect(this.min.x, this.min.y - 10, this.width, 20) + } else { + ctx.fillRect(this.min.x, this.min.y - 3, this.width, 25) + } + } + } + } + }, + vanish(x, y, width, height, isVertical = false, hide = { + x: 0, + y: 150 + }) { + x = x + width / 2 + y = y + height / 2 + const vertices = [{ + x: x, + y: y, + index: 0, + isInternal: false + }, { + x: x + width, + y: y, + index: 1, + isInternal: false + }, { + x: x + width, + y: y + height, + index: 4, + isInternal: false + }, { + x: x, + y: y + height, + index: 3, + isInternal: false + }] + const block = body[body.length] = Bodies.fromVertices(x, y, vertices, { + // const block = body[body.length] = Bodies.rectangle(x, y, width, height, { + collisionFilter: { + category: cat.map, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + isNonStick: true, //this keep sporangium from sticking + isTouched: false, + fadeTime: 10 + Math.ceil(0.25 * width), + fadeCount: null, + isThere: true, + returnTime: 120, + returnCount: 0, + shrinkVertices(size) { + if (isVertical) { + return [{ + x: x, + y: y * size, + index: 0, + isInternal: false + }, { + x: x + width, + y: y * size, + index: 1, + isInternal: false + }, { + x: x + width, + y: (y + height) * size, + index: 4, + isInternal: false + }, { + x: x, + y: (y + height) * size, + index: 3, + isInternal: false + }] + } else { + return [{ + x: x * size, + y: y, + index: 0, + isInternal: false + }, { + x: (x + width) * size, + y: y, + index: 1, + isInternal: false + }, { + x: (x + width) * size, + y: y + height, + index: 4, + isInternal: false + }, { + x: x * size, + y: y + height, + index: 3, + isInternal: false + }] + } + }, + query() { + if (this.isThere) { + if (this.isTouched) { + if (!m.isTimeDilated) { + this.fadeCount-- + Matter.Body.setVertices(this, this.shrinkVertices(Math.max(this.fadeCount / this.fadeTime, 0.03))) + } + if (this.fadeCount < 1) { + Matter.Body.setPosition(this, hide) + this.isThere = false + this.isTouched = false + this.collisionFilter.mask = 0 //cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + this.returnCount = this.returnTime + Matter.Body.setVertices(this, this.shrinkVertices(1)) + Matter.Body.setVertices(this, vertices) + } + } else if (Matter.Query.collides(this, [player]).length) { // || (Matter.Query.collides(this, body).length)) { + this.isTouched = true + this.fadeCount = this.fadeTime; + } + } else { + if (!m.isTimeDilated) { + this.returnCount-- + if (this.returnCount < 1) { + Matter.Body.setPosition(this, { + x: x, + y: y + }) + if (Matter.Query.collides(this, [player]).length) { //|| (Matter.Query.collides(this, body).length)) { + Matter.Body.setPosition(this, hide) + this.returnCount = 15 + } else { + this.isThere = true + this.collisionFilter.mask = cat.player | cat.mob | cat.body | cat.bullet | cat.powerUp | cat.mobBullet + this.fadeCount = this.fadeTime + //delete any overlapping blocks + const blocks = Matter.Query.collides(this, body) + for (let i = 0; i < blocks.length; i++) { + if (blocks[i].bodyB !== this && blocks[i].bodyB !== m.holdingTarget) { //dont' delete yourself <----- bug here maybe... + Matter.Composite.remove(engine.world, blocks[i].bodyB); + blocks[i].bodyB.isRemoveMeNow = true + for (let i = 1; i < body.length; i++) { //find which index in body array it is and remove from array + if (body[i].isRemoveMeNow) { + body.splice(i, 1); + break + } + } + } + } + //delete any overlapping mobs + // const mobsHits = Matter.Query.collides(this, mob) + // for (let i = 0; i < mobsHits.length; i++) { + // if (mobsHits[i].bodyB !== this && mobsHits[i].bodyB !== m.holdingTarget) { //dont' delete yourself <----- bug here maybe... + // Matter.Composite.remove(engine.world, mobsHits[i].bodyB); + // mobsHits[i].bodyB.isRemoveMeNow = true + // for (let i = 1; i < mob.length; i++) { //find which index in body array it is and remove from array + // if (mob[i].isRemoveMeNow) { + // mob.splice(i, 1); + // break + // } + // } + // } + // } + } + } + } + } + ctx.beginPath(); + const v = this.vertices; + ctx.moveTo(v[0].x, v[0].y); + for (let i = 1; i < v.length; ++i) ctx.lineTo(v[i].x, v[i].y); + ctx.lineTo(v[0].x, v[0].y); + ctx.fillStyle = "#586370" + ctx.fill(); + // const color = 220 * (1 - this.fadeCount / this.fadeTime) + // ctx.fillStyle = `rgb(${color},220, 200)` + // ctx.fillStyle = `rgba(0,220,200,${this.fadeCount/this.fadeTime+0.05})` + // ctx.strokeStyle = `#bff` + // ctx.stroke(); + }, + }); + Matter.Body.setStatic(block, true); //make static + Composite.add(engine.world, block); //add to world + // who.classType = "body" + if (simulation.isHorizontalFlipped) x *= -1 + return block + }, + door(x, y, width, height, distance, speed = 1) { + x = x + width / 2 + y = y + height / 2 + const doorBlock = body[body.length] = Bodies.rectangle(x, y, width, height, { + collisionFilter: { + category: cat.body,//cat.map, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 1, + frictionStatic: 1, + restitution: 0, + isClosing: false, + openClose() { + if (!m.isTimeDilated) { + if (this.isClosing) { + if (this.position.y < y) { //try to close + if ( //if clear of stuff + Matter.Query.collides(this, [player]).length === 0 && + Matter.Query.collides(this, body).length < 2 && + Matter.Query.collides(this, mob).length === 0 + ) { + const position = { + x: this.position.x, + y: this.position.y + speed + } + Matter.Body.setPosition(this, position) + } + } + } else { + if (this.position.y > y - distance) { //try to open + const position = { + x: this.position.x, + y: this.position.y - speed + } + Matter.Body.setPosition(this, position) + } + } + } + }, + isClosed() { + return this.position.y > y - 1 + }, + draw() { + ctx.fillStyle = "#666" + ctx.beginPath(); + const v = this.vertices; + ctx.moveTo(v[0].x, v[0].y); + for (let i = 1; i < v.length; ++i) ctx.lineTo(v[i].x, v[i].y); + ctx.lineTo(v[0].x, v[0].y); + ctx.fill(); + } + }); + Matter.Body.setStatic(doorBlock, true); //make static + Composite.add(engine.world, doorBlock); //add to world + doorBlock.classType = "body" + return doorBlock + }, + doorMap(x, y, width, height, distance, speed = 20, addToWorld = true) { //for doors that use line of sight + x = x + width / 2 + y = y + height / 2 + const door = map[map.length] = Bodies.rectangle(x, y, width, height, { + collisionFilter: { + category: cat.map, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet, + // mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 1, + frictionStatic: 1, + restitution: 0, + isClosing: false, + openClose(isSetPaths = false) { + if (!m.isTimeDilated) { + if (this.isClosing) { + if (this.position.y < y) { //try to close + if ( //if clear of stuff + Matter.Query.collides(this, [player]).length === 0 && + Matter.Query.collides(this, body).length < 2 && + Matter.Query.collides(this, mob).length === 0 + ) { + const position = { + x: this.position.x, + y: this.position.y + speed + } + Matter.Body.setPosition(this, position) + if (isSetPaths) { + simulation.draw.setPaths() + simulation.draw.lineOfSightPrecalculation() //required precalculation for line of sight + } + } + } + } else { + if (this.position.y > y - distance) { //try to open + const position = { + x: this.position.x, + y: this.position.y - speed + } + Matter.Body.setPosition(this, position) + if (isSetPaths) { + simulation.draw.setPaths() + simulation.draw.lineOfSightPrecalculation() //required precalculation for line of sight + } + } + } + } + }, + isClosed() { + return this.position.y > y - 1 + }, + draw() { + ctx.fillStyle = "#666" + ctx.beginPath(); + const v = this.vertices; + ctx.moveTo(v[0].x, v[0].y); + for (let i = 1; i < v.length; ++i) ctx.lineTo(v[i].x, v[i].y); + ctx.lineTo(v[0].x, v[0].y); + ctx.fill(); + } + }); + + Matter.Body.setStatic(door, true); //make static + if (addToWorld) Composite.add(engine.world, door); //add to world + door.classType = "map" + return door + }, + portal(centerA, angleA, centerB, angleB) { + const width = 50 + const height = 150 + const mapWidth = 200 + const unitA = Matter.Vector.rotate({ x: 1, y: 0 }, angleA) + const unitB = Matter.Vector.rotate({ x: 1, y: 0 }, angleB) + draw = function () { + ctx.beginPath(); //portal + let v = this.vertices; + ctx.moveTo(v[0].x, v[0].y); + for (let i = 1; i < v.length; ++i) ctx.lineTo(v[i].x, v[i].y); + ctx.fillStyle = this.color + ctx.fill(); + } + query = function (isRemoveBlocks = false) { + if (Matter.Query.collides(this, [player]).length === 0) { //not touching player + if (player.isInPortal === this) player.isInPortal = null + } else if (player.isInPortal !== this) { //touching player + if (m.buttonCD_jump === m.cycle) player.force.y = 0 // undo a jump right before entering the portal + m.buttonCD_jump = 0 //disable short jumps when letting go of jump key + player.isInPortal = this.portalPair + //teleport + if (this.portalPair.angle % (Math.PI / 2)) { //if left, right up or down + if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + // Matter.Body.setPosition(player, this.portalPair.portal.position); + simulation.translatePlayerAndCamera(this.portalPair.portal.position) + } else { //if at some odd angle + if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + // Matter.Body.setPosition(player, this.portalPair.position); + simulation.translatePlayerAndCamera(this.portalPair.position) + } + //rotate velocity + let mag + if (this.portalPair.angle !== 0 && this.portalPair.angle !== Math.PI) { //portal that fires the player up + mag = Math.max(10, Math.min(50, player.velocity.y * 0.8)) + 11 + } else { + mag = Math.max(6, Math.min(50, Vector.magnitude(player.velocity))) + } + let v = Vector.mult(this.portalPair.unit, mag) + Matter.Body.setVelocity(player, v); + // // move bots to player + // for (let i = 0; i < bullet.length; i++) { + // if (bullet[i].botType) { + // Matter.Body.setPosition(bullet[i], Vector.sub(bullet[i].position, change)); + // // Matter.Body.setPosition(bullet[i], this.portalPair.portal.position); + // // Matter.Body.setPosition(bullet[i], Vector.add(this.portalPair.portal.position, { x: 250 * (Math.random() - 0.5), y: 250 * (Math.random() - 0.5) })); + // // Matter.Body.setVelocity(bullet[i], { x: 0, y: 0 }); + // } + // } + if (tech.isHealAttract) { //send heals to next portal + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "heal" && Vector.magnitudeSquared(Vector.sub(powerUp[i].position, m.pos)) < 1000000) { + Matter.Body.setPosition(powerUp[i], Vector.add(this.portalPair.portal.position, { x: 500 * (Math.random() - 0.5), y: 500 * (Math.random() - 0.5) })); + } + } + } + } + for (let i = 0, len = body.length; i < len; i++) { + if (body[i] !== m.holdingTarget) { + // body[i].bounds.max.x - body[i].bounds.min.x < 100 && body[i].bounds.max.y - body[i].bounds.min.y < 100 + if (Matter.Query.collides(this, [body[i]]).length === 0) { + if (body[i].isInPortal === this) body[i].isInPortal = null + } else if (body[i].isInPortal !== this) { //touching this portal, but for the first time + if (isRemoveBlocks) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + break + } + body[i].isInPortal = this.portalPair + //teleport + if (this.portalPair.angle % (Math.PI / 2)) { //if left, right up or down + Matter.Body.setPosition(body[i], this.portalPair.portal.position); + } else { //if at some odd angle + Matter.Body.setPosition(body[i], this.portalPair.position); + } + //rotate velocity + let mag + if (this.portalPair.angle !== 0 && this.portalPair.angle !== Math.PI) { //portal that fires up + mag = Math.max(10, Math.min(50, body[i].velocity.y * 0.8)) + 11 + let v = Vector.mult(this.portalPair.unit, mag) + //rotate the velocity vector of blocks fired directly up to keep them from getting stuck endlessly in vertical portals + Matter.Body.setVelocity(body[i], Vector.rotate(v, 0.5 * (Math.random() - 0.5))); + } else { + mag = Math.max(6, Math.min(50, Vector.magnitude(body[i].velocity))) + let v = Vector.mult(this.portalPair.unit, mag) + Matter.Body.setVelocity(body[i], v); + } + + } + } + } + + //remove block if touching + // if (body.length) { + // touching = Matter.Query.collides(this, body) + // for (let i = 0; i < touching.length; i++) { + // if (touching[i].bodyB !== m.holdingTarget) { + // for (let j = 0, len = body.length; j < len; j++) { + // if (body[j] === touching[i].bodyB) { + // body.splice(j, 1); + // len-- + // Matter.Composite.remove(engine.world, touching[i].bodyB); + // break; + // } + // } + // } + // } + // } + + // if (touching.length !== 0 && touching[0].bodyB !== m.holdingTarget) { + // if (body.length) { + // for (let i = 0; i < body.length; i++) { + // if (body[i] === touching[0].bodyB) { + // body.splice(i, 1); + // break; + // } + // } + // } + // Matter.Composite.remove(engine.world, touching[0].bodyB); + // } + } + + const portalA = composite[composite.length] = Bodies.rectangle(centerA.x, centerA.y, width, height, { + isSensor: true, + angle: angleA, + color: "hsla(197, 100%, 50%,0.7)", + draw: draw, + }); + const portalB = composite[composite.length] = Bodies.rectangle(centerB.x, centerB.y, width, height, { + isSensor: true, + angle: angleB, + color: "hsla(29, 100%, 50%, 0.7)", + draw: draw + }); + const mapA = composite[composite.length] = Bodies.rectangle(centerA.x - 0.5 * unitA.x * mapWidth, centerA.y - 0.5 * unitA.y * mapWidth, mapWidth, height + 10, { + collisionFilter: { + category: cat.map, + mask: cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + unit: unitA, + angle: angleA, + color: color.map, + draw: draw, + query: query, + lastPortalCycle: 0 + }); + Matter.Body.setStatic(mapA, true); //make static + Composite.add(engine.world, mapA); //add to world + + const mapB = composite[composite.length] = Bodies.rectangle(centerB.x - 0.5 * unitB.x * mapWidth, centerB.y - 0.5 * unitB.y * mapWidth, mapWidth, height + 10, { + collisionFilter: { + category: cat.map, + mask: cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + unit: unitB, + angle: angleB, + color: color.map, + draw: draw, + query: query, + lastPortalCycle: 0, + }); + Matter.Body.setStatic(mapB, true); //make static + Composite.add(engine.world, mapB); //add to world + + mapA.portal = portalA + mapB.portal = portalB + mapA.portalPair = mapB + mapB.portalPair = mapA + return [portalA, portalB, mapA, mapB] + }, + drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + return { + x: x, + y: yMin, + period: period, + dropCycle: 0, + speed: 0, + draw() { + if (!m.isTimeDilated) { + if (this.dropCycle < simulation.cycle) { //reset + this.dropCycle = simulation.cycle + this.period + Math.floor(40 * Math.random()) + this.y = yMin + this.speed = 1 + } else { //fall + this.speed += 0.35 //acceleration from gravity + this.y += this.speed + } + } + if (this.y < yMax) { //draw + ctx.fillStyle = color //"hsla(160, 100%, 35%,0.75)" + ctx.beginPath(); + ctx.arc(this.x, this.y, 8, 0, 2 * Math.PI); + ctx.fill(); + } + } + } + }, + laser(p1, p2, damage = 0.14, color = "#f00") { + return { + isOn: true, + position: p1, + look: p2, + color: color, + query() { + if (!m.isTimeDilated) { + let best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null } + best = vertexCollision(this.position, this.look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + // hitting player + if ((best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + const dmg = damage * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(255,0,0,0.5)", + time: 20 + }); + } + //draw + if (best.dist2 === Infinity) best = this.look; + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = this.color; + ctx.lineWidth = 5; + ctx.setLineDash([50 + 200 * Math.random(), 50 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + } + }, + countDown: 0, + countTotal: 480, + countDelay: 440, + motionQuery() { + if (!m.isTimeDilated) { + let best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null } + best = vertexCollision(this.position, this.look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + + if (this.countDown === 0) { + if ((best.who === playerBody || best.who === playerHead)) this.countDown = this.countTotal // hitting player + ctx.strokeStyle = `rgba(255,255,255,0.4)`; + ctx.lineWidth = 8 + 3 * Math.sin(simulation.cycle * 0.3); + } else if (this.countDown > this.countDelay) { + ctx.strokeStyle = `rgba(255,255,255,0.8)`; + ctx.lineWidth = 11; + this.countDown-- + } else { + this.countDown-- + if ((best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { // hitting player + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + const dmg = damage * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(255,0,0,0.5)", + time: 20 + }); + } + ctx.strokeStyle = this.color; + ctx.lineWidth = 5; + ctx.setLineDash([50 + 200 * Math.random(), 50 * Math.random()]); + } + //draw + if (best.dist2 === Infinity) best = this.look; + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(best.x, best.y); + ctx.stroke(); + ctx.setLineDash([]); + } + }, + } + }, + fizzler(p1, p2) { + return { + isOn: true, + position: p1, + look: p2, + color: color, + query() { + if (!m.isTimeDilated) { + // let best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null } + // best = vertexCollision(this.position, this.look, [body]); + + const hits = Matter.Query.ray(body, this.position, this.look, 25) + for (let i = hits.length - 1; i > -1; i--) { + // console.log(what) + const what = hits[i].bodyA + simulation.drawList.push({ x: what.position.x, y: what.position.y, radius: 11, color: "rgba(0,160,255,0.7)", time: 10 }); + if (what === m.holdingTarget) m.drop() + for (let i = 0; i < body.length; i++) { + if (body[i] === what) { + body.splice(i, 1); + break + } + } + Matter.Composite.remove(engine.world, what); + } + //draw + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(this.look.x, this.look.y); + // ctx.strokeStyle = "rgba(50,200,255,0.3)"; + // ctx.lineWidth = 2 + 5 * Math.random() + // ctx.stroke(); + ctx.strokeStyle = "rgba(50,160,255,0.17)"; + ctx.lineWidth = 35 + 25 * Math.random() * Math.random(); + ctx.stroke(); + + //draw random dots in the path + if (Math.random() < 0.05) { + const r = Math.random(); + const where = { + x: this.position.x + r * (this.look.x - this.position.x) + 60 * (Math.random() - 0.5), + y: this.position.y + r * (this.look.y - this.position.y) + 60 * (Math.random() - 0.5) + }; + simulation.drawList.push({ x: where.x, y: where.y, radius: 6, color: "rgba(0,160,255,0.7)", time: 5 }); + } + } + }, + } + }, + isHazardRise: false, + hazard(x, y, width, height, damage = 0.002) { + return { + min: { x: x, y: y }, + max: { x: x + width, y: y + height }, + width: width, + height: height, + maxHeight: height, + isOn: true, + opticalQuery() { + if (this.isOn) { + //draw + ctx.fillStyle = `hsla(0, 100%, 50%,${0.6 + 0.4 * Math.random()})` + ctx.fillRect(this.min.x, this.min.y, this.width, this.height) + //collision with player + if (this.height > 0 && Matter.Query.region([player], this).length && !(m.isCloak)) { + if (m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; + m.damage(damage) + simulation.drawList.push({ //add dmg to draw queue + x: player.position.x, + y: player.position.y, + radius: damage * 1500, + color: simulation.mobDmgColor, + time: 20 + }); + } + } + } + }, + query() { + if (this.isOn) { + ctx.fillStyle = "hsla(160, 100%, 35%,0.75)" + const offset = 5 * Math.sin(simulation.cycle * 0.015) + ctx.fillRect(this.min.x, this.min.y + offset, this.width, this.height - offset) + + if (this.height > 0 && Matter.Query.region([player], this).length) { + if (m.immuneCycle < m.cycle) { + const DRAIN = 0.004 * (tech.isRadioactiveResistance ? 0.2 : 1) + if (m.energy > DRAIN) { + m.energy -= DRAIN + if (tech.isEnergyHealth && m.energy < 0) m.death() + } else { + m.damage(damage * (tech.isRadioactiveResistance ? 0.2 : 1)) + + } + } + //float + if (player.velocity.y > 5) player.force.y -= 0.95 * player.mass * simulation.g + const slowY = (player.velocity.y > 0) ? Math.max(0.8, 1 - 0.002 * player.velocity.y * player.velocity.y) : Math.max(0.98, 1 - 0.001 * Math.abs(player.velocity.y)) //down : up + Matter.Body.setVelocity(player, { + x: Math.max(0.95, 1 - 0.036 * Math.abs(player.velocity.x)) * player.velocity.x, + y: slowY * player.velocity.y + }); + //undo 1/2 of gravity + player.force.y -= 0.5 * player.mass * simulation.g; + + } + //float power ups + powerUpCollide = Matter.Query.region(powerUp, this) + for (let i = 0, len = powerUpCollide.length; i < len; i++) { + const diameter = 2 * powerUpCollide[i].size + const buoyancy = 1 - 0.2 * Math.max(0, Math.min(diameter, this.min.y - powerUpCollide[i].position.y + powerUpCollide[i].size)) / diameter + powerUpCollide[i].force.y -= buoyancy * 1.24 * powerUpCollide[i].mass * simulation.g; + Matter.Body.setVelocity(powerUpCollide[i], { + x: powerUpCollide[i].velocity.x, + y: 0.97 * powerUpCollide[i].velocity.y + }); + } + } + }, + // draw() { + // if (this.isOn) { + // ctx.fillStyle = color + // ctx.fillRect(this.min.x, this.min.y, this.width, this.height) + // } + // }, + levelRise(growRate = 1) { + if (this.height < this.maxHeight && !m.isTimeDilated) { + this.height += growRate + this.min.y -= growRate + this.max.y = this.min.y + this.height + } + }, + levelFall(fallRate = 1) { + if (this.height > 0 && !m.isTimeDilated) { + this.height -= fallRate + this.min.y += fallRate + this.max.y = this.min.y + this.height + } + }, + level(isFill, growSpeed = 1) { + if (!m.isTimeDilated) { + if (isFill) { + if (this.height < this.maxHeight) { + this.height += growSpeed + this.min.y -= growSpeed + this.max.y = this.min.y + this.height + } + } else if (this.height > 0) { + this.height -= growSpeed + this.min.y += growSpeed + this.max.y = this.min.y + this.height + } + } + } + } + }, + mover(x, y, width, height, VxGoal = -6, force = VxGoal > 0 ? 0.0005 : -0.0005) { + //VxGoal below 3 don't move well, maybe try adjusting the force + x = x + width / 2 + y = y + height / 2 + const rect = map[map.length] = Bodies.rectangle(x, y, width, height, { + collisionFilter: { + category: cat.map, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 0, + frictionStatic: 0, + restitution: 0, + isClosing: false, + isMover: true, + VxGoal: VxGoal, + force: force, + push() { + if (!m.isTimeDilated) { + const touchingPlayer = Matter.Query.collides(this, [jumpSensor]) + if (touchingPlayer.length) { + m.moverX = this.VxGoal + if ((this.VxGoal > 0 && player.velocity.x < this.VxGoal) || (this.VxGoal < 0 && player.velocity.x > this.VxGoal)) { + player.force.x += this.force * player.mass + } + m.Vx = player.velocity.x - this.VxGoal + } + let pushBlock = (who) => { + if (!who.isMover) { + if ((this.VxGoal > 0 && who.velocity.x < this.VxGoal) || (this.VxGoal < 0 && who.velocity.x > this.VxGoal)) { + who.force.x += this.force * who.mass + } + const stoppingFriction = 0.5 + Matter.Body.setVelocity(who, { x: this.VxGoal * (1 - stoppingFriction) + who.velocity.x * stoppingFriction, y: who.velocity.y }); + Matter.Body.setAngularVelocity(who, who.angularVelocity * 0.9) + } + } + const blocks = Matter.Query.collides(this, body) + for (let i = 0; i < blocks.length; i++) { + pushBlock(blocks[i].bodyA) + pushBlock(blocks[i].bodyB) + } + const mobTargets = Matter.Query.collides(this, mob) + for (let i = 0; i < mobTargets.length; i++) { + pushBlock(mobTargets[i].bodyA) + pushBlock(mobTargets[i].bodyB) + } + let pushPowerUp = (who) => { + if (!who.isMover) { + if ((this.VxGoal > 0 && who.velocity.x < this.VxGoal) || (this.VxGoal < 0 && who.velocity.x > this.VxGoal)) { + who.force.x += 2 * this.force * who.mass + } + const stoppingFriction = 0.5 + Matter.Body.setVelocity(who, { x: this.VxGoal * (1 - stoppingFriction) + who.velocity.x * stoppingFriction, y: who.velocity.y }); + } + } + const powers = Matter.Query.collides(this, powerUp) + for (let i = 0; i < powers.length; i++) { + pushPowerUp(powers[i].bodyA) + pushPowerUp(powers[i].bodyB) + } + } + }, + draw() { + ctx.beginPath(); + const v = this.vertices; + ctx.moveTo(v[0].x + 2, v[0].y); + // for (let i = 1; i < v.length; ++i) ctx.lineTo(v[i].x, v[i].y); + ctx.lineTo(v[1].x - 2, v[1].y); + ctx.strokeStyle = "#000" + ctx.lineWidth = 4; + ctx.setLineDash([40, 40]); + ctx.lineDashOffset = (-simulation.cycle * this.VxGoal) % 80; + ctx.stroke(); + ctx.setLineDash([0, 0]); + }, + drawFast() { + ctx.beginPath(); + const v = this.vertices; + ctx.moveTo(v[0].x + 2, v[0].y); + // for (let i = 1; i < v.length; ++i) ctx.lineTo(v[i].x, v[i].y); + ctx.lineTo(v[1].x - 2, v[1].y); + ctx.strokeStyle = "#000" + ctx.lineWidth = 4; + ctx.setLineDash([60, 60]); + ctx.lineDashOffset = (-simulation.cycle * this.VxGoal) % 120; + ctx.stroke(); + ctx.setLineDash([0, 0]); + } + }); + Matter.Body.setStatic(rect, true); //make static + return rect + }, + transport(x, y, width, height, VxGoal = -6, force = VxGoal > 0 ? 0.0005 : -0.0005) { + //horizontal moving platform + //VxGoal below 3 don't move well, maybe try adjusting the force + x = x + width / 2 + y = y + height / 2 + const rect = body[body.length] = Bodies.rectangle(x, y, width, height, { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 0, + frictionStatic: 0, + restitution: 0, + isClosing: false, + isMover: true, + VxGoal: VxGoal, + force: force, + move() { + if (!m.isTimeDilated) { + Matter.Body.setPosition(this, { x: this.position.x + this.VxGoal, y: this.position.y }); //horizontal movement + const touchingPlayer = Matter.Query.collides(this, [jumpSensor]) + if (touchingPlayer.length) { + m.moverX = this.VxGoal + if ((this.VxGoal > 0 && player.velocity.x < this.VxGoal) || (this.VxGoal < 0 && player.velocity.x > this.VxGoal)) { + player.force.x += this.force * player.mass + } + m.Vx = player.velocity.x - this.VxGoal + } + let pushBlock = (who) => { + if (!who.isMover) { + if ((this.VxGoal > 0 && who.velocity.x < this.VxGoal) || (this.VxGoal < 0 && who.velocity.x > this.VxGoal)) { + who.force.x += this.force * who.mass + } + const stoppingFriction = 0.5 + Matter.Body.setVelocity(who, { x: this.VxGoal * (1 - stoppingFriction) + who.velocity.x * stoppingFriction, y: who.velocity.y }); + Matter.Body.setAngularVelocity(who, who.angularVelocity * 0.8) + } + } + const blocks = Matter.Query.collides(this, body) + for (let i = 0; i < blocks.length; i++) { + pushBlock(blocks[i].bodyA) + pushBlock(blocks[i].bodyB) + } + } + }, + draw() { + ctx.beginPath(); + const v = this.vertices; + ctx.moveTo(v[0].x, v[0].y); + for (let i = 1; i < v.length; ++i) ctx.lineTo(v[i].x, v[i].y); + ctx.lineTo(v[0].x, v[0].y); + ctx.fillStyle = "#586370" + ctx.fill(); + }, + changeDirection(isRight) { + if (isRight) { + this.VxGoal = Math.abs(this.VxGoal) + this.force = Math.abs(this.force) + if (Matter.Query.collides(this, [jumpSensor]).length) player.force.x += this.trainKickPlayer * this.force * player.mass + } else { + this.VxGoal = -Math.abs(this.VxGoal) + this.force = -Math.abs(this.force) + if (Matter.Query.collides(this, [jumpSensor]).length) player.force.x += this.trainKickPlayer * this.force * player.mass + } + }, + trainSpeed: Math.abs(VxGoal), + trainKickPlayer: 12 * Math.abs(force), + isSensing: false, + stops: { left: x, right: x + 1000 }, //this should probably be reset in the level code for the actual train stops + trainStop() { + if (this.isMoving) { + this.move(); + //oscillate back and forth + if (this.position.x < this.stops.left) {//stop + this.VxGoal = this.trainSpeed + this.force = 0.0005 + this.isMoving = false + this.isSensing = false + if (Matter.Query.collides(this, [jumpSensor]).length) player.force.x += this.trainKickPlayer * player.mass * (this.VxGoal > 0 ? 1 : -1)//give player a kick so they don't fall off + } else if (this.position.x > this.stops.right) {//stop + this.VxGoal = -this.trainSpeed + this.force = -0.0005 + this.isMoving = false + this.isSensing = false + if (Matter.Query.collides(this, [jumpSensor]).length) player.force.x += this.trainKickPlayer * player.mass * (this.VxGoal > 0 ? 1 : -1)//give player a kick so they don't fall off + } + } else if (this.isSensing) { + if (Matter.Query.collides(this, [jumpSensor]).length) { + this.isMoving = true + this.move(); //needs to move out of the stop range + // if (Matter.Query.collides(this, [jumpSensor]).length) player.force.x += trainKickPlayer * player.mass * (this.VxGoal > 0 ? 1 : -1)//give player a kick so they don't fall off + if (Matter.Query.collides(this, [jumpSensor]).length) { + Matter.Body.setVelocity(player, { x: this.VxGoal, y: player.velocity.y }); + } + } else if (this.position.x > this.stops.right && player.position.x < this.stops.left + 500) {//head to other stop if the player is far away + this.changeDirection(false) //go left + this.isMoving = true + this.move(); //needs to move out of the stop range + } else if (this.position.x < this.stops.left && player.position.x > this.stops.right - 500) {//head to other stop if the player is far away + this.changeDirection(true) //go right + this.isMoving = true + this.move(); //needs to move out of the stop range + } + } else if (!Matter.Query.collides(this, [jumpSensor]).length) {//wait until player is off the train to start sensing + this.isSensing = true + } + }, + }); + Matter.Body.setStatic(rect, true); //make static + Composite.add(engine.world, rect); //add to world + rect.classType = "body" + return rect + }, + chain(x, y, angle = 0, isAttached = true, len = 15, radius = 20, stiffness = 1, damping = 1) { + const gap = 2 * radius + const unit = { + x: Math.cos(angle), + y: Math.sin(angle) + } + for (let i = 0; i < len; i++) { + body[body.length] = Bodies.polygon(x + gap * unit.x * i, y + gap * unit.y * i, 12, radius, { + inertia: Infinity, + isNotHoldable: true + }); + const who = body[body.length - 1] + who.collisionFilter.category = cat.body; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + Composite.add(engine.world, who); //add to world + who.classType = "body" + } + for (let i = 1; i < len; i++) { //attach blocks to each other + consBB[consBB.length] = Constraint.create({ + bodyA: body[body.length - i], + bodyB: body[body.length - i - 1], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + cons[cons.length] = Constraint.create({ //pin first block to a point in space + pointA: { + x: x, + y: y + }, + bodyB: body[body.length - len], + stiffness: 1, + damping: damping + }); + Composite.add(engine.world, cons[cons.length - 1]); + if (isAttached) { + cons[cons.length] = Constraint.create({ //pin last block to a point in space + pointA: { + x: x + gap * unit.x * (len - 1), + y: y + gap * unit.y * (len - 1) + }, + bodyB: body[body.length - 1], + stiffness: 1, + damping: damping + }); + Composite.add(engine.world, cons[cons.length - 1]); + } + }, + //****************************************************************************************************************** + //****************************************************************************************************************** + //****************************************************************************************************************** + //****************************************************************************************************************** + template() { + // level.announceMobTypes() + simulation.enableConstructMode() + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 1500; + level.exit.y = -1875; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + // color.map = "#444" //custom map color + + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { }; + + spawn.mapRect(-100, 0, 1000, 100); + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + // spawn.bodyRect(1540, -1110, 300, 25, 0.9); + // spawn.randomSmallMob(1300, -70); + // spawn.randomMob(2650, -975, 0.8); + // spawn.randomGroup(1700, -900, 0.4); + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + // spawn.secondaryBossChance(100, -1500) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + testing() { + // simulation.enableConstructMode() //tech.giveTech('motion sickness') //used to build maps in testing mode + + document.body.style.backgroundColor = "#fff"; + // color.map = "#444" //custom map color + level.defaultZoom = 1500 + simulation.zoomTransition(level.defaultZoom) + + const mover = level.mover(2800, -300, 1000, 25); //x,y,width.height,VxGoal,force + + const train = level.transport(2900, -500, 500, 25, 8); //x,y,width.height,VxGoal,force + // spawn.bodyRect(1900, -550, 50, 50); + const button = level.button(2535, -200) + // spawn.bodyRect(250, -450, 50, 50); //block on button + + level.custom = () => { + + //oscillate back and forth + if (train.position.x < 2000) { + train.changeDirection(true) //go right + } else if (train.position.x > 4000) { + train.changeDirection(false) //go left + } + if (!button.isUp) train.move(); + + mover.push(); + ctx.fillStyle = "#d4d4d4" + ctx.fillRect(2500, -475, 200, 300) + + ctx.fillStyle = "#ddd" + ctx.fillRect(-150, -1000, 6875, 1000); + ctx.fillStyle = "rgba(0,255,255,0.1)"; + ctx.fillRect(6400, -550, 300, 350); + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + train.draw() + mover.draw(); + button.query(); + button.draw(); + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-150, -650, 900, 250) + }; + level.setPosToSpawn(0, -450); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 6500; + level.exit.y = -230; + + spawn.mapRect(-950, 0, 8200, 800); //ground + spawn.mapRect(-950, -1200, 800, 1400); //left wall + spawn.mapRect(-950, -1800, 8200, 800); //roof + spawn.mapRect(-250, -400, 1000, 600); // shelf + spawn.mapRect(-250, -1200, 1000, 550); // shelf roof + // for (let i = 0; i < 10; ++i) powerUps.spawn(550, -800, "ammo", false); + + function blockDoor(x, y, blockSize = 58) { + spawn.mapRect(x, y - 290, 40, 60); // door lip + spawn.mapRect(x, y, 40, 50); // door lip + for (let i = 0; i < 4; ++i) spawn.bodyRect(x + 5, y - 260 + i * blockSize, 30, blockSize); + } + + spawn.mapRect(2500, -1200, 200, 750); //right wall + spawn.mapRect(2500, -200, 200, 300); //right wall + spawn.mapRect(4500, -1200, 200, 650); //right wall + blockDoor(4585, -310) + spawn.mapRect(4500, -300, 200, 400); //right wall + spawn.mapRect(6400, -1200, 400, 750); //right wall + spawn.mapRect(6400, -200, 400, 300); //right wall + spawn.mapRect(6700, -1800, 800, 2600); //right wall + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 100); //exit bump + //place to hide + spawn.mapRect(4650, -300, 1150, 50); + spawn.mapRect(5750, -300, 50, 200); + spawn.mapRect(5575, -100, 50, 125); + spawn.mapRect(5300, -275, 50, 175); + spawn.mapRect(5050, -100, 50, 150); + spawn.mapRect(4850, -275, 50, 175); + spawn.mapRect(-950, -3250, 850, 1750); + //roof + spawn.mapRect(-175, -2975, 300, 1425); + spawn.mapRect(75, -2650, 325, 1150); + spawn.mapRect(375, -2225, 250, 650); + spawn.mapRect(4075, -2125, 700, 800); + spawn.mapRect(4450, -2950, 675, 1550); + spawn.mapRect(4875, -3625, 725, 2225); + spawn.mapRect(5525, -4350, 1725, 2925); + spawn.mapRect(7200, -5125, 300, 3900); + + + //??? + // m.addHealth(Infinity) + + // spawn.starter(1900, -500, 200) //big boy + // spawn.starter(1900, -500, 100) //big boy + // for (let i = 0; i < 10; ++i) spawn.launcher(1900, -500) + // spawn.suckerBoss(1900, -500) + // spawn.launcherBoss(3200, -500) + // spawn.laserTargetingBoss(1700, -500) + // spawn.powerUpBoss(1900, -500) + // spawn.powerUpBossBaby(3200, -500) + // spawn.dragonFlyBoss(1700, -500) + // spawn.streamBoss(3200, -500) + // spawn.pulsarBoss(1700, -500) + // spawn.spawnerBossCulture(3200, -500) + // spawn.grenadierBoss(1700, -500) + // spawn.growBossCulture(3200, -500) + // spawn.blinkBoss(1700, -500) + // spawn.snakeSpitBoss(3200, -500) + // spawn.laserBombingBoss(1700, -500) + // spawn.launcherBoss(3200, -500) + // spawn.blockBoss(1700, -500) + // spawn.blinkBoss(3200, -500) + // spawn.spiderBoss(1700, -500) + // spawn.tetherBoss(1700, -500) //go to actual level? + // spawn.revolutionBoss(1900, -500) + // spawn.bomberBoss(1400, -500) + // spawn.cellBossCulture(1600, -500) + // spawn.shieldingBoss(1700, -500) + + // for (let i = 0; i < 10; ++i) spawn.bodyRect(1600 + 5, -500, 30, 40); + // for (let i = 0; i < 4; i++) spawn.starter(1900, -500) + // spawn.pulsar(1900, -500) + // spawn.shield(mob[mob.length - 1], 1900, -500, 1); + // mob[mob.length - 1].isShielded = true + // spawn.nodeGroup(1200, 0, "grenadier") + // spawn.blinkBoss(1200, -500) + // spawn.suckerBoss(2900, -500) + // spawn.randomMob(1600, -500) + }, + null() { + level.levels.pop(); //remove lore level from rotation + // level.onLevel-- + // console.log(level.onLevel, level.levels) + //start a conversation based on the number of conversations seen + if (localSettings.loreCount > lore.conversation.length - 1) localSettings.loreCount = lore.conversation.length - 1; //repeat final conversation if lore count is too high + if (!simulation.isCheating && localSettings.loreCount < lore.conversation.length) { + lore.testSpeechAPI() //see if speech is working + lore.chapter = localSettings.loreCount //set the chapter to listen to to be the lore level (you can't use the lore level because it changes during conversations) + lore.sentence = 0 //what part of the conversation to start on + lore.conversation[lore.chapter][lore.sentence]() + localSettings.loreCount++ //hear the next conversation next time you win + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + // const hazardSlime = level.hazard(-1800, 150, 3600, 650, 0.004, "hsla(160, 100%, 35%,0.75)") + level.isHazardRise = false //this is set to true to make the slime rise up + const hazardSlime = level.hazard(-1800, -800, 3600, 1600, 0.004) + hazardSlime.height -= 950 + hazardSlime.min.y += 950 + hazardSlime.max.y = hazardSlime.min.y + hazardSlime.height + const circle = { + x: 0, + y: -500, + radius: 50 + } + level.custom = () => { + //draw wide line + ctx.beginPath(); + ctx.moveTo(circle.x, -800) + ctx.lineTo(circle.x, circle.y) + ctx.lineWidth = 40; + ctx.strokeStyle = lore.talkingColor //"#d5dddd" //"#bcc"; + ctx.globalAlpha = 0.03; + ctx.stroke(); + ctx.globalAlpha = 1; + //support pillar + ctx.fillStyle = "rgba(0,0,0,0.2)"; + ctx.fillRect(-25, 0, 50, 1000); + + //draw circles + ctx.beginPath(); + ctx.arc(circle.x, circle.y, circle.radius, 0, 2 * Math.PI); + ctx.fillStyle = "#bcc" + ctx.fill(); + ctx.lineWidth = 2; + ctx.strokeStyle = "#abb"; + ctx.stroke(); + + ctx.beginPath(); + ctx.arc(circle.x, circle.y, circle.radius / 8, 0, 2 * Math.PI); + ctx.fillStyle = lore.talkingColor //"#dff" + ctx.fill(); + + // level.enter.draw(); + }; + let sway = { + x: 0, + y: 0 + } + let phase = -Math.PI / 2 + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.1)"; + ctx.fillRect(-1950, -950, 3900, 1900); + //draw center circle lines + ctx.beginPath(); + const step = Math.PI / 20 + const horizontalStep = 85 + if (simulation.isCheating) phase += 0.3 * Math.random() * Math.random() //(m.pos.x - circle.x) * 0.0005 //0.05 * Math.sin(simulation.cycle * 0.030) + // const sway = 5 * Math.cos(simulation.cycle * 0.007) + sway.x = sway.x * 0.995 + 0.005 * (m.pos.x - circle.x) * 0.05 //+ 0.04 * Math.cos(simulation.cycle * 0.01) + sway.y = 2.5 * Math.sin(simulation.cycle * 0.015) + for (let i = -19.5; i < 20; i++) { + const where = { + x: circle.x + circle.radius * Math.cos(i * step + phase), + y: circle.y + circle.radius * Math.sin(i * step + phase) + } + ctx.moveTo(where.x, where.y); + ctx.bezierCurveTo(sway.x * Math.abs(i) + where.x, where.y + 25 * Math.abs(i) + 60 + sway.y * Math.sqrt(Math.abs(i)), + sway.x * Math.abs(i) + where.x + horizontalStep * i, where.y + 25 * Math.abs(i) + 60 + sway.y * Math.sqrt(Math.abs(i)), + horizontalStep * i, -800); + } + ctx.lineWidth = 0.5; + ctx.strokeStyle = "#899"; + ctx.stroke(); + hazardSlime.query(); + if (level.isHazardRise) hazardSlime.level(true) + //draw wires + // ctx.beginPath(); + // ctx.moveTo(-500, -800); + // ctx.quadraticCurveTo(-800, -100, -1800, -375); + // ctx.moveTo(-600, -800); + // ctx.quadraticCurveTo(-800, -200, -1800, -325); + // ctx.lineWidth = 1; + // ctx.strokeStyle = "#9aa"; + // ctx.stroke(); + }; + level.setPosToSpawn(0, -50); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 25, 100, 10); + level.exit.x = 0; + level.exit.y = 40000; + level.defaultZoom = 1000 + simulation.zoomTransition(level.defaultZoom) + // document.body.style.backgroundColor = "#aaa"; + document.body.style.backgroundColor = "#ddd"; + color.map = "#586363" //808f8f" + + spawn.mapRect(-3000, 800, 5000, 1200); //bottom + spawn.mapRect(-2000, -2000, 5000, 1200); //ceiling + spawn.mapRect(-3000, -2000, 1200, 3400); //left + spawn.mapRect(1800, -1400, 1200, 3400); //right + + spawn.mapRect(-500, 0, 1000, 50); //center platform + spawn.mapRect(-500, -25, 25, 50); //edge shelf + spawn.mapRect(475, -25, 25, 50); //edge shelf + }, + initialPowerUps() { + //wait to spawn power ups until unpaused + //power ups don't spawn in experiment mode, so they don't get removed at the start of experiment mode + const goal = simulation.cycle + 10 + function cycle() { + if (simulation.cycle > goal) { + if (localSettings.loreCount === 6) { + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2170, "field", false); + } else { + powerUps.spawnStartingPowerUps(2095 + 20 * (Math.random() - 0.5), -2200); + } + if (simulation.difficultyMode === 1) { + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2600, "ammo", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2550, "ammo", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2400, "heal", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2350, "heal", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2350, "heal", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2100, "research", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2060, "research", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2120, "research", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2075, "research", false); + } else if (simulation.difficultyMode > 4) { + + } else { + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2300, "heal", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2100, "heal", false); + powerUps.spawn(2095 + 20 * (Math.random() - 0.5), -2060, "research", false); + } + //spin the power ups to prevent them from stacking awkwardly + for (let i = 0; i < powerUp.length; i++) { + Matter.Body.setAngularVelocity(powerUp[i], 5 * (Math.random() - 0.5)) + } + } else { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + }, + initial() { + if (level.levelsCleared === 0) { //if this is the 1st level of the game + if (simulation.difficultyMode > 2) spawn.setSpawnList() // don't begin with starter mobs + level.initialPowerUps() + if (level.levelsCleared === 0) powerUps.directSpawn(-60, -950, "difficulty", false); + + if (!simulation.isCheating && !m.isShipMode && !build.isExperimentRun) { + spawn.wireFoot(); + spawn.wireFootLeft(); + spawn.wireKnee(); + spawn.wireKneeLeft(); + spawn.wireHead(); + } else { + simulation.isCheating = true; + } + + if (localSettings.levelsClearedLastGame < 3) { + } else if (!build.isExperimentRun) { + simulation.trails(70) + //bonus power ups for clearing runs in the last game + if (!simulation.isCheating && localSettings.levelsClearedLastGame > 1) { + for (let i = 0; i < localSettings.levelsClearedLastGame / 3; i++) powerUps.spawn(2095 + 2 * Math.random(), -1270 - 50 * i, "tech", false); //spawn a tech for levels cleared in last game + simulation.inGameConsole(`for (let i = 0; i < localSettings.levelsClearedLastGame / 3; i++)`); + simulation.inGameConsole(`{ powerUps.spawn(m.pos.x, m.pos.y, "tech") //simulation superposition}`); + localSettings.levelsClearedLastGame = 0 //after getting bonus power ups reset run history + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + } + spawn.mapRect(2025, 0, 150, 50); //lid to floor hole + } else { + for (let i = 0; i < 60; i++) { + setTimeout(() => { + if (level.levels[level.onLevel] === "initial") spawn.sneaker(2100, -1500 - 50 * i); + }, 2000 + 500 * i); + } + } + + const wires = new Path2D() //pre-draw the complex lighting path to save processing + wires.moveTo(-150, -275) + wires.lineTo(80, -275) + wires.lineTo(80, -1000) + wires.moveTo(-150, -265) + wires.lineTo(90, -265) + wires.lineTo(90, -1000) + wires.moveTo(-150, -255) + wires.lineTo(100, -255) + wires.lineTo(100, -1000) + wires.moveTo(-150, -245) + wires.lineTo(1145, -245) + wires.lineTo(1145, 0) + wires.moveTo(-150, -235) + wires.lineTo(1135, -235) + wires.lineTo(1135, 0) + wires.moveTo(-150, -225) + wires.lineTo(1125, -225) + wires.lineTo(1125, 0) + wires.moveTo(-150, -215) + wires.lineTo(460, -215) + wires.lineTo(460, 0) + wires.moveTo(-150, -205) + wires.lineTo(450, -205) + wires.lineTo(450, 0) + wires.moveTo(-150, -195) + wires.lineTo(440, -195) + wires.lineTo(440, 0) + + wires.moveTo(1155, 0) + wires.lineTo(1155, -450) + wires.lineTo(1000, -450) + wires.lineTo(1000, -1000) + wires.moveTo(1165, 0) + wires.lineTo(1165, -460) + wires.lineTo(1010, -460) + wires.lineTo(1010, -1000) + wires.moveTo(1175, 0) + wires.lineTo(1175, -470) + wires.lineTo(1020, -470) + wires.lineTo(1020, -1000) + wires.moveTo(1185, 0) + wires.lineTo(1185, -480) + wires.lineTo(1030, -480) + wires.lineTo(1030, -1000) + wires.moveTo(1195, 0) + wires.lineTo(1195, -490) + wires.lineTo(1040, -490) + wires.lineTo(1040, -1000) + + wires.moveTo(1625, -1000) + wires.lineTo(1625, 0) + wires.moveTo(1635, -1000) + wires.lineTo(1635, 0) + wires.moveTo(1645, -1000) + wires.lineTo(1645, 0) + wires.moveTo(1655, -1000) + wires.lineTo(1655, 0) + wires.moveTo(1665, -1000) + wires.lineTo(1665, 0) + + wires.moveTo(1675, -465) + wires.lineTo(2325, -465) + wires.lineTo(2325, 0) + wires.moveTo(1675, -455) + wires.lineTo(2315, -455) + wires.lineTo(2315, 0) + wires.moveTo(1675, -445) + wires.lineTo(2305, -445) + wires.lineTo(2305, 0) + wires.moveTo(1675, -435) + wires.lineTo(2295, -435) + wires.lineTo(2295, 0) + + wires.moveTo(2335, 0) + wires.lineTo(2335, -710) + wires.lineTo(2600, -710) + wires.moveTo(2345, 0) + wires.lineTo(2345, -700) + wires.lineTo(2600, -700) + wires.moveTo(2355, 0) + wires.lineTo(2355, -690) + wires.lineTo(2600, -690) + + let isSpawnedWarp = false + level.custom = () => { + if (!isSpawnedWarp && simulation.testing) { + isSpawnedWarp = true + powerUps.directSpawn(m.pos.x, -900, "warp") + // powerUps.directSpawn(2100, -1200, "warp") + } + //working on a message using text + // ctx.font = "50px Arial"; + // ctx.fillStyle = "rgba(0,0,0,0.3)" + // for (let i = 0; i < 5; i++) { + // const wiggle = 2 + // ctx.fillText("move", 500 + wiggle * Math.random(), -500 + wiggle * Math.random()); + // ctx.fillText("move", 500, -400); + // } + + //push around power ups stuck in the tube wall + if (!(simulation.cycle % 30)) { + for (let i = 0, len = powerUp.length; i < len; i++) { + if (powerUp[i].name === "instructions") { + if (simulation.isCheating) { + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + break + } + } else if (powerUp[i].position.y < -1000) { + powerUp[i].force.x += 0.01 * (Math.random() - 0.5) * powerUp[i].mass + } + + } + } + //draw binary number + const binary = (localSettings.runCount >>> 0).toString(2) + const height = 20 + const width = 8 + const yOff = -40 //-580 + let xOff = -130 //2622 + ctx.strokeStyle = "#bff" + ctx.lineWidth = 1.5; + ctx.beginPath() + for (let i = 0; i < binary.length; i++) { + if (binary[i] === "0") { + ctx.moveTo(xOff, yOff) + ctx.lineTo(xOff, yOff + height) + ctx.lineTo(xOff + width, yOff + height) + ctx.lineTo(xOff + width, yOff) + ctx.lineTo(xOff, yOff) + xOff += 10 + width + } else { + ctx.moveTo(xOff, yOff) + ctx.lineTo(xOff, yOff + height) + xOff += 10 + } + } + ctx.stroke(); + + ctx.beginPath() + ctx.strokeStyle = "#ccc" + ctx.lineWidth = 5; + ctx.stroke(wires); + + //squares that look like they keep the wires in place + ctx.beginPath() + ctx.rect(1600, -500, 90, 100) + ctx.rect(-55, -285, 12, 100) + ctx.rect(1100, -497, 8, 54) + ctx.rect(2285, -200, 80, 10) + ctx.rect(1110, -70, 100, 10) + ctx.fillStyle = "#ccc" + ctx.fill() + + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(2600, -600, 400, 300) + + // level.enter.draw(); + level.exit.drawAndCheck(); + }; + + level.customTopLayer = () => { + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(2600, -600, 400, 300) + //draw shade for ceiling tech + ctx.fillStyle = "rgba(68, 68, 68,0.95)" + ctx.fillRect(2030, -2800, 150, 1800); + ctx.fillRect(2030, 0, 150, 1800); + ctx.fillStyle = "rgba(68, 68, 68,0.98)" + // ctx.fillRect(-2750, -300, 2600, 125); + ctx.fillRect(-2925, -2800, 2775, 2650); + }; + level.setPosToSpawn(460, -100); //normal spawn + // level.enter.x = -1000000; //hide enter graphic for first level by moving to the far left + level.exit.x = 2800; + level.exit.y = -335; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1000 //1400 is normal + level.defaultZoom = 1600 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = "#e1e1e1"; + + // spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(-2750, -2800, 2600, 2515); + spawn.mapRect(-3275, -185, 3125, 1985); + requestAnimationFrame(() => { powerUps.directSpawn(-2315, -3050, "instructions", false); }); + spawn.mapRect(-3275, -2800, 400, 3250); + spawn.mapRect(-2775, -575, 50, 25); + spawn.mapRect(-2775, -950, 50, 25); + spawn.mapRect(-2775, -1325, 50, 25); + spawn.mapRect(-2775, -1700, 50, 25); + spawn.mapRect(-2775, -2075, 50, 25); + spawn.mapRect(-2775, -2450, 50, 25); + + spawn.mapRect(3000, -2800, 2600, 4600); //right wall + // spawn.mapRect(-250, 0, 3600, 1800); //ground + spawn.mapRect(-250, 0, 2300, 1800); //ground + + // Matter.Body.setVelocity(map[map.length - 1], { x: 10, y: -10 }); + spawn.mapRect(2150, 0, 1200, 1800); //ground + spawn.mapRect(2025, -3, 25, 15); //lip on power up chamber + spawn.mapRect(2150, -3, 25, 15); //lip on power up chamber + + // spawn.mapRect(-250, -2800, 3600, 1800); //roof + spawn.mapRect(-250, -2800, 2300, 1800); //split roof + map[map.length - 1].friction = 0 + map[map.length - 1].frictionStatic = 0 + spawn.mapRect(2150, -2800, 1200, 1800); //split roof + map[map.length - 1].friction = 0 + map[map.length - 1].frictionStatic = 0 + spawn.mapRect(2025, -1010, 25, 13); //lip on power up chamber + spawn.mapRect(2150, -1010, 25, 13); //lip on power up chamber + + spawn.mapRect(2600, -300, 500, 500); //exit shelf + spawn.mapRect(2600, -1200, 500, 600); //exit roof + spawn.mapRect(-95, -1100, 80, 110); //wire source + spawn.mapRect(410, -10, 90, 20); //small platform for player + + spawn.bodyRect(2425, -120, 70, 50); + spawn.bodyRect(2400, -100, 100, 60); + spawn.bodyRect(2500, -150, 100, 130); //exit step + }, + final() { + // color.map = "rgba(0,0,0,0.8)" + const slime = level.hazard(simulation.isHorizontalFlipped ? 150 - 860 : -150, -360, 880, 259) //x, y, width, height, damage = 0.002) { + slime.height -= slime.maxHeight - 150 //start slime at zero + slime.min.y += slime.maxHeight + slime.max.y = slime.min.y + slime.height + level.custom = () => { + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + slime.query(); + slime.levelRise(0.1) + + ctx.fillStyle = "rgba(0,255,255,0.1)" + ctx.fillRect(5385, -550, 300, 250) + }; + + level.setPosToSpawn(0, -250); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + spawn.mapRect(5500, -330 + 20, 100, 20); //spawn this because the real exit is in the wrong spot + level.exit.x = 0; + level.exit.y = -8000; + + level.defaultZoom = 2500 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#ddd"; + + for (let i = 0; i < 16; i++) powerUps.spawn(4600 + 40 * i, -30, "ammo"); + if (simulation.difficultyMode > 5) for (let i = 0; i < 8; i++) powerUps.spawn(4600 + 40 * i, -30, "ammo"); //extra ammo on why difficulty + + spawn.mapRect(-1950, 0, 8200, 1800); //ground + spawn.mapRect(-1950, -1500, 1800, 1900); //left wall + spawn.mapRect(-1950, -3300, 8200, 1800); //roof + spawn.mapRect(-250, -200, 1000, 300); // shelf + spawn.mapRect(-250, -1700, 1000, 1250); // shelf roof + spawn.mapRect(705, -210, 25, 50); + spawn.mapRect(725, -220, 25, 50); + spawn.bodyRect(750, -125, 125, 125); + spawn.bodyRect(875, -50, 50, 50); + + spawn.mapRect(5400, -1700, 400, 1150); //right wall + spawn.mapRect(5400, -300, 400, 400); //right wall + spawn.mapRect(5700, -3300, 1800, 5100); //right wall + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 100); //exit bump + spawn.mapRect(5403, -650, 400, 450); //blocking exit + if (mobs.mobDeaths < level.levelsCleared && !simulation.isCheating) { //pacifist run + for (let i = 0; i < 250; i++) spawn.starter(1000 + 4000 * Math.random(), -1500 * Math.random()) + } else { + spawn.finalBoss(3000, -750) + } + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + + level.setPosToSpawn(0, -250); + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + slime.query(); + slime.levelRise(0.1) + ctx.fillStyle = "rgba(0,255,255,0.1)" + ctx.fillRect(-5385 - 300, -550, 300, 250) + }; + } + if (mobs.mobDeaths < level.levelsCleared && localSettings.loreCount > 5 && !simulation.isCheating) { + //open door for pacifist run on final lore chapter + if (simulation.isHorizontalFlipped) { + level.exit.x = -5500 - 100; + } else { + level.exit.x = 5500; + } + level.exit.y = -330; + Matter.Composite.remove(engine.world, map[map.length - 1]); + map.splice(map.length - 1, 1); + simulation.draw.setPaths(); //redraw map draw path + level.levels.push("null") + } + }, + gauntlet() { + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,255,255,0.1)" + ctx.fillRect(6400, -550, 300, 350) + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-175, -975, 900, 575) + }; + level.setPosToSpawn(0, -475); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 6500; + level.exit.y = -230; + level.defaultZoom = 1500 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#ddd"; + + // spawn.mapRect(-300, -1050, 300, 200); + // Matter.Body.setAngle(map[map.length - 1], -Math.PI / 4) + + + spawn.mapRect(-950, 0, 8200, 800); //ground + spawn.mapRect(-950, -1200, 800, 1400); //left wall + spawn.mapRect(-950, -1800, 8200, 800); //roof + spawn.mapRect(175, -700, 575, 950); + spawn.mapRect(-250, -425, 600, 650); + spawn.mapRect(-250, -1200, 1000, 250); // shelf roof + powerUps.spawnStartingPowerUps(600, -800); + spawn.blockDoor(710, -710); + spawn.mapRect(2500, -1200, 200, 750); //right wall + spawn.blockDoor(2585, -210) + spawn.mapRect(2500, -200, 200, 300); //right wall + + spawn.mapRect(4500, -1200, 200, 750); //right wall + spawn.blockDoor(4585, -210) + spawn.mapRect(4500, -200, 200, 300); //right wall + + spawn.mapRect(6400, -1200, 400, 750); //right wall + spawn.mapRect(6400, -200, 400, 300); //right wall + spawn.mapRect(6700, -1800, 800, 2600); //right wall + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 100); //exit bump + + + if (mobs.mobDeaths < level.levelsCleared && !simulation.isCheating) { //pacifist run + spawn.pickList.splice(0, 1); + spawn.pickList.push('starter'); + spawn.pickList.splice(0, 1); + spawn.pickList.push('starter'); + spawn.starter(1500, -200, 150 + Math.random() * 30); + spawn.nodeGroup(3500, -200, 'starter'); + spawn.lineGroup(5000, -200, 'starter'); + for (let i = 0; i < 3; ++i) { + if (simulation.difficulty * Math.random() > 15 * i) spawn.nodeGroup(2000 + 500 * (Math.random() - 0.5), -800 + 200 * (Math.random() - 0.5), 'starter'); + if (simulation.difficulty * Math.random() > 10 * i) spawn.lineGroup(3500 + 500 * (Math.random() - 0.5), -800 + 200 * (Math.random() - 0.5), 'starter'); + if (simulation.difficulty * Math.random() > 7 * i) spawn.nodeGroup(5000 + 500 * (Math.random() - 0.5), -800 + 200 * (Math.random() - 0.5), 'starter'); + } + } else { + spawn[spawn.pickList[0]](1500, -200, 150 + Math.random() * 30); + spawn.nodeGroup(3500, -200, spawn.allowedGroupList[Math.floor(Math.random() * spawn.allowedGroupList.length)]); + spawn.lineGroup(5000, -200, spawn.allowedGroupList[Math.floor(Math.random() * spawn.allowedGroupList.length)]); + for (let i = 0; i < 3; ++i) { + if (simulation.difficulty * Math.random() > 15 * i) spawn.randomGroup(2000 + 500 * (Math.random() - 0.5), -800 + 200 * (Math.random() - 0.5), Infinity); + if (simulation.difficulty * Math.random() > 10 * i) spawn.randomGroup(3500 + 500 * (Math.random() - 0.5), -800 + 200 * (Math.random() - 0.5), Infinity); + if (simulation.difficulty * Math.random() > 7 * i) spawn.randomGroup(5000 + 500 * (Math.random() - 0.5), -800 + 200 * (Math.random() - 0.5), Infinity); + } + } + if (simulation.difficulty > 1) { + spawn.randomLevelBoss(5750, -600); + spawn.secondaryBossChance(4125, -350) + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + level.setPosToSpawn(0, -475); + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,255,255,0.1)" + ctx.fillRect(-6400 - 300, -550, 300, 350) + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(175 - 900, -975, 900, 575) + }; + } + }, + subway() { + // simulation.enableConstructMode() //tech.giveTech('motion sickness') //used to build maps in testing mode + // m.maxHealth = m.health = 100 + // color.map = "#333" //custom map color + document.body.style.backgroundColor = "#e3e3e3"//"#e3e3e3"//color.map//"#333"//"#000" + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom) + level.setPosToSpawn(450 * (Math.random() < 0.5 ? 1 : -1), -300); //normal spawn + // spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //entrance bump disabled for performance + level.exit.x = 0; + level.exit.y = -9000; + // spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 100); //exit bump disabled for performance + const stationWidth = 9000 + let stationNumber = 0; + let stationCustom = () => { } + let stationCustomTopLayer = () => { } + const train = [] + train.push(level.transport(1475, -200, 500, 25, 30)) + train[train.length - 1].isMoving = false + train[train.length - 1].stops = { left: 1725, right: 7225 } + train.push(level.transport(-1475 - 500, -200, 500, 25, -30)) + train[train.length - 1].isMoving = false + train[train.length - 1].stops = { left: -7225, right: -1725 } + + const stationList = [] //use to randomize station order + for (let i = 1, totalNumberOfStations = 10; i < totalNumberOfStations; ++i) stationList.push(i) //!!!! update station number when you add a new station + shuffle(stationList); + stationList.splice(0, 3); //remove some stations to keep it to 4 stations + stationList.unshift(0) //add index zero to the front of the array + + let isExitOpen = false + let gatesOpenRight = -1 + let gatesOpenLeft = -1 + const infrastructure = (x, isInProgress = true) => { + if (isInProgress) { + spawn.setSpawnList(); //picks a couple mobs types for a themed random mob spawns + function removeAll(array) { + for (let i = 0; i < array.length; ++i) Matter.Composite.remove(engine.world, array[i]); + } + removeAll(map); + map = []; + removeAll(composite); + composite = [] + //remove any powerUp that is too far from player + for (let i = 0; i < powerUp.length; ++i) { + if (Vector.magnitudeSquared(Vector.sub(player.position, powerUp[i].position)) > 9000000) { //remove any powerUp farther then 3000 pixels from player + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i--, 1) + } + } + //remove any mob that is too far from player + for (let i = 0; i < mob.length; ++i) { + if (Vector.magnitudeSquared(Vector.sub(player.position, mob[i].position)) > 4000000 && !mob[i].isDarkMatter) { //remove any mob farther then 2000 pixels from player + mob[i].removeConsBB() + mob[i].removeCons() + mob[i].leaveBody = false + mob[i].alive = false + Matter.Composite.remove(engine.world, mob[i]); + mob.splice(i--, 1) + } + } + } + const checkGate = (gate, gateButton) => { + if (gate) { //check status of buttons and gates + gate.isClosing = gateButton.isUp + gate.openClose(true); + if (gateButton.isUp) { + gateButton.query(); + if (!gateButton.isUp) { + simulation.inGameConsole(`station gate opened`, 360); + if (stationNumber > 0) { + if (!isExitOpen && gatesOpenRight < stationNumber) level.newLevelOrPhase() //run some new level tech effects + gatesOpenRight = stationNumber + } else if (stationNumber < 0) { + if (!isExitOpen && gatesOpenLeft > stationNumber) level.newLevelOrPhase() //run some new level tech effects + gatesOpenLeft = stationNumber + } else { //starting station both doors open + gatesOpenLeft = stationNumber + gatesOpenRight = stationNumber + } + if (Math.abs(stationNumber) > 0 && ((Math.abs(stationNumber) + 1) % stationList.length) === 0) { + simulation.inGameConsole(`level exit opened`, 360); + isExitOpen = true; + } + } + } + // gateButton.draw(); + if (gateButton.isUp) { + //aura around button + ctx.beginPath(); + ctx.ellipse(gateButton.min.x + gateButton.width * 0.5, gateButton.min.y + 6, 0.75 * gateButton.width, 0.5 * gateButton.width, 0, Math.PI, 0); //ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) + ctx.fillStyle = `hsla(345, 100%, 80%,${0.1 + 0.4 * Math.random()})` + ctx.fill(); + ctx.fillStyle = "hsl(345, 100%, 75%)" + ctx.fillRect(gateButton.min.x, gateButton.min.y - 10, gateButton.width, 25) + ctx.strokeStyle = "#000"//"rgba(255,255,255,0.2)" + ctx.lineWidth = 2 + ctx.strokeRect(gateButton.min.x, gateButton.min.y - 10, gateButton.width, 25) + } else { + ctx.fillStyle = "hsl(345, 100%, 75%)" + ctx.fillRect(gateButton.min.x, gateButton.min.y, gateButton.width, 10) + ctx.strokeStyle = "#000"//"rgba(255,255,255,0.2)" + ctx.lineWidth = 2 + ctx.strokeRect(gateButton.min.x, gateButton.min.y, gateButton.width, 10) + } + } + } + const stations = [ //update totalNumberOfStations as you add more stations + () => { //empty starting station + if (isExitOpen) { + level.exit.x = x - 50; + level.exit.y = -260; + if (simulation.difficultyMode < 7) powerUps.spawn(level.exit.x, level.exit.y - 100, "tech"); + } else { + var gateButton = level.button(x - 62, -237, 125, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber === 0 && gatesOpenRight === -1 && gatesOpenLeft === -1) { + var gateR = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + var gateL = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + for (let i = 0; i < 10; ++i) powerUps.chooseRandomPowerUp(x + 800 * (Math.random() - 0.5), -300 - 100 * Math.random())//only spawn heal or ammo once at the first station + } + } + + spawn.mapRect(x + -1400, -750, 3375, 100); //roof + spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + // spawn.mapRect(x + -550, -220, 1125, 100); //floor + // spawn.mapRect(x + -475, -230, 975, 150);//floor + spawn.mapVertex(x + 0, -200, "400 0 -400 0 -300 -80 300 -80"); //hexagon but wide + + // spawn.mapRect(x + -1350, -550, 50, 150); + // spawn.mapRect(x + 1300, -550, 50, 150); + stationCustom = () => { }; + stationCustomTopLayer = () => { + checkGate(gateR, gateButton) + checkGate(gateL, gateButton) + }; + }, + () => { //portal maze + const buttonsCoords = [{ x: x + 50, y: -1595 }, { x: x + 637, y: -2195 }, { x: x - 1487, y: -2145 }] + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + spawn.mapRect(x + -1775, -1600, 3400, 1000); //center pillar + spawn.mapRect(x + -4100, -3325, 8000, 700); //roof + spawn.mapRect(x + -4100, -3325, 325, 1500); + spawn.mapRect(x + 3500, -3325, 400, 1500); + spawn.mapRect(x + -225, -700, 450, 600); //lower portal blocks + + //upper parts + spawn.mapRect(x + -1425, -2400, 1900, 50); + spawn.mapRect(x + -775, -2750, 575, 1045); + spawn.mapRect(x + 475, -1900, 450, 375); + spawn.mapRect(x + 2225, -2300, 125, 350); + spawn.mapRect(x + 2550, -2350, 700, 50); + spawn.mapRect(x + 1375, -2850, 125, 650); + spawn.mapRect(x + 600, -2200, 200, 195); + spawn.mapRect(x + -3500, -2275, 825, 75); + spawn.mapRect(x + -1550, -2150, 250, 250); + spawn.mapRect(x + -2575, -2450, 275, 345); + + if (!isExitOpen) { + if (Math.random() < 0.5) { + spawn.randomMob(x + 2850, -2425, 0); + spawn.randomMob(x + 2275, -2425, 0); + spawn.randomMob(x + 2000, -2150, 0); + spawn.randomMob(x + 1650, -2150, 0); + spawn.randomMob(x + 1000, -2475, 0); + spawn.randomMob(x + 725, -2450, 0); + spawn.randomMob(x + 525, -2175, 0); + spawn.randomMob(x + 200, -1950, 0); + spawn.randomMob(x + -25, -1825, 0); + spawn.randomMob(x + -975, -2000, 0); + spawn.randomMob(x + -1500, -2225, 0); + spawn.randomMob(x + 1850, -2125, 0); + spawn.randomMob(x + 225, -1975, 0); + spawn.randomMob(x + 25, -1950, 0); + spawn.randomMob(x + 25, -1950, 0); + } else { + spawn.randomMob(x + 250, -1850, 0); + spawn.randomMob(x + 225, -1950, 0); + spawn.randomMob(x + 125, -2000, 0); + spawn.randomMob(x + 0, -1800, 0); + spawn.randomMob(x + -1725, -2300, 0); + spawn.randomMob(x + -2025, -2175, 0); + spawn.randomMob(x + -2050, -2250, 0); + spawn.randomMob(x + -2000, -2350, 0); + spawn.randomMob(x + -2950, -2400, 0); + spawn.randomMob(x + -2775, -2400, 0); + spawn.randomMob(x + -2425, -2550, 0); + spawn.randomMob(x + 1950, -2225, 0); + spawn.randomMob(x + -2700, -2100, 0); + spawn.randomMob(x + -1925, -2175, 0); + spawn.randomMob(x + -825, -2050, 0); + } + } + + const portal1 = level.portal({ x: x - 250, y: -310 }, Math.PI, + { x: x + -3750, y: -2100 }, 0) + const portal2 = level.portal({ x: x + 250, y: -310 }, 0, + { x: x + 3475, y: -2100 }, Math.PI) + const portal3 = level.portal({ x: x - 800, y: -2500 }, Math.PI, + { x: x - 175, y: -2500 }, 0) + const portal4 = level.portal({ x: x + 1275, y: -1700 }, Math.PI, + { x: x - 1275, y: -1700 }, 0) + stationCustom = () => { + portal1[2].query() + portal1[3].query() + portal2[2].query() + portal2[3].query() + portal3[2].query() + portal3[3].query() + portal4[2].query() + portal4[3].query() + } + stationCustomTopLayer = () => { + checkGate(gate, gateButton) + portal1[0].draw(); + portal1[1].draw(); + portal1[2].draw(); + portal1[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + portal3[0].draw(); + portal3[1].draw(); + portal3[2].draw(); + portal3[3].draw(); + portal4[0].draw(); + portal4[1].draw(); + portal4[2].draw(); + portal4[3].draw(); + } + }, + () => { //opening and closing doors + const buttonsCoords = [{ x: x - 800, y: -2245 }, { x: x + 250, y: -870 }, { x: x + 1075, y: -1720 }, { x: x - 1600, y: -1995 }] + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + + if (!isExitOpen) { + if (Math.random() < 0.5) { + spawn.randomMob(x + 1125, -650, 0); + spawn.randomMob(x + 150, -950, 0); + spawn.randomMob(x + 100, -975, 0); + spawn.randomMob(x + 75, -975, 0); + spawn.randomMob(x + 275, -1225, 0); + spawn.randomMob(x + 825, -975, 0); + spawn.randomMob(x + -50, -1625, 0); + spawn.randomMob(x + -950, -1550, 0); + spawn.randomMob(x + -975, -1550, 0); + spawn.randomMob(x + -900, -2500, 0); + spawn.randomMob(x + -975, -2550, 0); + spawn.randomMob(x + 675, -1950, 0); + spawn.randomMob(x + 675, -2550, 0); + spawn.randomMob(x + 1225, -1825, 0); + spawn.randomMob(x + -750, -2450, 0); + spawn.randomMob(x + -700, -825, 0); + } else { + spawn.randomMob(x + -675, -675, 0); + spawn.randomMob(x + -575, -925, 0); + spawn.randomMob(x + -425, -1100, 0); + spawn.randomMob(x + -225, -1225, 0); + spawn.randomMob(x + -650, -1250, 0); + spawn.randomMob(x + -675, -775, 0); + spawn.randomMob(x + 75, -1000, 0); + spawn.randomMob(x + -1100, -1575, 0); + spawn.randomMob(x + -1250, -1850, 0); + spawn.randomMob(x + -1625, -2100, 0); + spawn.randomMob(x + -700, -2500, 0); + spawn.randomMob(x + -375, -2550, 0); + spawn.randomMob(x + 250, -2025, 0); + spawn.randomMob(x + 675, -2175, 0); + spawn.randomMob(x + -1000, -2000, 0); + spawn.randomMob(x + -1550, -2325, 0); + spawn.randomMob(x + -1725, -2425, 0); + } + } + + spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + spawn.mapRect(x + -2550, -3200, 425, 1375);//roof left wall + spawn.mapRect(x + 2125, -3175, 450, 1375);//roof right wall + spawn.mapRect(x + -2550, -3200, 5125, 225);//roof + + spawn.mapRect(x + -1325, -550, 1375, 50);//first floor roof/ground + spawn.mapRect(x + 775, -550, 675, 50); + spawn.mapRect(x + -200, -875, 1300, 50); //2nd floor roof/ground + spawn.mapRect(x + -125, -1125, 50, 275); + spawn.mapRect(x + -125, -1150, 800, 50); //3rd floor roof/ground + spawn.mapRect(x + -1450, -1475, 1600, 50); + spawn.mapRect(x + -1325, -1725, 800, 50); //4th floor roof/ground + spawn.mapRect(x + 50, -1725, 1350, 50); + spawn.mapRect(x + -1125, -2250, 700, 50); + + spawn.mapRect(x, -525, 50, 150); //door cap for ground at ground y = -210 + const door1 = level.doorMap(x + 12, -380, 25, 170, 140, 20, false) //x, y, width, height, distance, speed = 20 + spawn.mapRect(x - 200, -525 - 340, 50, 150); //door cap for ground at ground y = -210 + const door2 = level.doorMap(x - 188, -380 - 340, 25, 170, 140, 20, false) //x, y, width, height, distance, speed = 20 + spawn.mapRect(x + 100, -525 - 940, 50, 150); //door cap for ground at ground y = -210 + const door3 = level.doorMap(x + 112, -380 - 940, 25, 170, 140, 20, false) //x, y, width, height, distance, speed = 20 + spawn.mapRect(x + 450, -3050, 50, 775); + const door4 = level.doorMap(x + 462, -2300, 25, 575, 520, 30, false) //x, y, width, height, distance, speed = 20 + + const portal1 = level.portal({ + x: x + 2100, + y: -2100 + }, Math.PI, { //right + x: x + -1275, + y: -650 + }, 2 * Math.PI) //right + + stationCustom = () => { + door1.isClosing = (simulation.cycle % 240) < 120 + door1.openClose(true); + door2.isClosing = (simulation.cycle % 240) > 120 + door2.openClose(true); + door3.isClosing = (simulation.cycle % 240) < 120 + door3.openClose(true); + door4.isClosing = (simulation.cycle % 240) > 120 + door4.openClose(true); + portal1[2].query() + portal1[3].query() + } + stationCustomTopLayer = () => { + checkGate(gate, gateButton) + portal1[0].draw(); + portal1[1].draw(); + portal1[2].draw(); + portal1[3].draw(); + } + }, + () => { //slime + const buttonsCoords = [{ x: x - 675, y: -895 }, { x: x - 750, y: -70 }, { x: x + 75, y: -570 },] + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + + + spawn.mapRect(x + -1575, -2000, 3025, 100); //roof + // spawn.mapRect(x + -1575, -2200, 3025, 300); //roof + // spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + spawn.mapRect(x + -1500, -210, 500, 350); //station floor left + spawn.mapRect(x + 1000, -210, 500, 350); //station floor right + spawn.mapRect(x + 900, -1250, 125, 1250); + spawn.mapRect(x - 1025, -1550, 125, 1625); + spawn.mapRect(x - 50, -1900, 100, 1500); + spawn.mapRect(x + -975, -1250, 200, 25); + spawn.mapRect(x + -950, -625, 150, 25); + spawn.mapRect(x - 925, -400, 250, 175); + spawn.mapRect(x - 725, -900, 225, 300); + spawn.mapRect(x + 325, -225, 325, 75); + spawn.mapRect(x + 400, -950, 275, 25); + spawn.mapRect(x + 775, -575, 200, 25); + spawn.mapRect(x + 0, -1225, 125, 25); + spawn.mapRect(x + 0, -575, 225, 175); + spawn.mapRect(x - 925, -75, 875, 150); + spawn.mapRect(x + 475, -1400, 75, 1250); + + if (!isExitOpen) { + if (Math.random() < 0.5) { + spawn.randomMob(x + -850, -450, 0); + spawn.randomMob(x + -850, -125, 0); + spawn.randomMob(x + -725, -100, 0); + spawn.randomMob(x + 0, -100, 0); + spawn.randomMob(x + 800, -50, 0); + spawn.randomMob(x + 50, -275, 0); + spawn.randomMob(x + -300, -425, 0); + spawn.randomMob(x + -750, -475, 0); + spawn.randomMob(x + -850, -775, 0); + spawn.randomMob(x + -650, -1000, 0); + spawn.randomMob(x + -150, -1325, 0); + spawn.randomMob(x + -825, -1350, 0); + spawn.randomMob(x + -375, -150, 0); + } else { + spawn.randomMob(x + 350, -350, 0); + spawn.randomMob(x + 175, -700, 0); + spawn.randomMob(x + 350, -1175, 0); + spawn.randomMob(x + 200, -1600, 0); + spawn.randomMob(x + 500, -1675, 0); + spawn.randomMob(x + 425, -50, 0); + spawn.randomMob(x + 725, -75, 0); + spawn.randomMob(x + 650, -700, 0); + spawn.randomMob(x + 775, -1150, 0); + spawn.randomMob(x + 500, -1675, 0); + spawn.randomMob(x + -150, -175, 0); + spawn.randomMob(x + -800, -150, 0); + } + } + + const boost1 = level.boost(x - 1185, -225, 1400) + const boost2 = level.boost(x + 1100, -225, 1100) + const hazard1 = level.hazard(x - 900, -1225, 1800, 1225) + let isSlimeRiseUp = false + const drip = [] + drip.push(level.drip(x - 900 + 1800 * Math.random(), -1900, 0, 100)) // drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + drip.push(level.drip(x - 900 + 1800 * Math.random(), -1900, 0, 150)) + drip.push(level.drip(x - 900 + 1800 * Math.random(), -1900, 0, 70)) + // drip.push(level.drip(x - 900 + 1800 * Math.random(), -1900, 0, 210)) + // drip.push(level.drip(x - 900 + 1800 * Math.random(), -1900, 0, 67)) + stationCustom = () => { + for (let i = 0; i < drip.length; i++) drip[i].draw() + // drip1.draw(); + // drip2.draw(); + // drip3.draw(); + } + stationCustomTopLayer = () => { + checkGate(gate, gateButton) + + hazard1.query(); + hazard1.level(isSlimeRiseUp, 1.5) + if (!(hazard1.height < hazard1.maxHeight)) { + isSlimeRiseUp = false + } else if (!(hazard1.height > 0)) { + isSlimeRiseUp = true + } + boost1.query(); + boost2.query(); + } + }, + () => { //portal fling + const buttonsCoords = [{ x: x + 775, y: -1695 }, { x: x - 775, y: -800 }, { x: x - 375, y: -2080 },] + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + spawn.mapRect(x + -1600, -3450, 300, 1475); //roof + spawn.mapRect(x + -1600, -3450, 3225, 100); + spawn.mapRect(x + 1300, -3450, 325, 1525); + + spawn.mapVertex(x + 400, -180, "-300 0 -300 -100 300 -100 400 0"); + spawn.mapVertex(x - 400, -180, "300 0 300 -100 -300 -100 -400 0"); + spawn.mapRect(x + -1500, -210, 1425, 350); //station floor left + spawn.mapRect(x + 75, -210, 1425, 350); //station floor right + spawn.mapRect(x + 75, -950, 50, 450); + spawn.mapRect(x + 125, -700, 1225, 200); + spawn.mapRect(x + -1325, -1775, 775, 175); + spawn.mapVertex(x + 445, -800, "-200 0 -200 -300 100 -300 185 0"); + spawn.mapVertex(x - 310, -1880, "-185 0 -100 -400 400 -400 400 0"); + spawn.mapVertex(x + -675, -725, "325 0 250 80 -250 80 -325 0 -250 -80 250 -80"); + spawn.mapRect(x + 625, -1700, 750, 500); + + if (!isExitOpen) { + spawn.randomMob(x + -750, -1925, 0); + spawn.randomMob(x + -425, -2300, 0); + spawn.randomMob(x + -350, -2200, 0); + spawn.randomMob(x + -275, -2175, 0); + spawn.randomMob(x + -375, -2175, 0); + spawn.randomMob(x + 1075, -1850, 0); + spawn.randomMob(x + 925, -1775, 0); + spawn.randomMob(x + 1150, -1800, 0); + spawn.randomMob(x + 1400, -2150, 0); + spawn.randomMob(x + 925, -850, 0); + spawn.randomMob(x + 800, -800, 0); + spawn.randomMob(x + 875, -825, 0); + spawn.randomMob(x + 1050, -900, 0); + spawn.randomMob(x + 19050, -2925, 0); + spawn.randomMob(x + 17150, -3150, 0); + spawn.randomMob(x + 17700, -3300, 0); + } + const portal1 = level.portal({ + x: x + 0, + y: -200 + }, -Math.PI / 2, { //up + x: x + 200, + y: -900 + }, -Math.PI / 2) //up + const portal2 = level.portal({ + x: x + 1275, + y: -800 + }, Math.PI, { //right + x: x + -1275, + y: -1875 + }, 2 * Math.PI) //right + + stationCustom = () => { + portal1[2].query(true) + portal1[3].query(true) + portal2[2].query() + portal2[3].query() + } + stationCustomTopLayer = () => { + checkGate(gate, gateButton) + portal1[0].draw(); + portal1[1].draw(); + portal1[2].draw(); + portal1[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + } + }, + () => { //tower levels and squares + const buttonsCoords = [{ x: x - 300, y: -3120 }, { x: x + 600, y: -3020 }, { x: x - 575, y: -1770 }, { x: x - 450, y: -2370 }] + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + + spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + spawn.mapRect(x + -1625, -3950, 3225, 350);//roof + spawn.mapRect(x + 1300, -3850, 300, 2150); //roof wall + spawn.mapRect(x + -1625, -3950, 325, 2250); //roof wall + spawn.mapRect(x + -1050, -575, 1000, 75); + spawn.mapRect(x + 175, -575, 975, 75); + spawn.mapRect(x + -1050, -825, 150, 275); + spawn.mapRect(x + -900, -1200, 2275, 75); + spawn.mapRect(x + 125, -1425, 1250, 300); + spawn.mapRect(x + -925, -1775, 2100, 75); + spawn.mapRect(x + -100, -2050, 950, 350); + spawn.mapRect(x + -925, -2100, 100, 400); + spawn.mapRect(x + -700, -2375, 1225, 75); + spawn.mapRect(x + 650, -2375, 575, 75); + spawn.mapRect(x + -25, -2750, 350, 269); + spawn.mapRect(x + -950, -3125, 975, 75); + spawn.mapRect(x + 325, -3025, 900, 75); + spawn.bodyRect(x + -125, -1325, 225, 125, 0.3); + spawn.bodyRect(x + -225, -2100, 300, 50, 0.3); + spawn.bodyRect(x + -225, -2575, 100, 200, 0.3); + spawn.bodyRect(x + 850, -2575, 150, 200, 0.3); + spawn.bodyRect(x + 850, -1875, 75, 100, 0.3); + spawn.bodyRect(x + 500, -725, 175, 150, 0.3); + spawn.bodyRect(x + -925, -2250, 100, 150, 0.3); + spawn.bodyRect(x + -1050, -950, 150, 125, 0.3); + + const mobPlacement = [ + () => { //1st floor + spawn.randomMob(x + -775, -725, 0); + spawn.randomMob(x + -575, -700, 0); + spawn.randomMob(x + -275, -700, 0); + spawn.randomMob(x + -125, -650, 0); + spawn.randomMob(x + 250, -675, 0); + spawn.randomMob(x + 425, -650, 0); + spawn.randomMob(x + 775, -650, 0); + spawn.randomMob(x + 1050, -675, 0); + spawn.randomMob(x + 675, -950, 0); + spawn.randomMob(x + -625, -900, 0); + spawn.randomMob(x + -750, -1400, 0); + spawn.randomMob(x + -500, -2025, 0); + spawn.randomMob(x + -125, -3225, 0); + }, + () => { //2nd floor + spawn.randomMob(x + -950, -925, 0); + spawn.randomMob(x + -775, -1325, 0); + spawn.randomMob(x + -450, -1500, 0); + spawn.randomMob(x + -325, -1250, 0); + spawn.randomMob(x + 0, -1500, 0); + spawn.randomMob(x + 375, -1525, 0); + spawn.randomMob(x + 750, -1550, 0); + spawn.randomMob(x + 1175, -1550, 0); + spawn.randomMob(x + -875, -1350, 0); + spawn.randomMob(x + -875, -2375, 0); + spawn.randomMob(x + 175, -2850, 0); + spawn.randomMob(x + 750, -2475, 0); + }, + () => {//3rd floor + spawn.randomMob(x + 1075, -2000, 0); + spawn.randomMob(x + 725, -2125, 0); + spawn.randomMob(x + 350, -2125, 0); + spawn.randomMob(x + -325, -2000, 0); + spawn.randomMob(x + -675, -1875, 0); + spawn.randomMob(x + -725, -2200, 0); + spawn.randomMob(x + -675, -2575, 0); + spawn.randomMob(x + -425, -2675, 0); + spawn.randomMob(x + -50, -2875, 0); + spawn.randomMob(x + 425, -2725, 0); + spawn.randomMob(x + 1150, -2550, 0); + spawn.randomMob(x + 1150, -2175, 0); + spawn.randomMob(x + 1000, -1900, 0); + spawn.randomMob(x + 500, -2550, 0); + spawn.randomMob(x + 125, -2900, 0); + }, + () => {//all floors + spawn.randomMob(x + 1000, -850, 0); + spawn.randomMob(x + 300, -850, 0); + spawn.randomMob(x + -450, -825, 0); + spawn.randomMob(x + -1025, -1125, 0); + spawn.randomMob(x + -750, -1375, 0); + spawn.randomMob(x + -225, -1375, 0); + spawn.randomMob(x + 625, -1525, 0); + spawn.randomMob(x + 1025, -1925, 0); + spawn.randomMob(x + -425, -2100, 0); + spawn.randomMob(x + -400, -2650, 0); + spawn.randomMob(x + 150, -3000, 0); + spawn.randomMob(x + 675, -3200, 0); + spawn.randomMob(x + -550, -3300, 0); + + }, + ] + if (!isExitOpen) mobPlacement[Math.floor(Math.random() * mobPlacement.length)]()//different random mob placements, with mobs clustered to surprise player + stationCustom = () => { } + stationCustomTopLayer = () => { + checkGate(gate, gateButton) + } + }, + () => { //jump pads and 6 sided platforms + const buttonsCoords = [{ x: x + 278, y: -1814 }, { x: x + 778, y: -1814 }, { x: x + 2025, y: -1995 }, { x: x - 2025, y: -2425 }, { x: x - 2100, y: -1995 }] + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + + spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + spawn.mapRect(x + -3200, -3200, 300, 1400); //roof left wall + spawn.mapRect(x + 2600, -3200, 300, 1400);//roof right wall + spawn.mapRect(x + -3175, -3200, 6175, 225);//roof + if (Math.random() < 0.3) spawn.mapRect(x + -1350, -550, 150, 50); //wall ledge + if (Math.random() < 0.3) spawn.mapRect(x + 1175, -550, 200, 50); //wall ledge + spawn.mapVertex(x + 600, -900, "490 0 350 80 -350 80 -490 0 -350 -80 350 -80"); //hexagon but wide + spawn.mapVertex(x - 600, -750, "490 0 350 80 -350 80 -490 0 -350 -80 350 -80"); //hexagon but wide + spawn.mapVertex(x - 100, -1850, "-100 -300 0 -350 100 -300 100 300 0 350 -100 300"); //hexagon but tall + spawn.mapVertex(x + -600, -2000, "-150 -450 150 -450 150 450 0 525 -150 450"); //hexagon but big and tall and flat + spawn.mapVertex(x + 350, -1575, "-150 0 150 0 150 450 0 525 -150 450"); //hexagon but tall and flat top + spawn.mapVertex(x + 850, -1575, "-150 0 150 0 150 450 0 525 -150 450"); //hexagon but tall and flat top + spawn.mapVertex(x + -2050, -2350, "490 0 350 80 -350 80 -490 0 -350 -80 350 -80"); //left top corner hexagon but wide + spawn.mapVertex(x + 1700, -2450, "-100 -300 0 -350 100 -300 100 300 0 350 -100 300"); //hexagon but tall + + const mobPlacement = [ + () => { //rightish + spawn.randomMob(x + 2250, -2375, 0); + spawn.randomMob(x + 1950, -2825, 0); + spawn.randomMob(x + 1275, -2775, 0); + spawn.randomMob(x + 1450, -2200, 0); + spawn.randomMob(x + 825, -1950, 0); + spawn.randomMob(x + 400, -1875, 0); + spawn.randomMob(x + -75, -2275, 0); + spawn.randomMob(x + -650, -2550, 0); + spawn.randomMob(x + 1500, -2075, 0); + spawn.randomMob(x + 2125, -2650, 0); + spawn.randomMob(x + 2075, -2250, 0); + spawn.randomMob(x + 1000, -2850, 0); + spawn.randomMob(x + 750, -950, 0); + spawn.randomMob(x + -750, -1125, 0); + spawn.randomMob(x + -1575, -2050, 0); + }, + () => { //leftish + spawn.randomMob(x + -2225, -2125, 0); + spawn.randomMob(x + -2675, -2125, 0); + spawn.randomMob(x + -2600, -2600, 0); + spawn.randomMob(x + -2100, -2725, 0); + spawn.randomMob(x + -1425, -2600, 0); + spawn.randomMob(x + -1375, -2050, 0); + spawn.randomMob(x + -575, -2575, 0); + spawn.randomMob(x + -125, -2300, 0); + spawn.randomMob(x + 350, -1925, 0); + spawn.randomMob(x + -350, -1050, 0); + spawn.randomMob(x + -1000, -1000, 0); + spawn.randomMob(x + -700, -1300, 0); + spawn.randomMob(x + 350, -1150, 0); + spawn.randomMob(x + -575, -2525, 0); + spawn.randomMob(x + -1075, -2525, 0); + }, + () => {//centerish + spawn.randomMob(x + 25, -2275, 0); + spawn.randomMob(x + 300, -1975, 0); + spawn.randomMob(x + 700, -1950, 0); + spawn.randomMob(x + 325, -1200, 0); + spawn.randomMob(x + -225, -950, 0); + spawn.randomMob(x + -925, -975, 0); + spawn.randomMob(x + -675, -2575, 0); + spawn.randomMob(x + -1425, -2175, 0); + spawn.randomMob(x + 1575, -2075, 0); + spawn.randomMob(x + 2300, -2075, 0); + spawn.randomMob(x + 425, -1925, 0); + spawn.randomMob(x + 125, -2175, 0); + spawn.randomMob(x + -325, -2150, 0); + spawn.randomMob(x + -350, -950, 0); + spawn.randomMob(x + 600, -325, 0); + spawn.randomMob(x + -600, -375, 0); + }, + ] + if (!isExitOpen) mobPlacement[Math.floor(Math.random() * mobPlacement.length)]()//different random mob placements, with mobs clustered to surprise player + const boost1 = level.boost(x - 50, -225, 790) + const boost2 = level.boost(x + 550, -985, 900) + const boost3 = level.boost(x + -850, -835, 1900) + stationCustom = () => { } + stationCustomTopLayer = () => { + checkGate(gate, gateButton) + boost1.query(); + boost2.query(); + boost3.query(); + } + }, + () => { //crouch tunnels + const buttonsCoords = [{ x: x + 625, y: -1395 }, { x: x - 15, y: -1595 }, { x: x - 800, y: -1295 }] + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + spawn.mapRect(x + -1575, -2200, 3025, 300); //roof + spawn.mapRect(x + -1100, -925, 100, 425); + spawn.mapRect(x + -1100, -575, 375, 75); + spawn.mapRect(x + -925, -1300, 375, 125); + spawn.mapRect(x + -300, -1300, 620, 125); + spawn.mapRect(x + 450, -1400, 500, 225); + spawn.mapRect(x + 900, -550, 500, 50); + spawn.mapRect(x + 950, -925, 400, 270); + spawn.mapRect(x + 1250, -1250, 150, 75); + spawn.mapRect(x + -225, -525, 800, 210); + spawn.mapRect(x + -100, -1600, 300, 193); + spawn.mapRect(x + 925, -1250, 75, 75); + spawn.bodyRect(x + 200, -1475, 75, 175, 0.3); + spawn.bodyRect(x + -25, -625, 225, 100, 0.3); + spawn.bodyRect(x + -1000, -750, 125, 175, 0.3); + spawn.bodyRect(x + -625, -1450, 75, 150, 0.3); + spawn.bodyRect(x + -650, -300, 300, 75, 0.3); + if (!isExitOpen) { + spawn.randomMob(x + -750, -1425, 0); + spawn.randomMob(x + -1050, -1100, 0); + spawn.randomMob(x + -825, -750, 0); + spawn.randomMob(x + -500, -400, 0); + spawn.randomMob(x + 450, -650, 0); + spawn.randomMob(x + 0, -725, 0); + spawn.randomMob(x + 300, -1350, 0); + spawn.randomMob(x + 550, -1500, 0); + spawn.randomMob(x + 725, -1650, 0); + spawn.randomMob(x + 900, -1550, 0); + spawn.randomMob(x + 1100, -1300, 0); + spawn.randomMob(x + -1050, -1050, 0); + spawn.randomMob(x + -925, -350, 0); + spawn.randomMob(x + 75, -1750, 0); + spawn.randomMob(x + 1000, -375, 0); + } + stationCustom = () => { } + stationCustomTopLayer = () => { + checkGate(gate, gateButton) + ctx.fillStyle = "rgba(0,0,0,0.08)" + ctx.fillRect(x + -225, -325, 800, 125); + ctx.fillRect(x + -100, -1425, 300, 125); + ctx.fillRect(x + 950, -675, 400, 125); + } + }, + () => { //angled jumps + const buttonsCoords = [{ x: x + 50, y: -1395 }, { x: x - 625, y: -2945 }, { x: x + 900, y: -2945 }] + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + + spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + boosts = [] + boosts.push(level.boost(x - 311, -218, 1200, 1.85)) + spawn.mapRect(x + -225, -525, 675, 375); + spawn.mapRect(x + -1350, -1175, 400, 675); + spawn.mapRect(x + -225, -2125, 675, 400); + + // spawn.mapRect(x + -225, -1325, 675, 550); + spawn.mapRect(x + -225, -1400, 675, 650); + + boosts.push(level.boost(x - 1335, -1200, 1800, 1)) + boosts.push(level.boost(x + 1272, -1300, 1550, 2.75)) //far right + //high up walls + boosts.push(level.boost(x + 1455, -2048, 1450, 2.5)) + spawn.mapRect(x + 1500, -3825, 325, 1900); + boosts.push(level.boost(x - 1555, -2048, 1450, 0.64)) + // spawn.mapRect(x + -1625, -3975, 3450, 325); + spawn.mapRect(x + -1825, -4000, 325, 2150); + spawn.mapRect(x + -1825, -4070, 3650, 375);//roof + + spawn.randomMob(x + 100, -2125, 0); + boosts.push(level.boost(x + 75, -2175, 2800)) + spawn.mapRect(x + -100, -3900, 400, 400); + Matter.Body.setAngle(map[map.length - 1], map[map.length - 1].angle - Math.PI / 4); + + spawn.mapRect(x + 225, -2950, 1100, 150); + spawn.mapRect(x + -1325, -2950, 1325, 150); + + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + + if (!isExitOpen) { + spawn.randomMob(x + 350, -600, 0); + spawn.randomMob(x + -25, -600, 0); + spawn.randomMob(x + 600, -300, 0); + spawn.randomMob(x + 1050, -300, 0); + spawn.randomMob(x + 350, -1525, 0); + spawn.randomMob(x + -75, -1525, 0); + spawn.randomMob(x + -1075, -1275, 0); + spawn.randomMob(x + -1350, -2050, 0); + spawn.randomMob(x + -50, -2250, 0); + spawn.randomMob(x + -200, -3050, 0); + spawn.randomMob(x + -925, -3150, 0); + spawn.randomMob(x + 450, -3125, 0); + spawn.randomMob(x + 1075, -3025, 0); + spawn.randomMob(x + 750, -3125, 0); + spawn.randomMob(x + -725, -3125, 0); + } + stationCustom = () => { + for (let i = 0; i < boosts.length; i++) { + boosts[i].query() + } + } + stationCustomTopLayer = () => { + checkGate(gate, gateButton) + ctx.fillStyle = "rgba(0,0,0,0.08)" + ctx.fillRect(x - 225, -775, 675, 275); + ctx.fillRect(x - 225, -1750, 675, 375); + } + }, + () => { //people movers + simulation.removeEphemera("zoom")//stop previous zooms + simulation.zoomTransition(2000) + const buttonsCoords = [{ x: x - 65, y: -2045 }] //only one button location? + const buttonsCoordsIndex = Math.floor(Math.random() * buttonsCoords.length) //pick a random element from the array + const moverDirection = stationNumber > 0 ? 1 : -1 + console.log(stationNumber) + if (isExitOpen) { + level.exit.x = buttonsCoords[buttonsCoordsIndex].x; + level.exit.y = buttonsCoords[buttonsCoordsIndex].y - 25; + } else { + var gateButton = level.button(buttonsCoords[buttonsCoordsIndex].x, buttonsCoords[buttonsCoordsIndex].y, 126, false) //x, y, width = 126, isSpawnBase = true + gateButton.isUp = true + if (stationNumber > gatesOpenRight) { + var gate = level.doorMap(x + 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } else if (stationNumber < gatesOpenLeft) { + var gate = level.doorMap(x - 1375, -525, 50, 375, 300, 20, false) //x, y, width, height, distance, speed = 20 + } + } + + //floor 0 + spawn.mapRect(x + -1500, -210, 3000, 400);//station floor + const movers = [] + movers.push(level.mover(x + -1200, -220, 900, 50, 3 * moverDirection)) + movers.push(level.mover(x + 300, -220, 900, 50, 3 * moverDirection)) + spawn.mapRect(x + -4700, -7000, 700, 5200);//Left wall + spawn.mapRect(x + 4000, -7000, 500, 5200);//Right wall + const portals = [] + portals.push(level.portal({ x: x - 315, y: -310 }, Math.PI, { x: x - 3985, y: -2110 }, 0)) + spawn.mapRect(x - 1375, -1100, 2750, 300); + spawn.mapRect(x + -300, -525, 600, 550); + + //floor 1 fast with jump in middle + movers.push(level.mover(x - 4000, -2025, 2700, 50, 30 * moverDirection)) + movers.push(level.mover(x + 1300, -2025, 2700, 50, 30 * moverDirection)) + portals.push(level.portal({ x: x + 3985, y: -2110 }, Math.PI, { x: x - 3985, y: -3410 }, 0)) + spawn.mapRect(x + -500, -2050, 1000, 150); + spawn.mapRect(x + -4200, -2300, 1225, 125); + spawn.mapRect(x + 2675, -2350, 1625, 150); + //up mode triggered by player contact + const elevator0 = level.elevator(x - 1300, -1175, 175, 50, -1600, 0.011, { up: 0.01, down: 0.7 }) + const elevator1 = level.elevator(x + 1125, -1175, 175, 50, -1600, 0.011, { up: 0.01, down: 0.7 }) + + //floor 2 slow with some things to jump on and mobs + portals.push(level.portal({ x: x + 3985, y: -3410 }, Math.PI, { x: x - 3985, y: -5110 }, 0)) + movers.push(level.mover(x - 4000, -3325, 8000, 50, 7 * moverDirection)) + if (Math.random() < 0.5) { + spawn.mapRect(x + 1125, -3625, 325, 200); + spawn.mapRect(x - 1350, -3600, 375, 175); + spawn.mapRect(x + 325, -3825, 325, 100); + spawn.mapRect(x - 675, -3800, 450, 75); + spawn.mapRect(x - 1775, -3900, 175, 400); + spawn.mapRect(x - 2100, -4275, 325, 775); + spawn.mapRect(x + 2625, -3700, 450, 125); + spawn.mapRect(x - 3350, -3335, 175, 50); + spawn.mapRect(x - 200, -3335, 500, 50); + spawn.mapRect(x + 3200, -3335, 325, 50); + } else { + spawn.mapRect(x + -325, -3550, 425, 125); + spawn.mapRect(x + -1100, -3750, 425, 75); + spawn.mapRect(x + -2175, -3500, 200, 200); + spawn.mapRect(x + 675, -3700, 175, 75); + spawn.mapRect(x + 2375, -3425, 275, 125); + spawn.mapRect(x + 1750, -3650, 275, 75); + spawn.mapRect(x + 1125, -3850, 175, 550); + spawn.mapRect(x + -3300, -4175, 675, 550); + } + spawn.mapRect(x + 3550, -3625, 550, 100); + spawn.mapRect(x + -4100, -3650, 325, 100); + if (!isExitOpen) { + spawn.randomMob(x + 3900, -3725, 0); + spawn.randomMob(x + 3675, -3700, 0); + spawn.randomMob(x + 2075, -3400, 0); + spawn.randomMob(x + 2500, -3500, 0); + spawn.randomMob(x + 1975, -3700, 0); + spawn.randomMob(x + 1250, -3900, 0); + spawn.randomMob(x + 800, -3750, 0); + spawn.randomMob(x + 2700, -4700, 0); + spawn.randomMob(x + -75, -3650, 0); + spawn.randomMob(x + 575, -3500, 0); + spawn.randomMob(x + -850, -3900, 0); + spawn.randomMob(x + -2725, -4350, 0); + spawn.randomMob(x + -2975, -4300, 0); + spawn.randomMob(x + -3950, -3675, 0); + spawn.randomMob(x + -2950, -3450, 0); + spawn.randomMob(x + -2075, -3575, 0); + spawn.randomMob(x + -1650, -3450, 0); + spawn.randomMob(x + -2825, -4400, 0); + spawn.randomMob(x + -900, -4475, 0); + spawn.randomMob(x + -75, -3575, 0); + spawn.randomMob(x + 3900, -3775, 0); + spawn.randomMob(x + 2825, -3375, 0); + spawn.randomMob(x + 2075, -3425, 0); + spawn.randomMob(x + 1525, -3425, 0); + spawn.randomMob(x + 350, -3500, 0); + spawn.randomMob(x + -1675, -3650, 0); + spawn.randomMob(x + -3025, -3450, 0); + spawn.randomMob(x + -3850, -3750, 0); + } + + //floor 3 fast with bumps + spawn.mapRect(x + -4250, -7000, 8475, 325);//roof + portals.push(level.portal({ x: x + 3985, y: -5110 }, Math.PI, { x: x + 320, y: -310 }, 0)) + movers.push(level.mover(x - 4000, -5025, 8000, 50, 50 * moverDirection)) + if (Math.random() < 0.5) { + spawn.mapVertex(x - 2100, -5050, "-150 0 150 0 5 -150 -5 -150") + spawn.mapVertex(x - 0, -5100, "-500 0 500 0 25 -300 -25 -300") + spawn.mapVertex(x + 2100, -5050, "-300 0 300 0 100 -100 -100 -100") + } else { + spawn.mapVertex(x - 2100, -5050, "-100 0 100 0 25 -100 -25 -100") + spawn.mapVertex(x - 0, -5050, "-400 0 400 0 100 -100 -100 -100") + spawn.mapVertex(x + 2100, -5050, "-400 0 400 0 100 -100 -100 -100") + } + spawn.mapRect(x + 2000, -6700, 200, 1250); + spawn.mapRect(x + -100, -6700, 200, 1075); + spawn.mapRect(x + -2125, -6700, 50, 925); + // spawn.mapRect(x + -4150, -5325, 975, 125); //portal over hang + // spawn.mapRect(x + 3325, -5300, 850, 100);//portal over hang + + stationCustom = () => { + for (let i = 0; i < movers.length; i++) movers[i].push(); + for (let i = 0; i < portals.length; i++) { + portals[i][2].query() + portals[i][3].query() + } + } + stationCustomTopLayer = () => { + for (let i = 0; i < portals.length; i++) { + portals[i][0].draw() + portals[i][1].draw() + portals[i][2].draw() + portals[i][3].draw() + } + elevator0.moveOnTouch() + elevator1.moveOnTouch() + + //custom draw so you can see the mover tracks on subway map with the Line of sight graphics + ctx.strokeStyle = "#000" + ctx.lineWidth = 4; + ctx.setLineDash([40, 40]); + for (let i = 0; i < movers.length; i++) { + ctx.beginPath(); + ctx.moveTo(movers[i].vertices[0].x + 2, movers[i].vertices[0].y - 3); + ctx.lineTo(movers[i].vertices[1].x - 2, movers[i].vertices[1].y - 3); + ctx.lineDashOffset = (-simulation.cycle * movers[i].VxGoal) % 80; + ctx.stroke(); + } + ctx.setLineDash([0, 0]); + checkGate(gate, gateButton) + } + }, + ] + //update totalNumberOfStations to a higher number when adding new maps + simulation.zoomTransition(level.defaultZoom) + // stations[9]() //for testing a specific station + stations[stationList[Math.abs(stationNumber % stationList.length)]]() //*************** run this one when uploading + //add in standard station map infrastructure + spawn.mapRect(x + -8000, 0, 16000, 800);//tunnel floor + spawn.mapRect(x + 1500 - 200, -2000, 6400, 1500); //tunnel roof + spawn.mapRect(x + -1500 - 6400 + 200, -2000, 6400, 1500); //tunnel roof + + // add debris so you can see how fast the train moves + const debrisCount = 4 + const size = 18 + Math.random() * 25; + const wide = 6400 + if (isInProgress) { + //adds new map elements to the level while the level is already running + for (let i = 0; i < map.length; ++i) { + map[i].collisionFilter.category = cat.map; + map[i].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(map[i], true); //make static + Composite.add(engine.world, map[i]); //add to world + } + simulation.draw.setPaths() + simulation.draw.lineOfSightPrecalculation() //required precalculation for line of sight + + + //shift trains left/right, as you move left or right a train will jump over and become the train needed at the next station + let repositionTrain + let playerOnTrain + if (Math.abs(train[0].position.x - m.pos.x) > Math.abs(train[1].position.x - m.pos.x)) { //figure out which train the player is farthest from and move it + repositionTrain = train[0] + playerOnTrain = train[1] + } else { + repositionTrain = train[1] + playerOnTrain = train[0] + } + repositionTrain.isMoving = false + if (repositionTrain.position.x > playerOnTrain.position.x) { //decide if the train is moving left or right + Matter.Body.setPosition(repositionTrain, { x: -1725 + x, y: repositionTrain.position.y }); + repositionTrain.changeDirection(false) //go left + repositionTrain.stops = { right: -1725 + x, left: -7225 + x } + for (let i = 0; i < debrisCount; ++i) spawn.bodyRect(x + -1500 - 6400 + 200 + Math.random() * wide, -35, size * (0.6 + Math.random()), size * (0.6 + Math.random()), 1); + } else { + Matter.Body.setPosition(repositionTrain, { x: 1725 + x, y: repositionTrain.position.y }); + repositionTrain.changeDirection(true) //go right + repositionTrain.stops = { left: 1725 + x, right: 7225 + x } + for (let i = 0; i < debrisCount; ++i) spawn.bodyRect(x + 1500 - 200 + Math.random() * wide, -35, size * (0.6 + Math.random()), size * (0.6 + Math.random()), 1); + } + } else { + for (let i = 0; i < debrisCount; ++i) spawn.bodyRect(x + -1500 - 6400 + 200 + Math.random() * wide, -35, size * (0.6 + Math.random()), size * (0.6 + Math.random()), 1); + for (let i = 0; i < debrisCount; ++i) spawn.bodyRect(x + 1500 - 200 + Math.random() * wide, -35, size * (0.6 + Math.random()), size * (0.6 + Math.random()), 1); + } + } + infrastructure(0, false) //if this is run before the level starts, it needs a false + + level.custom = () => { + for (let i = 0; i < train.length; i++) train[i].trainStop() + ctx.fillStyle = "rgba(0,0,0,0.1)"//"#ddd" + ctx.fillRect(m.pos.x - 4000, m.pos.y - 4000, 8000, 8000) + level.exit.drawAndCheck(); + // level.enter.draw(); + + //track what station the player is in + if (m.pos.x > 0.55 * stationWidth + stationNumber * stationWidth) { + stationNumber++ + // if ((stationNumber % stationList.length) == 0) stationNumber++ //skip the stationNumber that is the modulus of the length of the stationList + infrastructure(stationNumber * stationWidth) + } else if (m.pos.x < -0.55 * stationWidth + stationNumber * stationWidth) { + stationNumber-- + // if ((stationNumber % stationList.length) == 0) stationNumber--//skip the stationNumber that is the modulus of the length of the stationList + infrastructure(stationNumber * stationWidth) + } + stationCustom() + }; + level.customTopLayer = () => { + for (let i = 0; i < train.length; i++) train[i].draw() + stationCustomTopLayer() + }; + level.isProcedural = true //only used in generating text for the level builder + simulation.draw.lineOfSightPrecalculation() //required precalculation for line of sight + simulation.draw.drawMapPath = simulation.draw.drawMapSight + }, + reservoir() { + level.announceMobTypes() + level.exit.x = 1700; + level.exit.y = -4510; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 25); + level.setPosToSpawn(-500, 850); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.defaultZoom = 2300 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + color.map = "#3d4240" + powerUps.spawnStartingPowerUps(-575, -2925) + //walls + spawn.mapRect(-3500, -5000, 1500, 6500); + spawn.mapRect(2000, -5000, 1500, 6500); + spawn.mapRect(-2500, 1100, 5000, 400); //slime floor + spawn.mapRect(-3500, -5475, 7000, 600); //top + spawn.mapRect(-1925, -4900, 175, 375); //pipe + spawn.mapRect(-1950, -4550, 225, 25); //pipe + //top floor exit + spawn.mapRect(1475, -4900, 50, 250); + spawn.mapRect(1400, -4475, 650, 50); + // ground + spawn.mapVertex(-687, 1060, "700 0 -700 0 -450 -300 450 -300"); //left base + spawn.mapVertex(863, 1060, "700 0 -700 0 -450 -300 450 -300"); //right base + //entrance + spawn.mapRect(-730, 525, 475, 50); + spawn.mapRect(-730, 550, 50, 150); + spawn.mapRect(-305, 550, 50, 500); + spawn.bodyRect(-717, 700, 25, 100); //door + spawn.bodyRect(-717, 800, 25, 100); //door + //1st floor //left + spawn.mapVertex(-1125 + 437, -50, "490 0 350 80 -350 80 -490 0 -350 -80 350 -80"); + spawn.mapRect(-1225, -100, 1070, 100); + if (Math.random() < 0.33) { + spawn.mapVertex(-687, -1000, "-100 -300 0 -350 100 -300 100 300 0 350 -100 300"); + } else if (Math.random() < 0.5) { + spawn.mapVertex(-687, -1000, "-150 -450 0 -525 150 -450 150 450 0 525 -150 450"); + } else { + spawn.mapVertex(-687, -700, "-150 0 150 0 150 450 0 525 -150 450"); + } + //right + spawn.mapVertex(425 + 437, -50, "490 0 350 80 -350 80 -490 0 -350 -80 350 -80"); + spawn.mapRect(325, -100, 1070, 100); + spawn.mapRect(175, 675, 425, 25); + spawn.mapRect(1125, 225, 425, 25); + spawn.mapRect(650, 450, 425, 25); + if (Math.random() < 0.33) { + spawn.mapVertex(855, -1000, "-100 -300 0 -350 100 -300 100 300 0 350 -100 300"); + } else if (Math.random() < 0.5) { + spawn.mapVertex(855, -1000, "-150 -450 0 -525 150 -450 150 450 0 525 -150 450"); + } else { + spawn.mapVertex(855, -700, "-150 0 150 0 150 450 0 525 -150 450"); + } + //2nd floor + spawn.mapVertex(-687, -1936, "-625 50 0 100 625 50 625 -50 -625 -50"); + spawn.mapVertex(855, -1936, "-625 50 0 100 625 50 625 -50 -625 -50"); + //2nd floor right building + spawn.mapRect(550, -3050, 600, 75); + spawn.bodyRect(-125, -2025, 475, 25); + spawn.mapRect(-925, -2350, 675, 50); + spawn.mapRect(-825, -2825, 425, 50); + spawn.mapRect(-450, -3125, 50, 350); + spawn.mapRect(-750, -3150, 350, 50); + spawn.mapRect(-650, -3400, 250, 300); + spawn.mapRect(-650, -3675, 200, 50); + spawn.bodyRect(-375, -2150, 100, 150, 0.2); + //2nd floor left pillar + spawn.mapRect(-1400, -2625, 325, 25); + spawn.mapRect(-1450, -3225, 425, 25); + spawn.mapRect(-1512.5, -3825, 550, 25); + + spawn.randomMob(1000, -275, 0.2); + spawn.randomMob(950, -1725, 0.1); + spawn.randomMob(-725, -1775, 0.1); + spawn.randomMob(-200, -2075, 0); + spawn.randomMob(-550, -3500, -0.2); + spawn.randomMob(375, -2125, 0); + spawn.randomMob(-700, -2450, -0.1); + spawn.randomMob(-1175, -2775, -0.1); + spawn.randomMob(1025, -3200, -0.2); + spawn.randomMob(-525, -3750, -0.2); + spawn.randomMob(1350, -2075, -0.3); + spawn.randomMob(1775, 1000, -0.4); + spawn.randomSmallMob(-575, -2925); + spawn.randomGroup(-400, -4400, 0); + if (simulation.difficulty > 1) { + spawn.randomLevelBoss(825, -3500); + spawn.secondaryBossChance(75, -1350) + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + const slime = level.hazard(-2000, -5000, 4000, 6060); // hazard(x, y, width, height, damage = 0.003) + slime.height -= slime.maxHeight - 60 //start slime at zero + slime.min.y += slime.maxHeight + slime.max.y = slime.min.y + slime.height + const elevator1 = level.elevator(-1625, -90, 310, 800, -2000, 0.0025, { up: 0.1, down: 0.2 }) //x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + const elevator2 = level.elevator(1175, -3050, 200, 250, -4475, 0.0025, { up: 0.12, down: 0.2 }) //x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + let waterFallWidth = 0 + let waterFallX = 0 + let waterFallSmoothX = 0 + let isWaterfallFilling = false + const riseRate = 0.30 + Math.min(1, simulation.difficulty * 0.005) + const spinnerArray = [] + if (simulation.isHorizontalFlipped) { //flip the map horizontally + spawn.mapVertex(584, -2500, "0 0 300 0 150 600 0 600"); + spawn.mapVertex(1116, -2500, "0 0 300 0 300 600 150 600"); + spawn.bodyRect(-200, -125, 625, 25); + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + elevator1.holdX = -elevator1.holdX // flip the elevator horizontally + elevator2.holdX = -elevator2.holdX // flip the elevator horizontally + spinnerArray.push(level.spinner(-110, -3325, 45, 600, 0.003, 0, 0, 0.01)) // spinner(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0) { + const boost1 = level.boost(-900, -2000, 790) + level.setPosToSpawn(500, 850); //normal spawn + level.custom = () => { + ctx.fillStyle = "#c0c3c9" ///!!!!!!!!!! for flipped x: newX = -oldX - width + ctx.fillRect(1468, -1975, 2, 1915) //elevator track + ctx.fillRect(-1274, -4460, 2, 1425) //elevator track + ctx.fillRect(1225, -3825, 25, 1850); //small pillar background + ctx.fillStyle = "#d0d4d6" + ctx.fillRect(275, -1925, 825, 2925) //large pillar background + ctx.fillRect(-1275, -1925, 825, 2925) //large pillar background + ctx.fillStyle = "#cff" //exit + ctx.fillRect(-2000, -4900, 525, 425) + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + boost1.query(); + elevator1.move(); + elevator2.move(); + ctx.fillStyle = "#233" + ctx.beginPath(); //central dot on spinners + ctx.arc(spinnerArray[0].pointA.x, spinnerArray[0].pointA.y, 9, 0, 2 * Math.PI); + for (let i = 0, len = spinnerArray.length; i < len; i++) { + ctx.moveTo(spinnerArray[i].pointA.x, spinnerArray[i].pointA.y) + ctx.arc(spinnerArray[i].pointA.x, spinnerArray[i].pointA.y, 9, 0, 2 * Math.PI); + } + ctx.fill(); + //shadow + ctx.fillStyle = "rgba(0,10,30,0.1)" + ctx.fillRect(-1150, -3000, 600, 1025); + ctx.fillRect(450, -3100, 300, 275); + ctx.fillRect(450, -3625, 200, 225); + ctx.fillRect(400, -2775, 425, 450); + ctx.fillRect(250, -2300, 675, 300); + slime.query(); + if (isWaterfallFilling) { + if (slime.height < 5500) { + //draw slime fill + ctx.fillStyle = `hsla(160, 100%, 43%,${0.3 + 0.07 * Math.random()})` + ctx.fillRect(waterFallX, -5050, waterFallWidth, 6175 - slime.height) + if (!m.isTimeDilated) { + waterFallWidth = 0.98 * waterFallWidth + 4.7 * Math.random() + waterFallSmoothX = 0.98 * waterFallSmoothX + 3.5 * Math.random() + waterFallX = 1857 - waterFallSmoothX + ctx.fillRect(waterFallX + waterFallWidth * Math.random(), -5050, 4, 6175 - slime.height) + //push player down if they go under waterfall + if (player.position.x > waterFallX && player.position.x < waterFallX + waterFallWidth && player.position.y < slime.height) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y + 2 + }); + } + } + slime.levelRise(riseRate) + } + } else if (Vector.magnitudeSquared(Vector.sub(player.position, level.enter)) > 100000) { + isWaterfallFilling = true + } + }; + } else { //not flipped + spawn.mapVertex(1116, -2500, "0 0 300 0 150 600 0 600"); + spawn.mapVertex(584, -2500, "0 0 300 0 300 600 150 600"); + if (Math.random() < 0.1) { + spinnerArray.push(level.spinner(65, -300, 40, 450, 0.003, Math.PI / 2)) + } else if (Math.random() < 0.25) { + spinnerArray.push(level.spinner(65, -500, 40, 500, 0.003, 0, 0, -0.015)) // spinner(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0) { + const r = 250 + const hexagon = `${r} 0 ${r * Math.cos(5.236)} ${r * Math.sin(5.236)} ${r * Math.cos(4.189)} ${r * Math.sin(4.189)} ${-r} 0 ${r * Math.cos(2.0944)} ${r * Math.sin(2.0944)} ${r * Math.cos(1.0472)} ${r * Math.sin(1.0472)} ` + Matter.Body.setVertices(spinnerArray[spinnerArray.length - 1].bodyB, Vertices.fromPath(hexagon)) + } else { + const W = 410; + const H = 30; + spawn.bodyRect(-120, -75, W, H, 1, spawn.propsIsNotHoldable) + let b = body[body.length - 1]; + cons[cons.length] = Constraint.create({ + pointA: { + x: b.position.x - (W / 2) + 50 - 211, + y: b.position.y - 1825 + }, + bodyB: b, + pointB: { + x: -(W / 2) + 50, + y: 0 + }, + damping: 0.01, + stiffness: 0.002, + length: 1800 + }); + cons[cons.length] = Constraint.create({ + pointA: { + x: b.position.x + (W / 2) - 50 + 211, + y: b.position.y - 1825 + }, + bodyB: b, + pointB: { + x: (W / 2) - 50, + y: 0 + }, + damping: 0.01, + stiffness: 0.002, + length: 1800 + }); + Composite.add(engine.world, [cons[cons.length - 1], cons[cons.length - 2]]) + } + + spinnerArray.push(level.spinner(50, -3325, 45, 600, 0.003, 0, 0, 0.01)) // spinner(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0) { + if (Math.random() < 0.5) { + const r = 200 + const hexagon = `${r} 0 ${r * Math.cos(5.236)} ${r * Math.sin(5.236)} ${r * Math.cos(4.189)} ${r * Math.sin(4.189)} ${-r} 0 ${r * Math.cos(2.0944)} ${r * Math.sin(2.0944)} ${r * Math.cos(1.0472)} ${r * Math.sin(1.0472)} ` + Matter.Body.setVertices(spinnerArray[spinnerArray.length - 1].bodyB, Vertices.fromPath(hexagon)) + } + + const boost1 = level.boost(800, -2000, 790) + + level.custom = () => { + ctx.fillStyle = "#c0c3c9" + ctx.fillRect(-1470, -1975, 2, 1915) //elevator track + ctx.fillRect(1276, -4460, 2, 1425) //elevator track + ctx.fillRect(-1250, -3825, 25, 1850); //small pillar background + ctx.fillStyle = "#d0d4d6" + ctx.fillRect(-1100, -1925, 825, 2925) //large pillar background + ctx.fillRect(450, -1925, 825, 2925) //large pillar background + ctx.fillStyle = "#cff" //exit + ctx.fillRect(1475, -4900, 525, 425) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + + level.customTopLayer = () => { + boost1.query(); + elevator1.move(); + elevator2.move(); + + ctx.fillStyle = "#233" + ctx.beginPath(); //central dot on spinners + ctx.arc(spinnerArray[0].pointA.x, spinnerArray[0].pointA.y, 9, 0, 2 * Math.PI); + for (let i = 0, len = spinnerArray.length; i < len; i++) { + ctx.moveTo(spinnerArray[i].pointA.x, spinnerArray[i].pointA.y) + ctx.arc(spinnerArray[i].pointA.x, spinnerArray[i].pointA.y, 9, 0, 2 * Math.PI); + } + ctx.fill(); + //shadow + ctx.fillStyle = "rgba(0,10,30,0.1)" + ctx.fillRect(550, -3000, 600, 1025); + ctx.fillRect(-750, -3100, 300, 275); + ctx.fillRect(-650, -3625, 200, 225); + ctx.fillRect(-825, -2775, 425, 450); + ctx.fillRect(-925, -2300, 675, 300); + + slime.query(); + if (isWaterfallFilling) { + if (slime.height < 5500) { + //draw slime fill + ctx.fillStyle = `hsla(160, 100%, 43%,${0.3 + 0.07 * Math.random()})` + ctx.fillRect(waterFallX, -5050, waterFallWidth, 6175 - slime.height) + if (!m.isTimeDilated) { + waterFallWidth = 0.98 * waterFallWidth + 4.7 * Math.random() + waterFallSmoothX = 0.98 * waterFallSmoothX + 3.5 * Math.random() + waterFallX = waterFallSmoothX - 1985 + ctx.fillRect(waterFallX + waterFallWidth * Math.random(), -5050, 4, 6175 - slime.height) + //push player down if they go under waterfall + if (player.position.x > waterFallX && player.position.x < waterFallX + waterFallWidth && player.position.y < slime.height) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y + 2 + }); + } + } + slime.levelRise(riseRate) + } + } else if (Vector.magnitudeSquared(Vector.sub(player.position, level.enter)) > 100000) { + isWaterfallFilling = true + } + }; + } + }, + reactor() { + level.exit.x = 3500; + level.exit.y = -42; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 25); + level.defaultZoom = 2000 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#c3d6df" //"#d8dadf"; + color.map = "#303639"; + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + + spawn.bodyRect(250, -70, 100, 70, 1); + spawn.mapRect(-425, 0, 4500, 2100); + spawn.mapRect(-475, -2825, 4500, 1025); + // spawn.mapRect(1200, -1300, 600, 800); + const a = 400 //side length + const c = 100 //corner offset + spawn.mapVertex(1487, -900, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${a - c} ${a - c} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off + //entrance + spawn.mapRect(-2025, -2825, 1250, 4925); + spawn.mapRect(-900, -2825, 1125, 1725); + spawn.mapRect(-900, -750, 1125, 2850); + spawn.mapRect(-325, -1250, 550, 300); + //exit + spawn.mapRect(3800, -2825, 1225, 4925); + spawn.mapRect(2750, -2150, 1325, 1775); + spawn.mapRect(2750, -475, 550, 300); + spawn.mapRect(2750, -7, 1050, 150); //exit room floor + + const doorIn = level.door(-313, -950, 525, 200, 190, 2) //x, y, width, height, distance, speed = 1 + const doorOut = level.door(2762, -175, 525, 200, 190, 2) //x, y, width, height, distance, speed = 1 + doorIn.collisionFilter.category = cat.map; + doorOut.collisionFilter.category = cat.map; // to prevent boson composite from letting the player skip the level + // doorOut.isClosing = true + let isDoorsLocked = false + let isFightOver = false + let isSpawnedBoss = false + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + level.setPosToSpawn(550, -800); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + + const button = level.button(-1500, 0) + button.isUp = true + + level.custom = () => { + if (isDoorsLocked) { + if (player.position.x > 300) { //if player gets trapped inside starting room open up again + isDoorsLocked = false + doorIn.isClosing = false + } + } + doorIn.openClose(); + doorOut.openClose(); + ctx.fillStyle = "#d5ebef" + ctx.fillRect(-3800, -375, 1050, 375) + level.enter.draw(); + level.exit.drawAndCheck(); + button.draw(); + if (button.isUp) { + button.query(); + } else if (!isSpawnedBoss) { + if (player.position.x < 0) { + if (!doorOut.isClosed() || !doorIn.isClosed()) { + doorIn.isClosing = true + doorOut.isClosing = true + //block caught in a door + if (Matter.Query.collides(doorOut, body).length > 1 || Matter.Query.collides(doorIn, body).length > 1) { + button.isUp = true + doorIn.isClosing = false + doorOut.isClosing = false + } + } else { + isSpawnedBoss = true + isDoorsLocked = true + for (let i = 0; i < 12; ++i) powerUps.spawn(-1800 + 550 * Math.random(), -1800, "ammo") + for (let i = 0; i < 5; ++i) powerUps.spawn(-1800 + 550 * Math.random(), -1700, "heal"); + for (let i = 0; i < 1; ++i) powerUps.spawn(-1800 + 550 * Math.random(), -1750, "research"); + const scale = Math.pow(simulation.difficulty, 0.7) + if (mobs.mobDeaths < level.levelsCleared && !simulation.isCheating) { + for (let i = 0; i < 250; i++) spawn.starter(-2700 + 2400 * Math.random(), -1300 - 500 * Math.random()) + } else { + if (Math.random() < 0.07 && simulation.difficulty > 35) { + for (let i = 0, len = scale * 0.22 / 6; i < len; ++i) spawn.timeBoss(-1327 - 200 * i, -1525, 60, false); //spawn 1-2 at difficulty 15 + for (let i = 0, len = scale * 0.1 / 6; i < len; ++i) spawn.bounceBoss(-1327 - 200 * i, -1525, 80, false); + for (let i = 0, len = scale * 0.13 / 6; i < len; ++i) spawn.sprayBoss(-1327 - 200 * i, -1525, 30, false) + for (let i = 0, len = scale * 0.25 / 6; i < len; ++i) spawn.mineBoss(-1327 - 200 * i, -1525, 50, false); + } else { + if (Math.random() < 0.25) { + for (let i = 0, len = scale * 0.22; i < len; ++i) spawn.timeBoss(-1327 - 200 * i, -1525, 80, false); //spawn 1-2 at difficulty 15 + } else if (Math.random() < 0.33) { + for (let i = 0, len = scale * 0.1; i < len; ++i) spawn.bounceBoss(-1327 - 200 * i, -1525, 80, false); //spawn 1-2 at difficulty 15 + } else if (Math.random() < 0.5) { + for (let i = 0, len = scale * 0.13; i < len; ++i) spawn.sprayBoss(-1327 - 200 * i, -1525, 30, false) //spawn 2-3 at difficulty 15 + } else { + for (let i = 0, len = scale * 0.25; i < len; ++i) spawn.mineBoss(-1327 - 200 * i, -1525, 50, false); //spawn 3-4 at difficulty 15 + } + } + } + } + } else { + doorIn.isClosing = false + } + } else if (!isFightOver && !(simulation.cycle % 180)) { + let isFoundBoss = false + for (let i = 0; i < mob.length; i++) { + if (mob[i].isReactorBoss) { + isFoundBoss = true + break + } + } + if (!isFoundBoss) { + isFightOver = true + doorIn.isClosing = false + doorOut.isClosing = false + // powerUps.spawnBossPowerUp(-3600, -100) + powerUps.spawn(-3650, -50, "tech") + powerUps.spawn(-3650, -150, "tech") + if (simulation.difficultyMode < 7) powerUps.spawn(-3650, -300, "tech") + } + } + }; + + level.customTopLayer = () => { + doorIn.draw(); + doorOut.draw(); + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-225, -1100, 1000, 350); + }; + } else { + level.setPosToSpawn(-550, -800); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + + const button = level.button(1400, 0) + button.isUp = true + + level.custom = () => { + if (isDoorsLocked) { + if (player.position.x < -300) { //if player gets trapped inside starting room open up again + isDoorsLocked = false + doorIn.isClosing = false + } + } + doorIn.openClose(); + doorOut.openClose(); + ctx.fillStyle = "#d5ebef" + ctx.fillRect(2750, -375, 1050, 375) + level.enter.draw(); + level.exit.drawAndCheck(); + button.draw(); + if (button.isUp) { + button.query(); + } else if (!isSpawnedBoss) { + if (player.position.x > 0) { + if (!doorOut.isClosed() || !doorIn.isClosed()) { + doorIn.isClosing = true + doorOut.isClosing = true + //block caught in a door + if (Matter.Query.collides(doorOut, body).length > 1 || Matter.Query.collides(doorIn, body).length > 1) { + button.isUp = true + doorIn.isClosing = false + doorOut.isClosing = false + } + } else { + isSpawnedBoss = true + isDoorsLocked = true + for (let i = 0; i < 9; ++i) powerUps.spawn(1200 + 550 * Math.random(), -1700, "ammo") + for (let i = 0; i < 3; ++i) powerUps.spawn(1200 + 550 * Math.random(), -1700, "heal"); + if (simulation.difficultyMode > 5) for (let i = 0; i < 8; i++) powerUps.spawn(1200 + 550 * Math.random(), -1700, "ammo"); //extra ammo on why difficulty + const scale = Math.pow(simulation.difficulty, 0.7) //hard around 30, why around 54 + if (mobs.mobDeaths < level.levelsCleared && !simulation.isCheating) { + for (let i = 0; i < 250; i++) spawn.starter(300 + 2400 * Math.random(), -1300 - 500 * Math.random()) + } else { + if (Math.random() < 0.07 && simulation.difficulty > 35) { + for (let i = 0, len = scale * 0.25 / 6; i < len; ++i) spawn.timeBoss(1487 + 200 * i, -1525, 60, false); //spawn 1-2 at difficulty 15 + for (let i = 0, len = scale * 0.1 / 6; i < len; ++i) spawn.bounceBoss(1487 + 200 * i, -1525, 80, false); + for (let i = 0, len = scale * 0.15 / 6; i < len; ++i) spawn.sprayBoss(1487 + 200 * i, -1525, 30, false) + for (let i = 0, len = scale * 0.26 / 6; i < len; ++i) spawn.mineBoss(1487 + 200 * i, -1525, 50, false); + } else { + if (Math.random() < 0.25) { + for (let i = 0, len = scale * 0.25; i < len; ++i) spawn.timeBoss(1487 + 200 * i, -1525, 80, false); //spawn 1-2 at difficulty 15 + } else if (Math.random() < 0.33) { + for (let i = 0, len = scale * 0.1; i < len; ++i) spawn.bounceBoss(1487 + 200 * i, -1525, 80, false); //spawn 1-2 at difficulty 15 + } else if (Math.random() < 0.5) { + for (let i = 0, len = scale * 0.15; i < len; ++i) spawn.sprayBoss(1487 + 200 * i, -1525, 30, false) //spawn 2-3 at difficulty 15 + } else { + for (let i = 0, len = scale * 0.26; i < len; ++i) spawn.mineBoss(1487 + 200 * i, -1525, 50, false); //spawn 3-4 at difficulty 15 + } + } + } + // spawn.secondaryBossChance(2200, -800) + } + } else { + doorIn.isClosing = false + } + } else if (!isFightOver && !(simulation.cycle % 180)) { + let isFoundBoss = false + for (let i = 0; i < mob.length; i++) { + if (mob[i].isBoss) { + isFoundBoss = true + break + } + } + if (!isFoundBoss) { + isFightOver = true + doorIn.isClosing = false + doorOut.isClosing = false + // powerUps.spawnBossPowerUp(3600, -100) + powerUps.spawn(3650, -50, "tech") + powerUps.spawn(3650, -150, "tech") + powerUps.spawn(3650, -300, "tech") + // if (player.position.x < 2760 && player.position.x > 210) {} + } + } + }; + + level.customTopLayer = () => { + doorIn.draw(); + doorOut.draw(); + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-775, -1100, 1000, 350); + }; + } + + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + towers() { + // simulation.isHorizontalFlipped = true + level.announceMobTypes() + const isFlippedHorizontal = (simulation.isHorizontalFlipped && Math.random() < 0.33) ? true : false + if (isFlippedHorizontal) { + level.setPosToSpawn(9150 + 50, -2230 - 25); + level.exit.x = 400 - 50; + level.exit.y = -50 + 25; + leftRoomColor = "#cff" + rightRoomColor = "rgba(0,0,0,0.13)" + } else { + level.setPosToSpawn(400, -50); + level.exit.x = 9150; + level.exit.y = -2230; + } + + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + level.fallMode = "position"; //must set level.fallModeBounds in this mode to prevent player getting stuck left or right + level.fallModeBounds = { left: level.enter.x, right: level.exit.x } //used with level.fallMode = "position"; + if (isFlippedHorizontal) level.fallModeBounds = { left: level.exit.x, right: level.enter.x } //used with level.fallMode = "position"; + simulation.fallHeight = 5000 //level.enter.y - 4000 + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 2300 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#cdd9df"; + powerUps.spawnStartingPowerUps(6300, 1025) + + const boost1 = level.boost(7560, 1480, 1700, 1.75) + const boost2 = level.boost(7098, 0, 1250, Math.PI / 3) //x,y,push,angle radians + const boost3 = level.boost(9700, -730, 1050, 1.95) + const boost4 = level.boost(4300, -720, 1500, 1.25) + const boost5 = level.boost(3000, -1215, 3000, 1.25) + const boost6 = level.boost(8251, -619, 1200, 2.7) + const boost7 = level.boost(7750, -1540, 1050, 1.2) + // const boost6 = level.boost(8235, -619, 3500, 2.9) + + const train1 = level.transport(3650, 100, 415, 500, 8); //x,y,width.height,VxGoal,force + const train2 = level.transport(1250, 100, 415, 500, -8); //x,y,width.height,VxGoal,force + const train3 = level.transport(4050, 100, 415, 500, 8); //x,y,width.height,VxGoal,force + + let portal1, portal2 + portal1 = level.portal({ + x: 3675, + y: -2225 + 1025 + }, -Math.PI / 2, { //up + x: 3675, + y: -375 + }, Math.PI / 2) //down + + portal2 = level.portal({ + x: 6300, + y: -1225 + }, -Math.PI / 2, { //up + x: 6300, + y: -375 + }, Math.PI / 2) //down + level.custom = () => { + boost1.query(); + boost2.query(); + boost3.query(); + boost4.query(); + boost5.query(); + boost6.query(); + boost7.query(); + //trains oscillate back and forth and act like they are bouncing off each other + if (train1.position.x < 2850) { + train1.changeDirection(true) //go right + } else if (train1.position.x > 3850) { + train1.changeDirection(false) //go left + } + if (train2.position.x < 1450) { + train2.changeDirection(true) //go right + } else if (train2.position.x > 2450) { + train2.changeDirection(false) //go left + } + if (train3.position.x < 4250) { + train3.changeDirection(true) //go right + } else if (train3.position.x > 5250) { + train3.changeDirection(false) //go left + } + train1.move(); + train2.move(); + train3.move(); + ctx.fillStyle = "rgba(0,0,0,0.25)" + ctx.fillRect(1250, 121, 4200, 6) + ctx.fillStyle = "rgba(50,70,100,0.04)" + ctx.fillRect(2500, -10000, 1800, 30000); + ctx.fillRect(8300, -10000, 1800, 30000); + ctx.fillRect(-500, -10000, 1800, 30000); + ctx.fillRect(5400, -10000, 1800, 30000); + + portal1[2].query() + portal1[3].query() + portal2[2].query() + portal2[3].query() + + ctx.fillStyle = "#cff" + if (isFlippedHorizontal) { + ctx.fillRect(150, -300, 525, 325); //entrance typically + } else { + ctx.fillRect(8925, -2575, 525, 400) //exit typically + } + + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.13)" + ctx.fillRect(8300, -1950, 1550, 1275); + ctx.fillRect(5400, 875, 1800, 650); + ctx.fillRect(2950, -2200, 875, 1050); + ctx.fillRect(5900, -1025, 800, 450); + if (isFlippedHorizontal) { + ctx.fillRect(8925, -2575, 575, 400) //exit typically + } else { + ctx.fillRect(150, -300, 525, 325); //entrance typically + } + + ctx.fillStyle = "rgba(0,0,0,0.5)" + ctx.fillRect(7175, -1515, 125, 180); + portal1[0].draw(); + portal1[1].draw(); + portal1[2].draw(); + portal1[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + }; + + // four large rounded squares + let a = 900 //side length + let c = 100 //corner offset + // spawn.mapVertex(3400, -1300, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${a - c} ${a - c} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off + // spawn.mapVertex(9200, -1300, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${a - c} ${a - c} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off + // spawn.mapVertex(6300, 900, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${a - c} ${a - c} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off + spawn.mapVertex(400, 900, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${a - c} ${a - c} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off + //lower 1st zone entrance /exit + spawn.mapRect(100, -350, 575, 75); + spawn.mapRect(100, -300, 75, 375); + spawn.mapRect(600, -325, 75, 175); + spawn.mapRect(600, -10, 75, 50); + + + //2nd zone upper hollow square + spawn.mapVertex(5650 - 2900, 900 - 2200, `${-a} ${-a + c} ${-a + c} ${-a} ${-400} ${-a} ${-400} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //1/2 square with edges cut off + spawn.mapVertex(6950 - 2900, 900 - 2200, `${400} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${a - c} ${a - c} ${a} ${400} ${a}`); //1/2 square with edges cut off + // spawn.mapRect(5600 - 2900, 1400 - 2200, 1350, 400); + spawn.mapRect(2950, -1175, 650, 775); + spawn.mapRect(3750, -1175, 100, 775); + spawn.mapRect(3575, -1025, 200, 475); + + + //4th zone far right hollow square near exit + spawn.mapVertex(9200, -2050, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${-600} ${-a} ${-600}`); //square with edges cut off --- hollow top + spawn.mapVertex(9200, -550, `${-a} ${600} ${a} ${600} ${a} ${a - c} ${a - c} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off --- hollow bottom + spawn.mapRect(9800, -2100, 300, 1600); //hollow left wall + spawn.mapVertex(8175, -1425, "-1400 -90 350 -90 400 -40 400 40 350 90 -1400 90"); + spawn.mapVertex(6856, -1425, "300 -90 -350 -90 -400 -40 -400 40 -350 90 300 90"); + //exit housing + spawn.mapRect(8925, -2575, 575, 75); + if (isFlippedHorizontal) { + spawn.mapRect(8925, -2550, 75, 400); + spawn.mapRect(9425, -2550, 75, 125); + spawn.mapRect(9425, -2215, 75, 50); + spawn.bodyRect(9425, -2425, 75, 210); + } else { + spawn.mapRect(9425, -2550, 75, 400); + spawn.mapRect(8925, -2550, 75, 125); + spawn.mapRect(8925, -2215, 75, 50); + } + + + + //lower 3rd zone + spawn.mapVertex(6300, 450, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${0} ${-a} ${0}`); //square with edges cut off --- hollow top + spawn.mapVertex(6300, 1200, "-400 -40 -350 -90 350 -90 400 -40 400 40 350 90 -350 90 -400 40"); + spawn.mapVertex(6450, 1650, `${-a} ${600} ${a + 700} ${600} ${a + 700} ${a - c} ${a - c + 700} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off --- hollow bottom + + //upper 3rd zone + a = 400 //side length + c = 50 //corner offset + // spawn.mapVertex(6300, -800, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${a - c} ${a - c} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off + spawn.mapVertex(6300, -1100, `${-a} ${-a + c} ${-a + c} ${-a} ${a - c} ${-a} ${a} ${-a + c} ${a} ${-200} ${-a} ${-200}`); //square with edges cut off + spawn.mapVertex(6300, -500, `${-a} ${200} ${a} ${200} ${a} ${a - c} ${a - c} ${a} ${-a + c} ${a} ${-a} ${a - c}`); //square with edges cut off + spawn.mapVertex(5800, -1425, "-300 -40 -250 -90 250 -90 300 -40 300 40 250 90 -250 90 -300 40"); + spawn.mapVertex(5485, -1850, "-400 -40 -350 -90 350 -90 400 -40 400 40 350 90 -350 90 -400 40"); + spawn.mapVertex(7115, -1850, "-400 -40 -350 -90 350 -90 400 -40 400 40 350 90 -350 90 -400 40"); //long + spawn.mapVertex(6300, -2175, "-300 -40 -250 -90 250 -90 300 -40 300 40 250 90 -250 90 -300 40"); //highest + spawn.mapVertex(4450, -1850, "-200 -40 -150 -90 150 -90 200 -40 200 40 150 90 -150 90 -200 40"); + // spawn.mapVertex(5300, -300, "-300 -60 -270 -90 270 -90 300 -60 300 60 270 90 -270 90 -300 60"); + spawn.mapVertex(5300, -300, "-300 -40 -250 -90 250 -90 300 -40 300 40 250 90 -250 90 -300 40"); + spawn.mapVertex(4500, -590, "-300 -90 250 -90 300 -40 300 40 250 90 -300 90"); + // spawn.mapVertex(4600, -590, "-500 -90 170 -90 200 -60 200 60 170 90 -500 90"); + + //no debris on this level, so spawn some heals and ammo + powerUps.chooseRandomPowerUp(6275, 1425); + powerUps.chooseRandomPowerUp(6300, -650); + powerUps.chooseRandomPowerUp(9550, -750); + + //random blocks + spawn.bodyRect(7725, -2200, 150, 250, 0.2); + spawn.bodyRect(4625, -825, 75, 125, 0.2); + spawn.bodyRect(3250, -1200, 25, 25, 0.2); + spawn.bodyRect(3375, -1275, 25, 75, 0.2); + spawn.bodyRect(3450, -1200, 50, 25, 0.2); + spawn.bodyRect(2825, -2225, 25, 25, 0.2); + spawn.bodyRect(4075, -2225, 50, 25, 0.2); + spawn.bodyRect(8850, -800, 75, 100, 0.2); + spawn.bodyRect(6900, -100, 75, 100, 0.2); + spawn.bodyRect(8975, -1575, 50, 50, 0.2); + spawn.bodyRect(5725, -1700, 125, 175, 0.2); + spawn.bodyRect(6850, -1725, 150, 200, 0.2); + spawn.bodyRect(500, -400, 100, 50, 0.3); + spawn.bodyRect(6025, 1050, 100, 50, 0.2); + spawn.bodyRect(6000, -800, 75, 200, 0.2); + spawn.bodyRect(6775, -75, 125, 75, 0.5); + spawn.bodyRect(7200, 1300, 50, 200, 0.5); + + + //mobs + spawn.randomMob(5700, -75, 0); + spawn.randomMob(6200, -100, 0); + spawn.randomMob(6900, -100, 0.1); + spawn.randomMob(5550, -500, 0.1); + spawn.randomMob(4675, -850, 0.1); + spawn.randomMob(4450, -2050, 0.1); + spawn.randomMob(4050, -2325, 0.1); + spawn.randomMob(3350, -1325, 0.2); + spawn.randomMob(5300, -2050, 0.2); + spawn.randomMob(5675, -2050, 0.2); + spawn.randomMob(5850, -1625, 0.3); + spawn.randomMob(6775, -1600, 0.3); + spawn.randomMob(7700, -1625, 0.4); + spawn.randomMob(7850, -2000, 0.4); + spawn.randomMob(7225, -2000, 0.4); + spawn.randomMob(6350, -2400, 0.5); + spawn.randomMob(8850, -1650, 0.5); + spawn.randomMob(9500, -1300, 0.5); + spawn.randomMob(9250, -900, 0.5); + spawn.randomMob(8600, -875, 0.6); + spawn.randomMob(5575, 1350, 0.6); + spawn.randomMob(6075, 1025, 0.6); + spawn.randomMob(6300, 1025, 0.7); + spawn.randomMob(6525, 1425, 0.8); + spawn.randomMob(7125, 1450, 0.9); + // spawn.randomMob(8600, -2325, 0.7); + // spawn.randomMob(8650, -2825, 0.8); + // spawn.randomMob(9225, -2850, 0.9); + // spawn.randomMob(8525, -2375, 0.9); + spawn.randomGroup(4925, -2850, 1); + if (simulation.difficulty > 1) { + spawn.randomLevelBoss(7275, -2475); + spawn.secondaryBossChance(8400, -1025) + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + + }, + factory() { + level.announceMobTypes() + // simulation.enableConstructMode() //remove this!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + level.setPosToSpawn(2235, -1375); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + level.exit.x = 7875; + level.exit.y = -2480; + + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1500 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d0d2d4"; + // color.map = "#262a2f" + let isPowerLeft = true + const movers = [] + //left side + movers.push(level.mover(125, -140, 925, 35, -5)) + movers.push(level.mover(1100, -437, 1100, 35, -5)) + movers.push(level.mover(2000, -600, 850, 35, -5)) + //right side + const moveSpeedStopGo = 8 + movers.push(level.mover(2700, -200, 3600, 35, 0)) + movers.push(level.mover(7175, -215, 2275, 50, 3)) + movers.push(level.mover(6475, -215, 275, 100, -3)) + movers.push(level.mover(6725, -500, 500, 375, 3)) + movers.push(level.mover(7675, -725, 500, 410, 0)) + movers.push(level.mover(6775, -1075, 375, 50, 0)) + movers.push(level.mover(5525, -1075, 450, 50, 0)) + movers.push(level.mover(6775, -2100, 375, 50, 0)) + movers.push(level.mover(5450, -1900, 525, 50, 0)) + + function setMoverDirection(VxGoal) { + for (let i = 7; i < movers.length; i++) movers[i].VxGoal = VxGoal + } + setMoverDirection(0) + + const buttonRight = level.button(7735, -1825) + buttonRight.isUp = true + const buttonLeft = level.button(5275, -1900) + + const lasers = [] + const laserX = 3390 //3882 - 1130 / 2 + const laserGap = 1295 //1130 + lasers.push(level.hazard(laserX, -500, 6, 300, 0.4)) + lasers.push(level.hazard(laserX + laserGap, -500, 6, 300, 0.4)) + lasers.push(level.hazard(laserX + laserGap * 2, -500, 6, 300, 0.4)) + for (let i = 0; i < lasers.length; i++) { + lasers[i].isOn = false; + spawn.mapRect(lasers[i].min.x - 55, -550, 110, 50); + spawn.mapRect(lasers[i].min.x - 10, -500, 25, 20); + } + const button1 = level.button(2235, -200) + button1.isUp = true + let bonusAmmoCount = 0 + level.custom = () => { + if (isPowerLeft) { + if (!(simulation.cycle % 90)) spawn.bodyRect(2730, -1600, 50, 50); + } else { + // for (let i = 0; i < trains.length; i++) { + // //oscillate back and forth + // if (trains[i].position.x < 5275) { + // trains[i].changeDirection(true) //go right + // } else if (trains[i].position.x > 7875) { + // trains[i].changeDirection(false) //go left + // } + // trains[i].move(); + // } + + const rate = 160 //multiples of 32! + if ((simulation.cycle % rate) === 80) { + for (let i = 0; i < lasers.length; i++) lasers[i].isOn = false; + movers[3].VxGoal = moveSpeedStopGo; + movers[3].force = 0.0005 + movers[2].VxGoal = moveSpeedStopGo; + movers[2].force = 0.0005 + } else if ((simulation.cycle % rate) === 0) { + movers[3].VxGoal = 0; + movers[3].force = 0 + movers[2].VxGoal = 0; + movers[2].force = 0 + spawn.bodyRect(2730, -1600, 50, 50); + if ((simulation.cycle % (rate * 3)) === 0) { + if (bonusAmmoCount < 3 && Math.random() < 0.5) { //some extra ammo because of all the extra mobs that don't drop ammo + bonusAmmoCount++ + powerUps.spawn(2760, -1550, Math.random() < 0.5 ? "heal" : "ammo", false); + } + + for (let i = 0; i < lasers.length; i++) lasers[i].isOn = true; + const block2Mob = (laserIndex) => { //convert block into mob + const laserHit = Matter.Query.ray(body, lasers[laserIndex].min, lasers[laserIndex].max) //check for collisions with 3rd laser + if (laserHit.length) { + for (let i = 0; i < body.length; i++) { + if (laserHit[0].body.id === body[i].id) { //need to find the block id so it can be removed + const list = ["flutter", "flutter", "flutter", "hopper", "slasher", "slasher", "slasher", "stabber", "springer", "striker", "sneaker", "launcher", "launcherOne", "exploder", "sucker", "spinner", "grower", "beamer", "spawner", "ghoster"] + const pick = list[Math.floor(Math.random() * list.length)] + spawn[pick](lasers[laserIndex].max.x, lasers[laserIndex].max.y - 20); + const who = mob[mob.length - 1] + Matter.Body.setVelocity(who, { x: (8 + 5 * Math.random()), y: -(14 + 10 * Math.random()) }); + who.locatePlayer() + who.leaveBody = false; + who.isDropPowerUp = false + //remove block + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + break + } + } + } + } + if (mob.length < 100 && !m.isTimeDilated) { + block2Mob(0) + block2Mob(1) + block2Mob(2) + } + } + } + } + if (buttonLeft.isUp) { + buttonLeft.query(); + if (!buttonLeft.isUp) { + setMoverDirection(7) + buttonRight.isUp = true //flip the other button up + + //remove any blocks on top of right button + const badBlocks = Matter.Query.region(body, buttonRight) + //figure out block's index + for (let j = 0; j < badBlocks.length; j++) { + let index = null + for (let i = 0; i < body.length; i++) { + if (badBlocks[j] === body[i]) index = i + } + //remove block + // console.log(index, j) + if (index) { + Matter.Composite.remove(engine.world, badBlocks[j]); + body.splice(index, 1); + } + } + + } + } else if (buttonRight.isUp) { + buttonRight.query(); + if (!buttonRight.isUp) { + setMoverDirection(-7) + //check for blocks and remove them + const list = Matter.Query.region(body, buttonLeft) //are any blocks colliding with this + buttonLeft.isUp = true //flip the other button up + if (list.length > 0) { + list[0].isRemoveMeNow = true + for (let i = 1; i < body.length; i++) { //find which index in body array it is and remove from array + if (body[i].isRemoveMeNow) { + Matter.Composite.remove(engine.world, list[0]); + body.splice(i, 1); + break + } + } + } + } + } + + if (button1.isUp) { //opens up secondary zone + button1.query(); + if (!button1.isUp) { + isPowerLeft = false + for (let i = 0; i < 3; i++) { + movers[i].VxGoal = 0; + movers[i].force = movers[i].VxGoal > 0 ? 0.0005 : -0.0005 + } + powerUps.spawnStartingPowerUps(2760, -1550); + spawn.randomMob(2700, -350, 0.2); + spawn.randomMob(6975, -650, 0.2); + spawn.randomMob(6550, -325, 0.3); + spawn.randomMob(7350, -350, 0.3); + spawn.randomMob(7925, -975, 0.5); + spawn.randomMob(7950, -1725, 0.5); + spawn.randomMob(7000, -1375, 0.3); + spawn.randomMob(5700, -1350, 0.5); + spawn.randomMob(5250, -1575, 0.5); + spawn.randomMob(6325, -75, 0.3); + spawn.randomMob(7900, -1925, 0.1); + spawn.randomMob(5300, -1975, 0.3); + spawn.randomMob(7875, -1900, 0.3); + spawn.randomMob(5325, -1975, 0.4); + + spawn.randomGroup(3900, -725, 0.4); + if (simulation.difficulty > 1) spawn.randomLevelBoss(6501, -1771); + spawn.secondaryBossChance(6063, -661) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + } + } + buttonRight.draw(); + buttonLeft.draw(); + button1.draw(); + for (let i = 0; i < movers.length; i++) movers[i].push(); + level.exit.drawAndCheck(); + level.enter.draw(); + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(6937, -2075, 50, 1775); //6937, -1050, 50, 675); + ctx.fillStyle = "rgba(0,255,255,0.15)" // ctx.fillStyle = "#f2f2f2" + ctx.fillRect(7675, -2875, 500, 425); //exit room + }; + level.customTopLayer = () => { + if (isPowerLeft) { + ctx.fillStyle = "rgba(0,0,0,0.2)" + ctx.fillRect(2400, -1650, 7050, 2750) //right side + ctx.fillRect(4950, -3075, 3225, 1425); + ctx.beginPath() + ctx.moveTo(2407, -576); + ctx.lineTo(2000, -573) + ctx.lineTo(1950, -439) + ctx.lineTo(1100, -432) + ctx.lineTo(1020, -143) + ctx.lineTo(125, -137) + ctx.lineTo(-109, 300) + ctx.lineTo(-125, 1089) + ctx.lineTo(2372, 1081) + ctx.lineTo(2452, 65) + ctx.fill(); + } else { + // for (let i = 0; i < trains.length; i++) trains[i].draw() + ctx.beginPath() + ctx.moveTo(2526, -589); + ctx.lineTo(2531, -597) + ctx.lineTo(2506, -594) + ctx.lineTo(2850, -600) + ctx.lineTo(2890, -193) + ctx.lineTo(6300, -200) + ctx.lineTo(6618, 857) + ctx.lineTo(6622, 1100) + ctx.lineTo(2521, 1100) + ctx.fillStyle = "rgba(0,0,0,0.2)" + ctx.fill(); + ctx.fillRect(-100, -1650, 2625, 2750) //left side + for (let i = 0; i < lasers.length; i++) lasers[i].opticalQuery() + } + ctx.fillStyle = "rgba(0,0,0,0.07)" + ctx.fillRect(7675, -2200, 1775, 2025); + ctx.fillRect(4950, -2075, 500, 1000); + ctx.fillRect(2050, -1650, 350, 325) //entrance room + for (let i = 0; i < movers.length; i++) movers[i].draw(); + }; + spawn.mapRect(-1550, -3050, 1450, 4150); //left wall + spawn.mapRect(-1550, -3050, 6525, 1400); //ceiling + spawn.mapRect(-1550, -3050, 6525, 1400); + spawn.mapRect(3000, -1700, 1975, 675); //ceiling center + + spawn.mapRect(3800, -4000, 5650, 950); + spawn.mapRect(3800, -4000, 1175, 2975); + spawn.mapRect(8175, -4000, 1275, 3685); //right wall + spawn.mapRect(8175, -200, 1275, 1300); //right wall + + spawn.mapRect(75, 0, 6275, 1100); //ground + spawn.mapRect(6475, -200, 2750, 1300); + spawn.mapRect(4975, -1087, 550, 62); + spawn.mapRect(4975, -1100, 500, 75); + + spawn.mapRect(7875, -1100, 175, 25); //right 3 hop stairs + spawn.mapRect(8075, -1450, 200, 25); + spawn.mapRect(7675, -1825, 375, 25); + spawn.mapRect(7675, -1800, 250, 725); + + spawn.mapRect(5125, -1275, 200, 25); //left 3 hop stairs + spawn.mapRect(4900, -1575, 175, 25); + spawn.mapRect(5125, -1900, 325, 25); + spawn.mapRect(5225, -1875, 225, 625); + spawn.mapRect(4950, -3075, 500, 1000); + + //exit + spawn.mapRect(7675, -2450, 525, 250); + spawn.mapRect(7675, -3050, 550, 175); + spawn.mapRect(7675, -2925, 50, 175); + + spawn.mapRect(1925, -1325, 550, 50); //entrance + spawn.mapRect(2050, -1675, 50, 175); //entrance + spawn.mapRect(1700, -200, 750, 275); //button shelf + if (Math.random() < 0.5) { //left side + spawn.mapRect(625, -1100, 425, 300); + spawn.mapRect(1375, -1100, 425, 300); + spawn.mapRect(1750, -835, 100, 35); + spawn.mapRect(-200, -525, 150, 35); + } else { + spawn.mapRect(800, -1125, 925, 400); + spawn.mapRect(75, -775, 400, 50); + spawn.mapRect(1700, -760, 75, 35); + spawn.mapRect(-200, -425, 150, 35); + } + spawn.mapRect(2400, -600, 125, 675); + spawn.mapRect(2400, -1750, 125, 1050); + spawn.mapRect(2700, -1700, 125, 85); + + spawn.randomMob(350, -325, 0.5); + spawn.randomMob(875, -375, 0.5); + spawn.randomMob(1250, -575, 0.5); + spawn.randomMob(1550, -600, 0.5); + spawn.randomSmallMob(1250, -175); + spawn.randomSmallMob(1500, -229); + spawn.randomSmallMob(1850, -300); + powerUps.spawn(5200, -1300, "ammo"); + }, + labs() { + level.announceMobTypes() + level.isProcedural = true //used in generating text for the level builder + level.defaultZoom = 1700 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d9d9de" //"#d3d3db" //"#dcdcdf"; + let isDoorLeft, isDoorRight, x, y + doCustom = [] + doCustomTopLayer = [] + offset = { x: 0, y: 0 } + const mobSpawnChance = 0 // Math.random() < chance + 0.07 * simulation.difficulty + enterOptions = [ + (x = offset.x, y = offset.y) => { //lasers + level.setPosToSpawn(x + 1750, y - 800); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + spawn.mapRect(x + 1450, y - 1350, 50, 450); //entrance left wall + spawn.bodyRect(x + 1460, y - 900, 30, 150); //entrance door + spawn.mapRect(x + 1600, y - 350, 500, 100); //toggle shelf + const toggle = level.toggle(x + 1650, y - 350, true) //(x,y,isOn,isLockOn = true/false) + let hazard1 + if (Math.random() > 0.5) { + spawn.mapRect(x + 550, y - 750, 1500, 50); //entrance shelf + // hazard1 = level.hazard(x + 850, y - 920, 600, 10, 0.4) //laser + hazard1 = level.laser({ x: x + 870, y: y - 915 }, { x: x + 1450, y: y - 915 }) + spawn.mapRect(x + 860, y - 925, 10, 20); //laser nose + spawn.mapRect(x + 660, y - 975, 200, 120); //laser body + } else { + spawn.mapRect(x + 1350, y - 750, 700, 50); //entrance shelf + // hazard1 = level.hazard(x + 1040, y - 660, 1000, 10, 0.4) //laser + hazard1 = level.laser({ x: x + 1060, y: y - 655 }, { x: x + 2000, y: y - 655 }) + spawn.mapRect(x + 1050, y - 665, 10, 20); //laser nose + spawn.mapRect(x + 650, y - 705, 400, 100); //laser body + } + // const hazard2 = level.hazard(x, y - 330, 450, 10, 0.4) //laser + const hazard2 = level.laser({ x: x + 5, y: y - 325 }, { x: x + 455, y: y - 325 }) + spawn.mapRect(x + 440, y - 335, 10, 20); //laser nose + spawn.mapRect(x + 450, y - 375, 400, 100); //laser body + const Xoffset = Math.floor(400 * Math.random()) + //level.hazard(x + Xoffset, y - 1300, 10, 1300, 0.4) //laser + const hazard3 = level.laser({ x: x + Xoffset + 5, y: y - 1290 }, { x: x + Xoffset + 5, y: y }) + spawn.mapRect(x + Xoffset - 5, y - 1310, 20, 20); //laser nose + const Xoffset2 = 1650 + Math.floor(300 * Math.random()) + // const hazard4 = level.hazard(x + Xoffset2, y - 240, 10, 250, 0.4) //laser + hazard4 = level.laser({ x: x + Xoffset2 + 5, y: y - 230 }, { x: x + Xoffset2 + 5, y: y - 230 + 250 }) + + spawn.mapRect(x + Xoffset2 - 5, y - 250, 20, 20); //laser nose + spawn.randomMob(x + 150, y + -1100, mobSpawnChance); + spawn.randomMob(x + 175, y + -775, mobSpawnChance); + spawn.randomMob(x + 150, y + -350, mobSpawnChance); + spawn.randomMob(x + 150, y + -75, mobSpawnChance); + spawn.randomMob(x + 650, y + -125, mobSpawnChance); + spawn.randomMob(x + 1200, y + -75, mobSpawnChance); + // let isSpawnedMobs = false + doCustomTopLayer.push( + () => { + toggle.query(); + if (toggle.isOn) { + if ((simulation.cycle % 120) > 60) { + hazard1.query(); + hazard2.query(); + } else { + hazard3.query(); + hazard4.query() + } + } + } + ) + }, + ] + exitOptions = [ + (x = offset.x, y = offset.y) => { + level.exit.x = x + 1725; + level.exit.y = y - 980; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + spawn.mapRect(x + 1500, y - 950, 500, 25); //exit platform + spawn.mapRect(x + 1550, y - 1300, 25, 175); //exit side wall + spawn.mapVertex(x + 1300, y - 125, "-400 0 -250 -400 250 -400 400 0"); + + spawn.bodyRect(x + 1075, y - 475, 125, 125, 0.25); + spawn.bodyRect(x + 500, y - 100, 125, 100, 0.25); + spawn.bodyRect(x + 200, y - 150, 100, 150, 0.25); + spawn.bodyRect(x + 1075, y - 1075, 100, 125, 0.25); + const density = 0.0015 + const angle = Math.PI / 2 + const variance = 0 //Math.PI + const frictionAir = 0.03 + const angularVelocity = 0 //0.01 + const spinVariance = 0 //0.02 + balance1 = level.spinner(x + 200, y - 500, 30, 400, density, angle + variance * (Math.random() - 0.5), frictionAir, angularVelocity + spinVariance * (Math.random() - 0.5)) // spinner(x, y, width, height, density = 0.001, angle=0,frictionAir=0.001,angularVelocity=0) { + balance2 = level.spinner(x + 200, y - 950, 30, 400, density, angle + variance * (Math.random() - 0.5), frictionAir, angularVelocity + spinVariance * (Math.random() - 0.5)) + balance3 = level.spinner(x + 650, y - 750, 30, 400, density, angle + variance * (Math.random() - 0.5), frictionAir, angularVelocity + spinVariance * (Math.random() - 0.5)) + balance4 = level.spinner(x + 1250, y - 1000, 30, 400, density, angle + variance * (Math.random() - 0.5), frictionAir, angularVelocity + spinVariance * (Math.random() - 0.5)) + + let isInRoom = false + doCustom.push( + () => { + if (!isInRoom && m.pos.x > x - 100 && m.pos.x < x + 2700 && m.pos.y > y - 1300 && m.pos.y < y) { //check if player is in this room and run code once + isInRoom = true + spawn.randomMob(x + 1175, y - 725, mobSpawnChance); + spawn.randomMob(x + 1450, y - 725, mobSpawnChance); + spawn.randomMob(x + 425, y - 100, mobSpawnChance); + spawn.randomMob(x + 1700, y - 300, mobSpawnChance); + spawn.randomMob(x + 1300, y - 375, mobSpawnChance); + } + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(x + 1550, y - 1300, 450, 350) + } + ) + doCustomTopLayer.push( + () => { + ctx.fillStyle = "#233" + ctx.beginPath(); + ctx.arc(balance1.pointA.x, balance1.pointA.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance2.pointA.x, balance2.pointA.y) + ctx.arc(balance2.pointA.x, balance2.pointA.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance3.pointA.x, balance3.pointA.y) + ctx.arc(balance3.pointA.x, balance3.pointA.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance4.pointA.x, balance4.pointA.y) + ctx.arc(balance4.pointA.x, balance4.pointA.y, 9, 0, 2 * Math.PI); + ctx.fill(); + } + ) + }, + (x = offset.x, y = offset.y) => { + level.exit.x = x + 1750; + level.exit.y = y - 980; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + spawn.mapRect(x + 1550, y - 950, 500, 25); //exit platform + spawn.mapRect(x + 1600, y - 1300, 25, 175); //exit side wall + spawn.bodyRect(x + 1275, y - 475, 125, 125, 0.25); + spawn.bodyRect(x + 500, y - 100, 125, 100, 0.25); + spawn.bodyRect(x + 800, y - 150, 100, 150, 0.25); + spawn.bodyRect(x + 875, y + -50, 50, 50); + spawn.bodyRect(x + 1025, y + -50, 50, 50); + + if (Math.random() > 0.5) { + const density = 0.0012 + const angle = Math.PI / 2 + const variance = 0.2 //Math.PI + const frictionAir = 0.015 + const height = 35 + balance1 = level.spinner(x + 1300, y - 425, height, 410, density, angle + variance * (Math.random() - 0.5), frictionAir) // spinner(x, y, width, height, density = 0.001, angle=0,frictionAir=0.001,angularVelocity=0) { + balance3 = level.spinner(x + 750, y - 650, height, 410, density, angle + variance * (Math.random() - 0.5), frictionAir) + balance2 = level.spinner(x + 300, y - 425, height, 410, density, angle + variance * (Math.random() - 0.5), frictionAir) + balance4 = level.spinner(x + 1250, y - 950, 50, 550, density, angle, 0.1) + const rotatingBlock = body[body.length - 1] + doCustom.push( + () => { + if (!isInRoom && m.pos.x > x - 100 && m.pos.x < x + 2700 && m.pos.y > y - 1300 && m.pos.y < y) { //check if player is in this room and run code once + isInRoom = true + spawn.randomMob(x + 1175, y - 725, mobSpawnChance); + spawn.randomMob(x + 1450, y - 725, mobSpawnChance); + spawn.randomMob(x + 425, y - 100, mobSpawnChance); + spawn.randomMob(x + 1200, y - 125, mobSpawnChance); + spawn.randomMob(x + 1300, y - 375, mobSpawnChance); + } + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(x + 1600, y - 1300, 400, 350) + rotatingBlock.torque += rotatingBlock.inertia * 0.000005 + } + ) + } else { + const density = 0.001 + const angle = Math.PI / 2 + const variance = Math.PI + const frictionAir = 0.015 + const width = 200 + const height = 200 + const spinVariance = 0.05 + balance1 = level.spinner(x + 175, y - 300, height, width, density, angle + variance * (Math.random() - 0.5), frictionAir, spinVariance * (Math.random() - 0.5)) // spinner(x, y, width, height, density = 0.001, angle=0,frictionAir=0.001,angularVelocity=0) { + balance2 = level.spinner(x + 500, y - 525, height, width, density, angle + variance * (Math.random() - 0.5), frictionAir, spinVariance * (Math.random() - 0.5)) + balance3 = level.spinner(x + 850, y - 700, height, width, density, angle + variance * (Math.random() - 0.5), frictionAir, spinVariance * (Math.random() - 0.5)) + balance4 = level.spinner(x + 1250, y - 850, height, width, density, angle + variance * (Math.random() - 0.5), frictionAir, spinVariance * (Math.random() - 0.5)) + doCustom.push( + () => { + if (!isInRoom && m.pos.x > x - 100 && m.pos.x < x + 2700 && m.pos.y > y - 1300 && m.pos.y < y) { //check if player is in this room and run code once + isInRoom = true + spawn.randomMob(x + 1175, y - 725, mobSpawnChance); + spawn.randomMob(x + 1450, y - 725, mobSpawnChance); + spawn.randomMob(x + 425, y - 100, mobSpawnChance); + spawn.randomMob(x + 1200, y - 125, mobSpawnChance); + spawn.randomMob(x + 1300, y - 375, mobSpawnChance); + } + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(x + 1600, y - 1300, 400, 350) + } + ) + } + let isInRoom = false + doCustomTopLayer.push( + () => { + ctx.fillStyle = "#233" + ctx.beginPath(); + ctx.arc(balance1.pointA.x, balance1.pointA.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance2.pointA.x, balance2.pointA.y) + ctx.arc(balance2.pointA.x, balance2.pointA.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance3.pointA.x, balance3.pointA.y) + ctx.arc(balance3.pointA.x, balance3.pointA.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance4.pointA.x, balance4.pointA.y) + ctx.arc(balance4.pointA.x, balance4.pointA.y, 9, 0, 2 * Math.PI); + ctx.fill(); + } + ) + } + ] + emptyOptions = [ //nothing good here except the starting power up, and duplicated bosses + (x = offset.x, y = offset.y) => { //pulse + if (!isDoorLeft && isDoorRight) { //flipped, entering from the right + powerUps.spawnStartingPowerUps(x + 2000 - 1650, y + -400); + spawn.mapRect(x + 2000 - 1575 - 25, y + -625, 25, 375); //wall on top of wall + spawn.mapRect(x + 2000 - 1575 - 25, y + -1325, 25, 525); //wall on top of wall + spawn.mapRect(x + 2000 - 1525 - 250, y + -350, 250, 450); //wall + spawn.mapRect(x + 2000 - 245 - 300, y + -200, 300, 100); //gun + spawn.mapRect(x + 2000 - 530 - 25, y + -190, 25, 80); //gun nose + const button = level.button(x + 2000 - 290 - 140, y - 200) + button.isReadyToFire = true + doCustom.push( + () => { + ctx.fillStyle = "rgba(0,0,0,0.05)"; //"rgba(0,0,0,0.1)"; + ctx.fillRect(x + 2000 - 255 - 280, y + -100, 280, 100); + button.query(); + button.draw(); + if (!button.isReadyToFire && button.isUp) { + button.isReadyToFire = true + } else if (button.isReadyToFire && !button.isUp) { + button.isReadyToFire = false + b.pulse(90, Math.PI, { + x: x + 2000 - 560, + y: y - 150 + }) + } + } + ) + spawn.randomMob(x + 2000 - 1600, y + -425, mobSpawnChance); + spawn.randomMob(x + 2000 - 1725, y + -1250, mobSpawnChance); + spawn.randomMob(x + 2000 - 1250, y + -1200, mobSpawnChance); + spawn.randomMob(x + 2000 - 300, y + -1200, mobSpawnChance); + spawn.randomMob(x + 2000 - 800, y + -125, mobSpawnChance); + let pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x + 2000 - 1275, y + -150, 90 + Math.random() * 40); //one extra large mob + } else { + powerUps.spawnStartingPowerUps(x + 1650, y + -400); + spawn.mapRect(x + 1575, y + -625, 25, 375); //wall on top of wall + spawn.mapRect(x + 1575, y + -1325, 25, 525); //wall on top of wall + spawn.mapRect(x + 1525, y + -350, 250, 450); //wall + spawn.mapRect(x + 245, y + -200, 300, 100); //gun + spawn.mapRect(x + 530, y + -190, 25, 80); //gun nose + const button = level.button(x + 290, y - 200) + button.isReadyToFire = true + + doCustom.push( + () => { + ctx.fillStyle = "rgba(0,0,0,0.05)"; //"rgba(0,0,0,0.1)"; + ctx.fillRect(x + 255, y + -100, 280, 100); + button.query(); + button.draw(); + if (!button.isReadyToFire && button.isUp) { + button.isReadyToFire = true + } else if (button.isReadyToFire && !button.isUp) { + button.isReadyToFire = false + b.pulse(90, 0, { x: x + 560, y: y - 150 }) + } + } + ) + spawn.randomMob(x + 1600, y + -425, mobSpawnChance); + spawn.randomMob(x + 1725, y + -1250, mobSpawnChance); + spawn.randomMob(x + 1250, y + -1200, mobSpawnChance); + spawn.randomMob(x + 300, y + -1200, mobSpawnChance); + spawn.randomMob(x + 800, y + -125, mobSpawnChance); + let pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x + 1275, y + -150, 90 + Math.random() * 40); //one extra large mob + } + }, + (x = offset.x, y = offset.y) => { //spawn block and fire it + if (!isDoorLeft && isDoorRight) { + powerUps.spawnStartingPowerUps(x + 1650, y + -400); + spawn.mapRect(x + 2000 - 1575 - 25, y + -625, 25, 375); //wall on top of wall + spawn.mapRect(x + 2000 - 1575 - 25, y + -1325, 25, 525); //wall on top of wall + spawn.mapRect(x + 2000 - 1525 - 250, y + -350, 250, 450); //wall + spawn.mapRect(x + 2000 - 245 - 300, y + -200, 300, 100); //gun + spawn.mapRect(x + 2000 - 530 - 25, y + -190, 25, 80); + const button = level.button(x + 2000 - 290 - 140, y - 200) + button.isReadyToFire = true + doCustom.push( + () => { + ctx.fillStyle = "rgba(0,0,0,0.05)"; //"rgba(0,0,0,0.1)"; + ctx.fillRect(x + 2000 - 255 - 280, y + -100, 280, 100); + button.query(); + button.draw(); + if (!button.isReadyToFire && button.isUp) { + button.isReadyToFire = true + } else if (button.isReadyToFire && !button.isUp) { + button.isReadyToFire = false + fireBlock = function (xPos, yPos) { + const index = body.length + spawn.bodyRect(xPos, yPos, 35 + 50 * Math.random(), 35 + 50 * Math.random()); + const bodyBullet = body[body.length - 1] + Matter.Body.setVelocity(body[index], { x: -120, y: -5 }); + body[index].isAboutToBeRemoved = true; + setTimeout(() => { //remove block + for (let i = 0; i < body.length; i++) { + if (body[i] === bodyBullet) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + } + } + }, 1000); + } + fireBlock(x + 2000 - 90 - 560 + 30 * Math.random(), y - 140); + fireBlock(x + 2000 - 90 - 560 + 30 * Math.random(), y - 160); + fireBlock(x + 2000 - 90 - 560 + 30 * Math.random(), y - 180); + fireBlock(x + 2000 - 90 - 560 + 30 * Math.random(), y - 200); + fireBlock(x + 2000 - 90 - 560 + 30 * Math.random(), y - 220); + fireBlock(x + 2000 - 90 - 560 + 30 * Math.random(), y - 240); + } + } + ) + spawn.randomMob(x + 2000 - 1600, y + -425, mobSpawnChance); + spawn.randomMob(x + 2000 - 1725, y + -1250, mobSpawnChance); + spawn.randomMob(x + 2000 - 1250, y + -1200, mobSpawnChance); + spawn.randomMob(x + 2000 - 300, y + -1200, mobSpawnChance); + spawn.randomMob(x + 2000 - 800, y + -125, mobSpawnChance); + let pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x + 2000 - 1275, y + -150, 90 + Math.random() * 40); //one extra large mob + } else { + powerUps.spawnStartingPowerUps(x + 1650, y + -400); + spawn.mapRect(x + 1575, y + -625, 25, 375); //wall on top of wall + spawn.mapRect(x + 1575, y + -1325, 25, 525); //wall on top of wall + spawn.mapRect(x + 1525, y + -350, 250, 450); //wall + spawn.mapRect(x + 245, y + -200, 300, 100); //gun + spawn.mapRect(x + 530, y + -190, 25, 80); + const button = level.button(x + 290, y - 200) + button.isReadyToFire = true + doCustom.push( + () => { + ctx.fillStyle = "rgba(0,0,0,0.05)"; //"rgba(0,0,0,0.1)"; + ctx.fillRect(x + 255, y + -100, 280, 100); + button.query(); + button.draw(); + if (!button.isReadyToFire && button.isUp) { + button.isReadyToFire = true + } else if (button.isReadyToFire && !button.isUp) { + button.isReadyToFire = false + fireBlock = function (xPos, yPos) { + const index = body.length + spawn.bodyRect(xPos, yPos, 35 + 50 * Math.random(), 35 + 50 * Math.random()); + const bodyBullet = body[body.length - 1] + Matter.Body.setVelocity(body[index], { x: 120, y: -5 }); + body[index].isAboutToBeRemoved = true; + + setTimeout(() => { //remove block + for (let i = 0; i < body.length; i++) { + if (body[i] === bodyBullet) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + } + } + }, 1000); + } + fireBlock(x + 560 + 30 * Math.random(), y - 140); + fireBlock(x + 560 + 30 * Math.random(), y - 160); + fireBlock(x + 560 + 30 * Math.random(), y - 180); + fireBlock(x + 560 + 30 * Math.random(), y - 200); + fireBlock(x + 560 + 30 * Math.random(), y - 220); + fireBlock(x + 560 + 30 * Math.random(), y - 240); + } + } + ) + spawn.randomMob(x + 1600, y + -425, mobSpawnChance); + spawn.randomMob(x + 1725, y + -1250, mobSpawnChance); + spawn.randomMob(x + 1250, y + -1200, mobSpawnChance); + spawn.randomMob(x + 300, y + -1200, mobSpawnChance); + spawn.randomMob(x + 800, y + -125, mobSpawnChance); + let pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x + 1275, y + -150, 90 + Math.random() * 40); //one extra large mob + } + }, + (x = offset.x, y = offset.y) => { //fire an "ammo clip" of blocks + if (!isDoorLeft && isDoorRight) { //flipped, entering from the right + powerUps.spawnStartingPowerUps(x + 2000 - 1650, y + -400); + spawn.mapRect(x + 2000 - 1575 - 25, y + -625, 25, 375); //wall on top of wall + spawn.mapRect(x + 2000 - 1575 - 25, y + -1325, 25, 525); //wall on top of wall + spawn.mapRect(x + 2000 - 1525 - 250, y + -350, 250, 450); //wall + spawn.mapRect(x + 2000 - 175 - 370, y + -200, 370, 100); //gun + spawn.mapRect(x + 2000 - 530 - 25, y + -190, 25, 80); + spawn.mapRect(x + 2000 - 545 - 10, y + -770, 10, 325); //block loader for gun //walls + spawn.mapRect(x + 2000 - 620 - 10, y + -770, 10, 325); //walls + spawn.mapRect(x + 2000 + 50 - 150, y + -425, 150, 50); + spawn.mapRect(x + 2000 - 175 - 370, y + -650, 370, 50); + spawn.mapRect(x + 2000 - 540 - 95, y + -460, 95, 15); //bottom that opens and closes + const bulletDoor = map[map.length - 1] //keep track of this body so it can be make non-collide later + for (let i = 0; i < 6; i++) spawn.bodyRect(x + 2000 - 60 - 555 + Math.floor(Math.random() * 10), y + -520 - 50 * i, 50, 50); //bullets for gun + spawn.bodyRect(x + 2000 - 250 - 40, y + -700, 40, 50); //extra bullets + spawn.bodyRect(x + 2000 - 350 - 30, y + -700, 30, 35); + spawn.bodyRect(x + 2000 - 425 - 40, y + -700, 40, 70); + const button = level.button(x + 2000 - 280 - 140, y - 200) //trigger for gun + button.isReadyToFire = true + doCustom.push( + () => { + ctx.fillStyle = "rgba(0,0,0,0.05)"; //"rgba(0,0,0,0.1)"; + ctx.fillRect(x + 2000 - 200 - 325, y + -625, 325, 650); + button.query(); + button.draw(); + if (!button.isReadyToFire && button.isUp) { + button.isReadyToFire = true + bulletDoor.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + } else if (button.isReadyToFire && !button.isUp) { + button.isReadyToFire = false + bulletDoor.collisionFilter.mask = 0 //cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + } else if (!button.isUp) { + const bounds = { + min: { + x: x + 2000 - 580, + y: y - 125 + }, + max: { + x: x + 2000 - 530, + y: y - 110 + } + } + const list = Matter.Query.region(body, bounds) + for (let i = 0, len = list.length; i < len; i++) { + Matter.Body.setVelocity(list[i], { + x: -120, + y: -5 + }); + } + if (Matter.Query.region([player], bounds).length) { + Matter.Body.setVelocity(player, { + x: -100, + y: -5 + }); + } + ctx.fillStyle = `rgba(255,0,255,${0.2 + 0.7 * Math.random()})` + ctx.fillRect(bounds.min.x, y - 185, 38, 70); + } + } + ) + spawn.randomMob(x + 2000 - 1600, y + -425, mobSpawnChance); + spawn.randomMob(x + 2000 - 1725, y + -1250, mobSpawnChance); + spawn.randomMob(x + 2000 - 1250, y + -1200, mobSpawnChance); + spawn.randomMob(x + 2000 - 300, y + -1200, mobSpawnChance); + spawn.randomMob(x + 2000 - 800, y + -125, mobSpawnChance); + let pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x + 2000 - 1275, y + -150, 90 + Math.random() * 40); //one extra large mob + } else { + powerUps.spawnStartingPowerUps(x + 1650, y + -400); + spawn.mapRect(x + 1575, y + -625, 25, 375); //wall on top of wall + spawn.mapRect(x + 1575, y + -1325, 25, 525); //wall on top of wall + spawn.mapRect(x + 1525, y + -350, 250, 450); //wall + spawn.mapRect(x + 175, y + -200, 370, 100); //gun + spawn.mapRect(x + 530, y + -190, 25, 80); + spawn.mapRect(x + 545, y + -770, 10, 325); //block loader for gun //walls + spawn.mapRect(x + 620, y + -770, 10, 325); //walls + spawn.mapRect(x - 50, y + -425, 150, 50); + spawn.mapRect(x + 175, y + -650, 370, 50); + spawn.mapRect(x + 540, y + -460, 95, 15); //bottom that opens and closes + const bulletDoor = map[map.length - 1] //keep track of this body so it can be make non-collide later + for (let i = 0; i < 6; i++) spawn.bodyRect(x + 555 + Math.floor(Math.random() * 10), y + -520 - 50 * i, 50, 50); //bullets for gun + spawn.bodyRect(x + 250, y + -700, 40, 50); //extra bullets + spawn.bodyRect(x + 350, y + -700, 30, 35); + spawn.bodyRect(x + 425, y + -700, 40, 70); + const button = level.button(x + 280, y - 200) //trigger for gun + button.isReadyToFire = true + doCustom.push( + () => { + ctx.fillStyle = "rgba(0,0,0,0.05)"; //"rgba(0,0,0,0.1)"; + ctx.fillRect(x + 200, y + -625, 325, 650); + button.query(); + button.draw(); + if (!button.isReadyToFire && button.isUp) { + button.isReadyToFire = true + bulletDoor.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + } else if (button.isReadyToFire && !button.isUp) { + button.isReadyToFire = false + bulletDoor.collisionFilter.mask = 0 //cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + } else if (!button.isUp) { + const bounds = { + min: { + x: x + 530, + y: y - 125 + }, + max: { + x: x + 580, + y: y - 110 + } + } + const list = Matter.Query.region(body, bounds) + for (let i = 0, len = list.length; i < len; i++) { + Matter.Body.setVelocity(list[i], { + x: 120, + y: -5 + }); + } + if (Matter.Query.region([player], bounds).length) { + Matter.Body.setVelocity(player, { + x: 100, + y: -5 + }); + } + ctx.fillStyle = `rgba(255,0,255,${0.2 + 0.7 * Math.random()})` + ctx.fillRect(bounds.min.x, y - 185, 38, 70); + } + } + ) + spawn.randomMob(x + 1600, y + -425, mobSpawnChance); + spawn.randomMob(x + 1725, y + -1250, mobSpawnChance); + spawn.randomMob(x + 1250, y + -1200, mobSpawnChance); + spawn.randomMob(x + 300, y + -1200, mobSpawnChance); + spawn.randomMob(x + 800, y + -125, mobSpawnChance); + let pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x + 1275, y + -150, 90 + Math.random() * 40); //one extra large mob + } + } + ] + lootOptions = [ //has some power up reward //field, ammo, research, gun + (x = offset.x, y = offset.y) => { + spawn.mapRect(x + 1925, y + -325, 125, 150); //4 wall ledges + spawn.mapRect(x + 1925, y + -865, 125, 150); //4 wall ledges + spawn.mapRect(x + -50, y + -325, 125, 150); //4 wall ledges + spawn.mapRect(x + -50, y + -865, 125, 150); //4 wall ledges + spawn.mapRect(x + 1700, y + -500, 200, 25); + spawn.mapRect(x + 75, y + -500, 200, 25); + + let chamberY = -650 + if (Math.random() > 0.5) { //upper chamber + chamberY = -650 - 640 + spawn.mapRect(x + 550, y + -10 - 640, 900, 25); //raised floor + spawn.mapRect(x + 450, y + -20 - 640, 1100, 25); + spawn.mapRect(x + 450, y + -675 - 640, 1100, 25); //chamber ceiling + powerUps.spawn(x + 998, y - 333 - 640, "tech", false); + spawn.mapVertex(x + 1000, y + -0, "575 0 -575 0 -450 -100 450 -100"); //base + } else { //lower chamber + spawn.mapRect(x + 400, y + -10, 1200, 50); //raised floor + spawn.mapRect(x + 450, y + -20, 1100, 50); + spawn.mapRect(x + 450, y + -675, 1100, 25); //chamber ceiling + spawn.mapRect(x + 550, y + -685, 900, 25); + powerUps.spawn(x + 998, y - 333, "tech", false); + } + const powerUp1 = powerUp[powerUp.length - 1] + if (powerUp1) powerUp1.holdPosition = { x: powerUp1.position.x, y: powerUp1.position.y } + let isSpawnedMobs = false + doCustom.push( + () => { + ctx.fillStyle = "#e4e4e9" //"rgba(255,255,255,1)"; + ctx.fillRect(x + 450, y + chamberY, 1100, 650); //chamber background + // if (!isInRoom && m.pos.x > x - 100 && m.pos.x < x + 2000 && m.pos.y > y - 1300 && m.pos.y < y) { //is player inside this room? + // isInRoom = true + // } else + if (powerUp1 && powerUp1.velocity.y !== 0) { //don't run this code if power up is gone //hack: powerUp1.velocity.y !== 0 seems to only be true if the power up doesn't exist and is no longer being affected by gravity + ctx.strokeStyle = "#f0f" + ctx.lineWidth = 2; + if (Vector.magnitudeSquared(Vector.sub(m.pos, powerUp1.position)) < 90000) { //zone radius is 300 + //damage player and drain energy + if (m.immuneCycle < m.cycle) { + if (m.energy < 0.02) { + //push out + // const force = Vector.mult(Vector.normalise(Vector.sub(player.position, powerUp1.position)), 0.02 * player.mass) + // player.force.x += force.x + // player.force.y += force.y + player.force.x += (player.position.x > powerUp1.position.x) ? 0.02 * player.mass : - 0.02 * player.mass + + } else { + m.energy -= 0.01 + //friction + Matter.Body.setVelocity(player, { + x: player.velocity.x * 0.45, + y: player.velocity.y * 0.98 + }); + } + } + + //draw electricity going towards player + const unit = Vector.normalise(Vector.sub(m.pos, powerUp1.position)) + let xElec = powerUp1.position.x + 40 * unit.x; + let yElec = powerUp1.position.y + 40 * unit.y; + ctx.beginPath(); + ctx.moveTo(xElec, yElec); + const step = 40 + for (let i = 0; i < 6; i++) { + xElec += step * (unit.x + 1.5 * (Math.random() - 0.5)) + yElec += step * (unit.y + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(xElec, yElec); + } + } else { + //draw electricity going in random directions + const angle = Math.random() * 2 * Math.PI + const Dx = Math.cos(angle); + const Dy = Math.sin(angle); + let xElec = powerUp1.position.x + 40 * Dx; + let yElec = powerUp1.position.y + 40 * Dy; + ctx.beginPath(); + ctx.moveTo(xElec, yElec); + const step = 40 + for (let i = 0; i < 6; i++) { + xElec += step * (Dx + 1.5 * (Math.random() - 0.5)) + yElec += step * (Dy + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(xElec, yElec); + } + } + ctx.lineWidth = 2 * Math.random(); + ctx.stroke(); //draw electricity + + ctx.beginPath(); //outline damage zone + ctx.arc(powerUp1.position.x, powerUp1.position.y, 300, 0, 2 * Math.PI); + ctx.stroke(); + //float power up in the air + Matter.Body.setPosition(powerUp1, { + x: powerUp1.holdPosition.x + 4 * Math.random(), //1300 -2 + y: powerUp1.holdPosition.y + 4 * Math.random() //335 -2 + }); + Matter.Body.setVelocity(powerUp1, { x: 0, y: 0 }); + } else if (!isSpawnedMobs) { + isSpawnedMobs = true + if (chamberY === -650) { //lower chamber + spawn.randomMob(x + 250, y + -650, mobSpawnChance); + spawn.randomMob(x + 1825, y + -600, mobSpawnChance); + spawn.randomGroup(x + 275, y + -1050, mobSpawnChance); + spawn.randomGroup(x + 675, y + -975, mobSpawnChance); + spawn.randomGroup(x + 1225, y + -975, Infinity); + } else { //upper chamber + spawn.randomMob(x + 250, y + -650, mobSpawnChance); + spawn.randomMob(x + 1800, y + -625, mobSpawnChance); + spawn.randomGroup(x + 300, y + -300, mobSpawnChance); + spawn.randomGroup(x + 650, y + -275, mobSpawnChance); + spawn.randomGroup(x + 1125, y + -300, Infinity); + } + } + } + ) + } + ] + upDownOptions = [ //extra tall vertical section 3000x3000 //this is where the level boss is + (x = offset.x, y = offset.y) => { //mover + const button = level.button(x + 935, y + 0) + button.isUp = true + doCustomTopLayer.push( + () => { + button.draw(); + if (button.isUp) { + button.query(); + if (!button.isUp) { + const mapStartingLength = map.length //track this so you know how many you added when running addMapToLevelInProgress + addMapToLevelInProgress = (who) => { //adds new map elements to the level while the level is already running //don't forget to run simulation.draw.setPaths() after you all the the elements so they show up visually + who.collisionFilter.category = cat.map; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(who, true); //make static + Composite.add(engine.world, who); //add to world + } + //map elements go here + //box around portals + spawn.mapRect(x + -50, y + -2700, 150, 110); + spawn.mapRect(x + -50, y + -2440, 150, 25); + spawn.mapRect(x + 1900, y + -2715, 150, 550); + spawn.mapRect(x + 1900, y + -2015, 150, 50); + spawn.mapRect(x + 1900, y + -1115, 150, 150); + spawn.mapRect(x + 1900, y + -815, 150, 50); + spawn.mapRect(x + -50, y + -340, 150, 50); + // spawn.mapRect(x + -50, y + -640, 150, 150); + spawn.mapRect(x + 1975, y - 1015, 50, 225); + spawn.mapRect(x + 1975, y - 2190, 50, 200); + spawn.mapRect(x + -25, y - 2615, 50, 200); + spawn.mapRect(x + -25, y - 515, 75, 200); + + //ledge to get to upper left door + // spawn.mapRect(x + -50, y - 1400, 100, 25); + spawn.mapRect(x + -25, y - 1075, 250, 25); + spawn.mapRect(x + -50, y - 1075, 150, 590); + + + const rampSpeed = 8 //+ Math.floor(4 * Math.random()) + const mover4 = level.mover(x, y + -2425, 1000, 50, rampSpeed) + const mover3 = level.mover(x + 1000, y + -2000, 1000, 50, rampSpeed) + const mover2 = level.mover(x + 1000, y + -800, 1000, 50, -rampSpeed) + const mover1 = level.mover(x, y + -325, 1000, 50, -rampSpeed) + const portal1 = level.portal({ + x: x + 125, + y: y - 415 + }, 2 * Math.PI, { //right + x: x + 125, + y: y - 2515 + }, 2 * Math.PI) //right + + const portal2 = level.portal({ + x: x + 1875, + y: y - 890 + }, Math.PI, { //left + x: x + 1875, + y: y - 2090 + }, Math.PI) //left + + doCustom.push(() => { + portal1[2].query() + portal1[3].query() + portal2[2].query() + portal2[3].query() + mover1.push(); + mover2.push(); + mover3.push(); + mover4.push(); + }) + doCustomTopLayer.push(() => { + portal1[0].draw(); + portal1[1].draw(); + portal1[2].draw(); + portal1[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + mover1.draw(); + mover2.draw(); + mover3.draw(); + mover4.draw(); + }) + for (let i = 0, numberOfMapElementsAdded = map.length - mapStartingLength; i < numberOfMapElementsAdded; i++) addMapToLevelInProgress(map[map.length - 1 - i]) + simulation.draw.setPaths() //update map graphics + + //blocks that ride the movers and portals + spawn.bodyRect(x + 175, y + -2525, 50, 75); + spawn.bodyRect(x + 300, y + -2525, 50, 50); + spawn.bodyRect(x + 500, y + -2525, 80, 75); + + //mobs go here + spawn.randomMob(x + 175, y + -125, 0); + spawn.randomMob(x + 1775, y + -125, 0); + // spawn.randomMob(x + 1750, y + -525, 0); + spawn.randomMob(x + 225, y + -1000, 0); + spawn.randomMob(x + 1675, y + -1075, 0); + // spawn.randomMob(x + 1575, y + -2450, 0); + spawn.randomMob(x + 425, y + -1850, 0); + spawn.randomMob(x + 1425, y + -1200, 0); + spawn.randomMob(x + 350, y + -1000, 0); + spawn.randomLevelBoss(x + 475, y + -1475); + spawn.secondaryBossChance(x + 1425, y + -1425); + } + } + } + ) + }, + (x = offset.x, y = offset.y) => { //hopBoss2 + const button = level.button(x + 935, y + 0) + button.isUp = true + // spawn.mapVertex(x + 5, y + -1318, "0 0 0 -250 125 -250"); //left ledges + // spawn.mapVertex(x + 1995, y + -1318, "0 0 0 -250 -125 -250"); // right ledges + doCustomTopLayer.push( + () => { + button.draw(); + if (button.isUp) { + button.query(); + if (!button.isUp) { + const mapStartingLength = map.length //track this so you know how many you added when running addMapToLevelInProgress + addMapToLevelInProgress = (who) => { //adds new map elements to the level while the level is already running //don't forget to run simulation.draw.setPaths() after you all the the elements so they show up visually + who.collisionFilter.category = cat.map; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(who, true); //make static + Composite.add(engine.world, who); //add to world + } + //map elements go here + spawn.mapRect(x + 150, y + -1400, 750, 50); + spawn.mapRect(x + 1100, y + -1400, 750, 50); + spawn.mapRect(x + 1825, y + -1050, 200, 50); + spawn.mapRect(x + -25, y + -1050, 200, 50); + spawn.mapRect(x + 1825, y + -325, 200, 50); + spawn.mapRect(x + -25, y + -325, 200, 50); + spawn.mapRect(x + 275, y + -700, 525, 50); + spawn.mapRect(x + 1200, y + -700, 525, 50); + spawn.mapRect(x + -25, y + -1400, 125, 1125); //side walls + spawn.mapRect(x + 1900, y + -1400, 150, 1125); + spawn.mapRect(x + 1900, y + -2700, 125, 1000); + spawn.mapRect(x + -50, y + -2725, 150, 1025); + spawn.mapRect(x + -25, y + -1750, 450, 50); + spawn.mapRect(x + 1575, y + -1750, 450, 50); + spawn.mapRect(x + 525, y + -1750, 950, 50); + for (let i = 0, numberOfMapElementsAdded = map.length - mapStartingLength; i < numberOfMapElementsAdded; i++) addMapToLevelInProgress(map[map.length - 1 - i]) + simulation.draw.setPaths() //update map graphics + //mobs go here + powerUps.spawn(x + 50, y - 1525, "ammo"); + powerUps.spawn(x + 1950, y - 1525, "ammo"); + powerUps.spawn(x + 1900, y - 1525, "ammo"); + spawn.hopMotherBoss(x + 800, y + -2200) + for (let i = 0; i < 4; ++i) spawn.hopBullet(x + 150 + 750 * Math.random(), y + -1600) + for (let i = 0; i < 4; ++i) spawn.hopBullet(x + 1100 + 750 * Math.random(), y + -1600) + spawn.hopper(x + 1550, y + -775); + spawn.hopper(x + 500, y + -775); + spawn.hopper(x + 500, y + -2200); + spawn.hopper(x + 1100, y + -2200); + spawn.hopMother(x + 1400, y + -775); + spawn.hopMother(x + 550, y + -775); + spawn.hopMother(x + 525, y + -1475); + spawn.hopMother(x + 1550, y + -1500); + } + } + } + ) + }, + (x = offset.x, y = offset.y) => { + // const toggle = level.toggle(x + 950, y + 0, false, true) // toggle(x, y, isOn = false, isLockOn = false) { + // toggle.isAddedElements = false + + const button = level.button(x + 935, y + 0) + button.isUp = true + + + spawn.mapVertex(x + 5, y + -1318, "0 0 0 -250 125 -250"); //left ledges + spawn.mapVertex(x + 1995, y + -1318, "0 0 0 -250 -125 -250"); // right ledges + doCustomTopLayer.push( + () => { + button.draw(); + if (button.isUp) { + button.query(); + if (!button.isUp) { + // toggle.isAddedElements = true //only do this once + addMapToLevelInProgress = (who) => { //adds new map elements to the level while the level is already running //don't forget to run simulation.draw.setPaths() after you all the the elements so they show up visually + who.collisionFilter.category = cat.map; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(who, true); //make static + Composite.add(engine.world, who); //add to world + } + let r = 150 + let hexagon = `${r} 0 ${r * Math.cos(5.236)} ${r * Math.sin(5.236)} ${r * Math.cos(4.189)} ${r * Math.sin(4.189)} ${-r} 0 ${r * Math.cos(2.0944)} ${r * Math.sin(2.0944)} ${r * Math.cos(1.0472)} ${r * Math.sin(1.0472)} ` + //450 horizontal spread // -130-130-130 = 390 vertical + if (Math.random() < 0.5) { + spawn.mapVertex(x + 775, y + -260, hexagon); + spawn.mapVertex(x + 1225, y + -260, hexagon); + + spawn.mapVertex(x + 550, y + -650, hexagon); + spawn.mapVertex(x + 1000, y + -650, hexagon); + spawn.mapVertex(x + 1450, y + -650, hexagon); + + spawn.mapVertex(x + 325, y + -1040, hexagon); + spawn.mapVertex(x + 775, y + -1040, hexagon); + spawn.mapVertex(x + 1225, y + -1040, hexagon); + spawn.mapVertex(x + 1675, y + -1040, hexagon); + + spawn.mapVertex(x + 550, y + -1430, hexagon); + spawn.mapVertex(x + 1000, y + -1430, hexagon); + spawn.mapVertex(x + 1450, y + -1430, hexagon); + + const numberOfMapElementsAdded = 12 + for (let i = 0; i < numberOfMapElementsAdded; i++) addMapToLevelInProgress(map[map.length - 1 - i]) + spawn.randomMob(x + 225, y + -1775, mobSpawnChance); + spawn.randomMob(x + 700, y + -1750, mobSpawnChance); + spawn.randomMob(x + 1175, y + -1725, mobSpawnChance); + spawn.randomMob(x + 1700, y + -1700, mobSpawnChance); + spawn.randomMob(x + 1750, y + -250, mobSpawnChance); + spawn.randomMob(x + 125, y + -250, mobSpawnChance); + } else { + spawn.mapVertex(x + 775, y + -260, hexagon); + spawn.mapVertex(x + 1225, y + -260, hexagon); + + spawn.mapVertex(x + 550, y + -650, hexagon); + spawn.mapVertex(x + 1000, y + -650, hexagon); + spawn.mapVertex(x + 1450, y + -650, hexagon); + + spawn.mapVertex(x + 775, y + -1040, hexagon); + spawn.mapVertex(x + 1225, y + -1040, hexagon); + + spawn.mapVertex(x + 550, y + -1430, hexagon); + spawn.mapVertex(x + 1000, y + -1430, hexagon); + spawn.mapVertex(x + 1450, y + -1430, hexagon); + + spawn.mapVertex(x + 775, y + -1820, hexagon); + spawn.mapVertex(x + 1225, y + -1820, hexagon); + const numberOfMapElementsAdded = 12 + for (let i = 0; i < numberOfMapElementsAdded; i++) addMapToLevelInProgress(map[map.length - 1 - i]) + + spawn.randomMob(x + 225, y + -1025, mobSpawnChance); + spawn.randomMob(x + 250, y + -1025, mobSpawnChance); + spawn.randomMob(x + 200, y + -675, mobSpawnChance); + spawn.randomMob(x + 225, y + -200, mobSpawnChance); + spawn.randomMob(x + 1750, y + -1075, mobSpawnChance); + spawn.randomMob(x + 1700, y + -650, mobSpawnChance); + spawn.randomMob(x + 1725, y + -650, mobSpawnChance); + spawn.randomMob(x + 1675, y + -175, mobSpawnChance); + } + simulation.draw.setPaths() //update map graphics + spawn.randomGroup(x + 300, y + -2200); + spawn.randomGroup(x + 1625, y + -2200); + spawn.randomLevelBoss(x + 700, y + -2300); + spawn.secondaryBossChance(x + 1250, y + -2300) + } + } + // toggle.query(); + // if (toggle.isOn && !toggle.isAddedElements) { //this code runs once after the toggle is triggered + + // } + } + ) + }, + (x = offset.x, y = offset.y) => { + // const toggle = level.toggle(x + 950, y + 0, false, true) // toggle(x, y, isOn = false, isLockOn = false) { + // toggle.isAddedElements = false + const button = level.button(x + 935, y + 0) + button.isUp = true + //left ledges + spawn.mapVertex(x + 5, y + -1868, "0 0 0 -250 125 -250"); + spawn.mapVertex(x + 5, y + -1318, "0 0 0 -250 125 -250"); //door + spawn.mapVertex(x + 5, y + -768, "0 0 0 -250 125 -250"); + // right ledges + spawn.mapVertex(x + 2000, y + -1868, "0 0 0 -250 -125 -250"); + spawn.mapVertex(x + 2000, y + -1318, "0 0 0 -250 -125 -250"); //door + spawn.mapVertex(x + 2000, y + -768, "0 0 0 -250 -125 -250"); + + doCustomTopLayer.push( + () => { + button.draw(); + if (button.isUp) { + button.query(); + if (!button.isUp) { + addMapToLevelInProgress = (who) => { //adds new map elements to the level while the level is already running //don't forget to run simulation.draw.setPaths() after you all the the elements so they show up visually + who.collisionFilter.category = cat.map; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(who, true); //make static + Composite.add(engine.world, who); //add to world + } + //right side hexagons + let r = 300 + let hexagon = `${r} 0 ${r * Math.cos(5.236)} ${r * Math.sin(5.236)} ${r * Math.cos(4.189)} ${r * Math.sin(4.189)} ${-r} 0 ${r * Math.cos(2.0944)} ${r * Math.sin(2.0944)} ${r * Math.cos(1.0472)} ${r * Math.sin(1.0472)} ` + spawn.mapVertex(x + 1640, y + -365, hexagon); + // r = 275 + // let hexagonHalf = `${r} 0 ${r*Math.cos(5.236)} ${r*Math.sin(5.236)} ${r*Math.cos(4.189)} ${r*Math.sin(4.189)} ${-r} 0 ` + // spawn.mapVertex(x + 2300, y + -75, hexagonHalf); + r = 150 + const hexagon150 = `${r} 0 ${r * Math.cos(5.236)} ${r * Math.sin(5.236)} ${r * Math.cos(4.189)} ${r * Math.sin(4.189)} ${-r} 0 ${r * Math.cos(2.0944)} ${r * Math.sin(2.0944)} ${r * Math.cos(1.0472)} ${r * Math.sin(1.0472)} ` + // spawn.mapVertex(x + 1750, y + -550, hexagon150); + spawn.mapVertex(x + 1750, y + -1100, hexagon150); + spawn.mapVertex(x + 1750, y + -1650, hexagon150); + spawn.mapVertex(x + 1750, y + -2200, hexagon150); + + //left side + r = 350 + let hexagonHalf = `${r} 0 ${r * Math.cos(5.236)} ${r * Math.sin(5.236)} ${r * Math.cos(4.189)} ${r * Math.sin(4.189)} ${-r} 0 ` + spawn.mapVertex(x + 425, y + -90, hexagonHalf); + + spawn.mapVertex(x + 850, y + -500, hexagon150); + spawn.mapVertex(x + 550, y + -850, hexagon150); + spawn.mapVertex(x + 250, y + -1200, hexagon150); + spawn.mapVertex(x + 250, y + -1700, hexagon150); + spawn.mapVertex(x + 725, y + -1950, hexagon150); + spawn.mapVertex(x + 1200, y + -2200, hexagon150); + const numberOfMapElementsAdded = 11 + for (let i = 0; i < numberOfMapElementsAdded; i++) addMapToLevelInProgress(map[map.length - 1 - i]) + + spawn.randomMob(x + 1050, y + -1500, mobSpawnChance); + spawn.randomMob(x + 1075, y + -1500, mobSpawnChance); + spawn.randomMob(x + 325, y + -550, mobSpawnChance); + spawn.randomMob(x + 800, y + -925, mobSpawnChance); + spawn.randomMob(x + 1400, y + -1250, mobSpawnChance); + spawn.randomMob(x + 1325, y + -1725, mobSpawnChance); + spawn.randomMob(x + 1350, y + -1725, mobSpawnChance); + spawn.randomMob(x + 575, y + -1375, mobSpawnChance); + spawn.randomMob(x + 225, y + -2275, mobSpawnChance); + spawn.randomMob(x + 875, y + -2450, mobSpawnChance); + spawn.randomMob(x + 1550, y + -2525, mobSpawnChance); + spawn.randomMob(x + 1525, y + -2525, mobSpawnChance); + spawn.randomLevelBoss(x + 1075, y + -1500); + spawn.secondaryBossChance(x + 1200, y + -1000) + simulation.draw.setPaths() //update map graphics + } + } + } + ) + }, + // (x = offset.x, y = offset.y) => { + // const elevator1 = level.elevator(x + 1100, y - 200, 250, 30, -2100, 0.0015) // x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }, isTeleport = false) { + // // const elevator1 = level.elevator(x + 175, y - 200, 250, 30, -1400, 0.001) + // // const elevator2 = level.elevator(x + 2175, y - 200, 250, 30, -1400, 0.001) + + // spawn.mapRect(-200, -1400, 350, 50); //up left door ledge + // spawn.mapRect(2450, -1400, 350, 50); //up right door ledge + + // spawn.mapRect(225, -450, 350, 350); //left crawl zone + // // spawn.mapRect(725, -175, 275, 75); + // spawn.mapRect(725, -225, 350, 100); + // spawn.mapRect(275, -750, 200, 200); + // spawn.mapRect(1375, -700, 500, 750); //right side big elevator wall + // spawn.mapRect(2375, -325, 350, 50); + // spawn.mapRect(1800, -500, 250, 50); + + // //up high elevator + // spawn.mapRect(1375, -2100, 500, 175); + // spawn.mapRect(600, -2100, 475, 175); + + // if (simulation.difficulty > 3) spawn.randomLevelBoss(x + 1250, y - 1400); + // doCustomTopLayer.push( + // () => { + // elevator1.move() + // } + // ) + // } + ] + //pick which type of room spawns + enter = enterOptions[Math.floor(Math.random() * enterOptions.length)]; + exit = exitOptions[Math.floor(Math.random() * exitOptions.length)]; + empty = emptyOptions[Math.floor(Math.random() * emptyOptions.length)]; + loot = lootOptions[Math.floor(Math.random() * lootOptions.length)]; + upDown = upDownOptions[Math.floor(Math.random() * upDownOptions.length)]; + // upDown = upDownOptions[0] //controls what level spawns for map designing building //********************************* DO !NOT! RUN THIS LINE IN THE FINAL VERSION *************************************** + //3x2: 4 short rooms (3000x1500), 1 double tall room (3000x3000) + //rooms + let rooms = ["exit", "loot", "enter", "empty"] + rooms = shuffle(rooms); //shuffles array order + //look... you and I both know there is a better way to do this, but it works so I'm gonna focus on other things + while ( //makes sure that the exit and entrance aren't both on the same floor + (rooms[0] === "enter" && rooms[2] === "exit") || + (rooms[2] === "enter" && rooms[0] === "exit") || + (rooms[1] === "enter" && rooms[3] === "exit") || + (rooms[3] === "enter" && rooms[1] === "exit") + ) rooms = shuffle(rooms); //shuffles array order + for (let i = 0; i < rooms.length; i++) { + if (rooms[i] === "enter") rooms[i] = enter + if (rooms[i] === "exit") rooms[i] = exit + if (rooms[i] === "empty") rooms[i] = empty + if (rooms[i] === "loot") rooms[i] = loot + } + // rooms = [enter, exit, loot, empty, ] //controls what level spawns for map designing building //********************************* DO !NOT! RUN THIS LINE IN THE FINAL VERSION *************************************** + + outline = (isLower = true) => { + spawn.mapRect(offset.x - 100, offset.y - 1400, 2100, 100); //ceiling + if (isLower) spawn.mapRect(offset.x - 100, offset.y, 2200, 100); //only draw floor if on the lower level + if (!isDoorLeft) spawn.mapRect(offset.x - 100, offset.y - 1400, 100, 1500); //left wall + if (isDoorRight) { //if door only add wall on right side + spawn.mapRect(offset.x + 2000, offset.y - 1400, 100, 1225); //right wall + spawn.mapRect(offset.x + 2000, offset.y - 10, 100, 20); //right doorstep + const doorWidth = 15 + Math.floor(100 * Math.random() * Math.random()) + spawn.bodyRect(offset.x + 2050 - doorWidth / 2, offset.y - 175, doorWidth, 165); //block door + } else { + spawn.mapRect(offset.x + 2000, offset.y - 1400, 100, 1500); //right wall + } + } + outlineUpDown = () => { + spawn.mapRect(offset.x - 100, offset.y + 0, 2100, 100); //floor + spawn.mapRect(offset.x - 100, offset.y - 2800, 2100, 100); //ceiling + if (!isDoorLeft) spawn.mapRect(offset.x - 100, offset.y - 2800, 100, 2900); //left wall + if (isDoorRight) { //if door only add wall on right side + //upper door + spawn.mapRect(offset.x + 2000, offset.y - 2800, 100, 1225); //right wall + spawn.mapRect(offset.x + 2000, offset.y - 1410, 100, 20); //right doorstep + const doorWidth = 15 + Math.floor(100 * Math.random() * Math.random()) + spawn.bodyRect(offset.x + 2050 - doorWidth / 2, offset.y - 1575, doorWidth, 165); //block door + //lower door + spawn.mapRect(offset.x + 2000, offset.y - 1400, 100, 1225); //right wall + spawn.mapRect(offset.x + 2000, offset.y - 10, 100, 20); //right doorstep + const doorWidth2 = 15 + Math.floor(100 * Math.random() * Math.random()) + spawn.bodyRect(offset.x + 2050 - doorWidth2 / 2, offset.y - 175, doorWidth2, 165); //block door + } else { + spawn.mapRect(offset.x + 2000, offset.y - 2800, 100, 2900); //right wall + } + } + + let columns = [ + () => { + offset.y = 0 + outlineUpDown() + upDown() + }, + () => { + offset.y = 0 + outline() + rooms[0]() + + offset.y = -1400 + outline(false) + rooms[1]() + }, + () => { + offset.y = 0 + outline() + rooms[2]() + + offset.y = -1400 + outline(false) + rooms[3]() + }, + ] + columns = shuffle(columns) //********************************* RUN THIS LINE IN THE FINAL VERSION *************************************** + for (let i = 0; i < 3; i++) { + if (i === 0) { + isDoorLeft = false + isDoorRight = true + } else if (i === 1) { + isDoorLeft = true + isDoorRight = true + } else { + isDoorLeft = true + isDoorRight = false + } + offset.x = i * 2100 + columns[i]() + } + level.custom = () => { + for (let i = 0, len = doCustom.length; i < len; i++) doCustom[i]() //runs all the active code from each room + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + for (let i = 0, len = doCustomTopLayer.length; i < len; i++) doCustomTopLayer[i]() //runs all the active code from each room + }; + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + pavilion() { + level.announceMobTypes() + level.fallMode = "start"; + const vanish = [] + level.exit.x = -850; + level.exit.y = -1485; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 25); + level.setPosToSpawn(-900, 225); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.defaultZoom = 1500 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#dcdcde"; + spawn.debris(-150, -775, 1425, 3); //16 debris per level + spawn.debris(1525, -25, 950, 3); //16 debris per level + spawn.debris(-650, -2100, 575, 2); //16 debris per level + + //bottom floor + //entrance + spawn.mapRect(-200, -750, 1500, 100); + spawn.mapRect(-575, 0, 2150, 500); + // spawn.mapRect(-1275, 275, 875, 225); + spawn.mapRect(-1275, 275, 3975, 225); + spawn.mapRect(-1050, 0, 325, 50); + spawn.mapRect(-775, 0, 50, 140); + vanish.push(level.vanish(-725, 13, 150, 25)) + spawn.mapRect(-200, -750, 100, 600); + // spawn.mapRect(1200, -750, 100, 600); + vanish.push(level.vanish(-350, -225, 150, 225)) + vanish.push(level.vanish(-350, -450, 150, 223)) + spawn.mapRect(2475, -1800, 250, 2300); + + + spawn.mapRect(1200, -750, 100, 450); + spawn.mapRect(1200, -375, 250, 75); + powerUps.spawnStartingPowerUps(550, -100); + spawn.mapRect(125, -12, 850, 50); + spawn.mapRect(175, -25, 750, 50); + spawn.bodyRect(1350, -175, 150, 175, 0.5); + spawn.bodyRect(1350, -600, 125, 225, 0.2); + + //middle floor + spawn.bodyRect(215, -1175, 100, 100, 0.3); + spawn.mapRect(-1300, -1800, 250, 2300); + // spawn.mapRect(-1300, -2075, 250, 2575); + if (Math.random() < 0.5) { + spawn.mapRect(500, -1350, 525, 425); + spawn.mapRect(25, -1050, 300, 198); + } else { + spawn.mapRect(500, -1350, 525, 497); + spawn.mapRect(25, -1050, 300, 150); + } + if (Math.random() < 0.5) { + vanish.push(level.vanish(400, -1600, 175, 25)) + vanish.push(level.vanish(950, -1600, 175, 25)) + } else { + vanish.push(level.vanish(550, -1575, 50, 225)) + vanish.push(level.vanish(925, -1575, 50, 225)) + } + + // vanish.push(level.vanish(575, -1575, 375, 225)) + spawn.bodyRect(225, -850, 50, 100, 0.4); + spawn.mapRect(600, -1800, 325, 225); + spawn.mapRect(1900, -1500, 325, 25); + spawn.bodyRect(1050, -1825, 250, 20, 0.2); + if (Math.random() < 0.5) { + vanish.push(level.vanish(1400, -1000, 200, 25)) + vanish.push(level.vanish(1625, -1250, 200, 25)) + } else { + vanish.push(level.vanish(1400, -1075, 175, 175)) + vanish.push(level.vanish(1575, -1250, 175, 175)) + } + vanish.push(level.vanish(1125, -1800, 625, 25)) + + // vanish.push(level.vanish(1500, -1800, 225, 25)) + vanish.push(level.vanish(-50, -1800, 450, 25)) + + //exit + // spawn.mapRect(-1050, -1450, 700, 25); + // spawn.mapRect(-1050, -1800, 525, 25); + spawn.mapRect(-575, -1800, 50, 200); + spawn.mapRect(-1050, -1800, 525, 75); + spawn.mapRect(-1050, -1450, 700, 75); + + spawn.randomMob(-1175, -1975, -0.4); + spawn.randomMob(275, -1500, -0.3); + spawn.randomMob(700, -1875, -0.2); + spawn.randomMob(2000, -800, -0.2); + spawn.randomMob(2600, -1850, 0); + spawn.randomMob(1425, -525, 0.1); + spawn.randomMob(2025, -1600, 0.3); + spawn.randomMob(1625, -1875, 0.3); + spawn.randomMob(-150, -1975, 0.4); + spawn.randomSmallMob(900, -825); + spawn.randomSmallMob(1050, -50); + + if (simulation.difficulty > 1) { + spawn.randomGroup(750, -2150, -0.8) + spawn.randomLevelBoss(2050, -2025) + spawn.secondaryBossChance(100, -1500) + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + level.setPosToSpawn(900, 225); //normal spawn + level.custom = () => { + ctx.fillStyle = "#d0d3d9" + ctx.fillRect(-2500, -1800, 3575, 2100); + ctx.fillStyle = "#c0c3c9" + ctx.fillRect(-2075, -1475, 25, 1800); + ctx.fillStyle = "#cff" //exit + ctx.fillRect(550, -1800, 525, 350) + + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + //shadow + ctx.fillStyle = "rgba(0,10,30,0.1)" + ctx.fillRect(-1450, -300, 150, 325); + ctx.fillRect(-1300, -650, 1500, 650) + ctx.fillRect(725, 50, 325, 225) + ctx.fillRect(-325, -950, 300, 225) + ctx.fillRect(-1025, -1000, 525, 275); + ctx.fillRect(-925, -1600, 325, 275); + for (let i = 0, len = vanish.length; i < len; i++) vanish[i].query() + }; + + } else { + level.custom = () => { + ctx.fillStyle = "#d0d3d9" + ctx.fillRect(-1075, -1800, 3575, 2100); + ctx.fillStyle = "#c0c3c9" + ctx.fillRect(2050, -1475, 25, 1800); + ctx.fillStyle = "#cff" //exit + ctx.fillRect(-1050, -1800, 525, 350) + + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + //shadow + ctx.fillStyle = "rgba(0,10,30,0.1)" + ctx.fillRect(1300, -300, 150, 325); + ctx.fillRect(-200, -675, 1500, 700) + ctx.fillRect(500, -950, 525, 225); + ctx.fillRect(600, -1600, 325, 275); + ctx.fillRect(-1050, 50, 325, 225) + ctx.fillRect(25, -950, 300, 225) + for (let i = 0, len = vanish.length; i < len; i++) vanish[i].query() + }; + } + }, + testChamber() { + level.announceMobTypes() + level.setPosToSpawn(0, -50); //lower start + level.exit.y = level.enter.y - 550; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = level.enter.x; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + level.defaultZoom = 2200 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d0d5d5"; + color.map = "#444" + spawn.mapRect(0, -1955, 175, 30); + const removeIndex1 = map.length - 1 //so much work to catch blocks caught at the bottom of the vertical portals + spawn.mapRect(1225, -1955, 175, 30); + const removeIndex2 = map.length - 1 //so much work to catch blocks caught at the bottom of the vertical portals + let portal, portal2, portal3 + // const hazard = level.hazard((simulation.isHorizontalFlipped ? -350 - 700 : 350), -2025, 700, 10, 0.4) //laser + // const hazard2 = level.hazard((simulation.isHorizontalFlipped ? -1775 - 150 : 1775), -2550, 150, 10, 0.4) //laser + // const hazard = level.laser({ x: (simulation.isHorizontalFlipped ? -350 - 700 : 350), y: -2025 }, { x: 700 + (simulation.isHorizontalFlipped ? -350 - 700 : 350), y: -2025 }) ////x, y, width, height, damage = 0.002) + // const hazard2 = level.laser({ x: 145 + (simulation.isHorizontalFlipped ? -1775 - 150 : 1775), y: -2545 }, { x: (simulation.isHorizontalFlipped ? -1775 - 150 : 1775), y: -2545 }) ////x, y, width, height, damage = 0.002) + let hazard, hazard2 + if (simulation.isHorizontalFlipped) { + hazard = level.laser({ x: -360, y: -2020 }, { x: -1050, y: -2020 }) ////x, y, width, height, damage = 0.002) + hazard2 = level.laser({ x: - 1920, y: -2545 }, { x: -1775, y: -2545 }) ////x, y, width, height, damage = 0.002) + } else { + hazard = level.laser({ x: 360, y: -2020 }, { x: 700 + 360, y: -2020 }) ////x, y, width, height, damage = 0.002) + hazard2 = level.laser({ x: 145 + 1775, y: -2545 }, { x: 1775, y: -2545 }) ////x, y, width, height, damage = 0.002) + } + spawn.mapRect(340, -2032.5, 20, 25); //laser nose + spawn.mapRect(1920, -2557.5, 20, 25); //laser nose + const button = level.button(2100, -2600) + const buttonDoor = level.button(600, -550) + const door = level.door(312, -750, 25, 190, 185) + + level.custom = () => { + if (!(m.cycle % 60)) { //so much work to catch blocks caught at the bottom of the vertical portals + let touching = Matter.Query.collides(map[removeIndex1], body) + if (touching.length) { + Matter.Composite.remove(engine.world, touching[0].bodyB); + for (let i = 0, len = body.length; i < len; i++) { + if (body[i].id === touching[0].bodyB.id) { + body.splice(i, 1); + break + } + } + } + touching = Matter.Query.collides(map[removeIndex2], body) + if (touching.length) { + Matter.Composite.remove(engine.world, touching[0].bodyB); + for (let i = 0, len = body.length; i < len; i++) { + if (body[i].id === touching[0].bodyB.id) { + body.splice(i, 1); + break + } + } + } + } + + buttonDoor.query(); + buttonDoor.draw(); + if (buttonDoor.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + + portal[2].query() + portal[3].query() + portal2[2].query() + portal2[3].query() + portal3[2].query() + portal3[3].query() + button.query(); + button.draw(); + + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(-300, -1000, 650, 500) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + door.draw(); + if (!button.isUp) { + hazard.query(); + hazard2.query(); + } + + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + portal3[0].draw(); + portal3[1].draw(); + portal3[2].draw(); + portal3[3].draw(); + }; + powerUps.spawnStartingPowerUps(1875, -3075); + + const powerUpPos = shuffle([{ //no debris on this level but 2 random spawn instead + x: -150, + y: -1775 + }, { + x: 2400, + y: -2650 + }, { + x: -175, + y: -1375 + }, { + x: 1325, + y: -150 + }]); + powerUps.chooseRandomPowerUp(powerUpPos[0].x, powerUpPos[0].y); + powerUps.chooseRandomPowerUp(powerUpPos[1].x, powerUpPos[1].y); + //outer wall + spawn.mapRect(2500, -3700, 1200, 3800); //right map wall + spawn.mapRect(-1400, -3800, 1100, 3900); //left map wall + spawn.mapRect(-1400, -4800, 5100, 1200); //map ceiling + spawn.mapRect(-1400, 0, 5100, 1200); //floor + //lower entrance /exit + spawn.mapRect(300, -375, 50, 225); + spawn.bodyRect(312, -150, 25, 140); + spawn.mapRect(300, -10, 50, 50); + spawn.mapVertex(1555, 0, "625 0 75 0 200 -100 500 -100"); //entrance ramp + //upper entrance / exit + spawn.mapRect(-400, -1050, 750, 50); + spawn.mapRect(300, -1050, 50, 300); + // spawn.bodyRect(312, -750, 25, 190); + spawn.mapRect(300, -560, 50, 50); + spawn.bodyRect(750, -725, 125, 125); + spawn.mapRect(1150, -1050, 250, 575); + spawn.mapRect(1725, -550, 50, 200); //walls around portal 3 + spawn.mapRect(1925, -550, 500, 200); + spawn.mapRect(1750, -390, 200, 40); + spawn.mapRect(-400, -550, 1800, 200); + spawn.mapRect(-200, -1700, 150, 25); //platform above exit room + spawn.mapRect(-200, -1325, 350, 25); + //portal 3 angled + spawn.mapRect(2425, -450, 100, 100); + //portal 1 bottom + spawn.mapRect(2290, -12, 375, 100); + spawn.mapRect(2350, -24, 375, 100); + spawn.mapRect(2410, -36, 375, 100); + //portal 1 top + spawn.mapRect(2290, -3012, 375, 50); + spawn.mapRect(2350, -3024, 375, 50); + spawn.mapRect(2410, -3036, 375, 50); + spawn.mapRect(1400, -3000, 1300, 50); //floor + spawn.mapRect(1750, -3050, 250, 75); + spawn.mapRect(1400, -3625, 50, 200); + spawn.mapRect(350, -3625, 50, 225); + spawn.mapRect(350, -3260, 50, 60); + spawn.mapRect(200, -3250, 1240, 50); + spawn.mapRect(1400, -3260, 50, 310); + spawn.bodyRect(1412, -3425, 25, 165); + spawn.mapRect(-150, -2925, 150, 25); + //portal 2 + spawn.mapRect(-300, -2600, 300, 675); //left platform + spawn.mapRect(1400, -2600, 375, 675); //right platform + spawn.mapRect(1925, -2600, 775, 675); //far right platform + spawn.bodyRect(2130, -2660, 50, 50); //button's block + spawn.mapRect(150, -2100, 200, 175); + spawn.mapRect(1050, -2100, 200, 175); + //mobs + spawn.randomMob(1075, -3500, -0.3); + spawn.randomMob(2175, -700, -0.2); + spawn.randomMob(-75, -850, -0.1); + spawn.randomMob(550, -3400, 0); + spawn.randomMob(0, -1175, 0.5); + spawn.randomMob(-75, -1150, 0.5); + spawn.randomMob(1075, -625, 0.5); + spawn.randomMob(800, -3400, -0.3); + spawn.randomMob(1225, -3375, -0.2); + spawn.randomMob(1200, -1125, -0.1); + spawn.randomMob(2050, -950, 0.5); + if (simulation.difficulty > 40) { + spawn.randomMob(2300, -2775, -0.5); + spawn.randomMob(600, -925, -0.5); + spawn.randomMob(1550, -2750, -0.5); + spawn.randomMob(1350, -1150, -0.5); + spawn.randomMob(-75, -1475, 0); + spawn.randomGroup(600, -2600, 0); + } + if (simulation.difficulty > 1) { + if (Math.random() < 0.5) { + spawn.randomLevelBoss(700, -1550); + } else { + spawn.randomLevelBoss(675, -2775); //["shooterBoss", "launcherBoss", "laserTargetingBoss", "streamBoss", "shieldingBoss", "pulsarBoss", "grenadierBoss"] + } + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(1925, -1250) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + // level.setPosToSpawn(0, -50); //-x // no need since 0 + button.min.x = -button.min.x - 126 // flip the button horizontally + button.max.x = -button.max.x + 126 // flip the button horizontally + buttonDoor.min.x = -buttonDoor.min.x - 126 // flip the button horizontally + buttonDoor.max.x = -buttonDoor.max.x + 126 // flip the button horizontally + + //this makes the hazard draw, but not collide for reasons I don't understand + //so don't use it, instead just call the hazard differently based on this flip flag + // hazard.min.x = -hazard.min.x - hazard.width //-x-width + // hazard.max.x = -hazard.max.x - hazard.width //-x-width + // hazard2.min.x = -hazard2.min.x - hazard2.width //-x-width + // hazard2.max.x = -hazard2.max.x - hazard2.width //-x-width + portal = level.portal({ + x: -2475, + y: -140 + }, 2 * Math.PI, { //right + x: -2475, + y: -3140 + }, 2 * Math.PI) //right + + portal2 = level.portal({ + x: -75, + y: -2150 + }, -Math.PI / 2, { //up + x: -1325, + y: -2150 + }, -Math.PI / 2) //up + + portal3 = level.portal({ + x: -1850, + y: -585 + }, -Math.PI / 2, { //up + x: -2425, + y: -600 + }, -1 * Math.PI / 3) //up left + + // level.custom = () => { }; + // level.customTopLayer = () => {}; + + } else { + portal = level.portal({ + x: 2475, + y: -140 + }, Math.PI, { //left + x: 2475, + y: -3140 + }, Math.PI) //left + portal2 = level.portal({ + x: 75, + y: -2150 + }, -Math.PI / 2, { //up + x: 1325, + y: -2150 + }, -Math.PI / 2) //up + portal3 = level.portal({ + x: 1850, + y: -585 + }, -Math.PI / 2, { //up + x: 2425, + y: -600 + }, -2 * Math.PI / 3) //up left + } + + }, + interferometer() { + level.isVerticalFLipLevel = true + mobs.maxMobBody = 20 //normally 40, but set to 10 to avoid too much clutter + simulation.fallHeight = 4000 + level.announceMobTypes() + level.setPosToSpawn(-1825, 1950); //lower start + level.exit.x = -1875 + level.exit.y = 1355 + level.defaultZoom = 2300 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d0d5d5"; + color.map = "#444" + + let buttons = [] + let lasers = [] + let balance = [] + level.isFlipped = false; + let isFlipping = false; + let isSpawned = false + const flipAnimationCycles = 120 + + let elevator = body[body.length] = Bodies.rectangle(800, 500, 300, 50, { + collisionFilter: { + category: cat.body, //cat.map, + mask: cat.player | cat.body | cat.bullet | cat.mob | cat.mobBullet //| cat.powerUp + }, + density: 0.1, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 1, + frictionStatic: 1, + restitution: 0, + frictionAir: 1, + classType: "body", + holdX: 1762, + maxHeight: -1580, + minHeight: 130, + verticalForce: 0.03, + isUp: false, + drag: 0.01, + move() { + this.force.y -= this.mass * simulation.g; //undo gravity + if (!m.isTimeDilated) { + if (level.isFlipped) { + ctx.fillStyle = "#ccc" + ctx.fillRect(this.holdX, -this.maxHeight, 5, this.maxHeight - this.minHeight) //draw path + + if (elevator.isUp) { + elevator.force.y += elevator.verticalForce * elevator.mass + if (elevator.position.y > -elevator.maxHeight) { + elevator.isUp = false + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: -elevator.maxHeight }); + Matter.Body.setVelocity(elevator, { x: 0, y: 0 }); + } + } else { + elevator.force.y -= (elevator.verticalForce) * elevator.mass + if (elevator.position.y < -elevator.minHeight) { + elevator.isUp = true + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: -elevator.minHeight }); + Matter.Body.setVelocity(elevator, { x: 0, y: 0 }); + } + } + //vertical position limits + if (this.position.y > -elevator.maxHeight) { + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: -elevator.maxHeight }); + } else if (this.position.y < -elevator.minHeight) { + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: -elevator.minHeight }); + } + } else { + ctx.fillStyle = "#ccc" + ctx.fillRect(this.holdX, this.maxHeight, 5, this.minHeight - this.maxHeight) //draw path + + if (elevator.isUp) { + elevator.force.y -= elevator.verticalForce * elevator.mass + if (elevator.position.y < elevator.maxHeight) { + elevator.isUp = false + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: elevator.maxHeight }); + Matter.Body.setVelocity(elevator, { x: 0, y: 0 }); + } + } else { + elevator.force.y += (elevator.verticalForce) * elevator.mass + if (elevator.position.y > elevator.minHeight) { + elevator.isUp = true + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: elevator.minHeight }); + Matter.Body.setVelocity(elevator, { x: 0, y: 0 }); + } + } + //vertical position limits + if (this.position.y < elevator.maxHeight) { + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: elevator.maxHeight }); + } else if (this.position.y > elevator.minHeight) { + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: elevator.minHeight }); + } + } + } + Matter.Body.setVelocity(elevator, { x: 0, y: elevator.velocity.y * this.drag }); //zero horizontal velocity and drag + Matter.Body.setPosition(elevator, { x: elevator.holdX, y: elevator.position.y }); //hold horizontal position + }, + }); + Composite.add(engine.world, elevator); //add to world + + let buildMapOutline = function () { + //boxes center on zero,zero with deep walls to hide background + spawn.mapRect(2025, -2000, 1975, 4000); //right map wall + spawn.mapRect(-4000, -2000, 2000, 4000); //left map wall + spawn.mapRect(-4000, -5000, 8000, 3000); //map ceiling + spawn.mapRect(-4000, 2000, 8000, 3000); //floor + } + let buildNormalMap = function () { + buttons.push(level.button(-1895, -1600, 126, true, false, "hsl(330, 100%, 50%)")) + buttons[buttons.length - 1].isUp = false + spawn.mapRect(-1675, -2025, 50, 250); + + simulation.ephemera.push({ + name: "buttons up", + count: flipAnimationCycles + 30, + do() { + this.count-- + if (this.count < 0) { + for (let i = 0; i < buttons.length; i++) buttons[i].isUp = true + simulation.removeEphemera(this.name); + isFlipping = false + } + }, + }) + + lasers.push(level.laser({ x: -1100, y: 1990 }, { x: -1100, y: -2000 })) ////x, y, width, height, damage = 0.002) + spawn.mapRect(-1112, 1990, 25, 25); //laser entrance + lasers.push(level.laser({ x: -600, y: 1990 }, { x: -600, y: -2000 })) ////x, y, width, height, damage = 0.002) + spawn.mapRect(-612, 1990, 25, 25); //laser entrance + lasers.push(level.laser({ x: -100, y: 1990 }, { x: -100, y: -2000 })) ////x, y, width, height, damage = 0.002) + spawn.mapRect(-112, 1990, 25, 25); //laser entrance + + balance.push(level.rotor(-1250, 1755, 400, 25, 0.01, 0, 0.5)) //balance(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + balance.push(level.rotor(-750, 1755, 400, 25, 0.01, Math.PI / 2, 0.5)) + balance.push(level.rotor(-275, 1675, 550, 32, 0.01, 0, 0.5)) + + lasers.push(level.laser({ x: 1610, y: -850 }, { x: -1625, y: -850 })) ////x, y, width, height, damage = 0.002) + // spawn.mapRect(1980, -862, 25, 25); //laser entrance + // balance.push(level.rotor(1000, -910, 550, 32, 0.01, 0, 0.5)) + + //left side + //level entrance + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + spawn.mapRect(level.exit.x, level.exit.y - 40, 100, 20); + spawn.mapRect(-2025, 1650, 400, 50); + spawn.mapRect(-2100, -1600, 475, 2925); + spawn.mapRect(-1675, 1500, 50, 325); + + // spawn.mapRect(-1625, 365, 500, 950); + // spawn.mapRect(-1075, 390, 450, 900); + // spawn.mapRect(-575, 415, 500, 850); + + spawn.mapVertex(-1375, 835, "-250 -475 0 -500 250 -475 250 475 -250 475"); + spawn.mapVertex(-850, 840, "-225 -475 0 -500 225 -475 225 475 -225 475"); + spawn.mapVertex(-350, 840, "-225 -475 0 -500 225 -475 225 475 -225 475"); + + //lower right side + //far right wall ledges + spawn.mapRect(1925, -1700, 200, 200); + spawn.mapRect(1925, -1200, 200, 200); + spawn.mapRect(1925, -700, 200, 200); + spawn.mapRect(1925, -200, 200, 200); + spawn.mapRect(1925, 300, 200, 200); + spawn.mapRect(1925, 800, 200, 200); + spawn.mapRect(1925, 1300, 200, 200); + + spawn.mapRect(1250, 1650, 500, 25); + spawn.mapRect(1300, 1125, 400, 25); + spawn.mapRect(1350, 600, 300, 25); + spawn.mapRect(1400, 75, 200, 25); + + spawn.mapRect(650, 1287, 475, 50); + spawn.mapRect(650, 800, 500, 125); + spawn.mapRect(650, 150, 500, 225); + spawn.mapRect(350, 1300, 800, 375); + spawn.mapRect(350, 950, 150, 400); + spawn.mapRect(-25, 950, 525, 100); + spawn.mapRect(-75, 525, 575, 200); + spawn.mapRect(-75, 75, 575, 200); + spawn.mapRect(475, 1987, 550, 50); + + //ceiling zone + spawn.mapRect(1200, -1600, 400, 25); + spawn.mapRect(-75, -1725, 1075, 25); + spawn.mapRect(-575, -1625, 450, 25); + spawn.mapRect(-1075, -1850, 450, 25); + spawn.mapRect(-1075, -1425, 450, 25); + spawn.mapRect(-1675, -1588, 550, 25); + } + let buildVerticalFLippedMap = function () { // flip Y with this -> spawn.mapRect(x, -y - h, w, h); + buttons.push(level.button(-1895, 1600, 126, true, true, "hsl(330, 100%, 50%)")) + buttons[buttons.length - 1].isUp = false + spawn.mapRect(-1675, 2025 - 250, 50, 250); + + simulation.ephemera.push({ + name: "buttons up", + count: flipAnimationCycles + 30, + do() { + this.count-- + if (this.count < 0) { + for (let i = 0; i < buttons.length; i++) buttons[i].isUp = true + simulation.removeEphemera(this.name); + isFlipping = false + } + }, + }) + + lasers.push(level.laser({ x: -1100, y: -1990 }, { x: -1100, y: 2000 })) ////x, y, width, height, damage = 0.002) + spawn.mapRect(-1112, -1990 - 25, 25, 25); //laser entrance + lasers.push(level.laser({ x: -600, y: -1990 }, { x: -600, y: 2000 })) ////x, y, width, height, damage = 0.002) + spawn.mapRect(-612, -1990 - 25, 25, 25); //laser entrance + lasers.push(level.laser({ x: -100, y: -1990 }, { x: -100, y: 2000 })) ////x, y, width, height, damage = 0.002) + spawn.mapRect(-112, -1990 - 25, 25, 25); //laser entrance + + balance.push(level.rotor(-1250, -1755 - 25, 400, 25, 0.01, 0, 0.5)) //balance(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + balance.push(level.rotor(-750, -1755 - 25, 400, 25, 0.01, Math.PI / 2, 0.5)) + balance.push(level.rotor(-250, -1675 - 32, 500, 32, 0.01, 0, 0.5)) + + lasers.push(level.laser({ x: 1610, y: 850 }, { x: -1625, y: 850 })) ////x, y, width, height, damage = 0.002) + // spawn.mapRect(1980, 862 - 25, 25, 25); //laser entrance + // balance.push(level.rotor(1000, 910 - 32, 550, 32, 0.01, 0, 0.5)) + + //left side + //level entrance + spawn.mapRect(level.enter.x, level.enter.y - 20 - 20, 100, 20); + spawn.mapRect(level.exit.x, level.exit.y + 40 - 20, 100, 20); + spawn.mapRect(-2025, -1650 - 50, 400, 50); + spawn.mapRect(-2100, +1600 - 2925, 475, 2925); + spawn.mapRect(-1675, -1500 - 325, 50, 325); + + spawn.mapVertex(-1375, -835, "-250 -475 250 -475 250 475 0 500 -250 475"); + spawn.mapVertex(-850, -835, "-225 -475 225 -475 225 475 0 500 -225 475"); + spawn.mapVertex(-350, -835, "-225 -475 225 -475 225 475 0 500 -225 475"); + + //far right wall ledges + spawn.mapRect(1925, 1700 - 200, 200, 200); + spawn.mapRect(1925, 1200 - 200, 200, 200); + spawn.mapRect(1925, 700 - 200, 200, 200); + spawn.mapRect(1925, 200 - 200, 200, 200); + spawn.mapRect(1925, -300 - 200, 200, 200); + spawn.mapRect(1925, -800 - 200, 200, 200); + spawn.mapRect(1925, -1300 - 200, 200, 200); + + spawn.mapRect(1250, -1650 - 25, 500, 25); + spawn.mapRect(1300, -1125 - 25, 400, 25); + spawn.mapRect(1350, -600 - 25, 300, 25); + spawn.mapRect(1400, -75 - 25, 200, 25); + + spawn.mapRect(650, -1287 - 50, 475, 50); + spawn.mapRect(650, -800 - 125, 500, 125); + spawn.mapRect(650, -150 - 225, 500, 225); + spawn.mapRect(350, -1300 - 375, 800, 375); + spawn.mapRect(350, -950 - 400, 150, 400); + spawn.mapRect(-25, -950 - 100, 525, 100); + spawn.mapRect(-75, -525 - 200, 575, 200); + spawn.mapRect(-75, -75 - 200, 575, 200); + spawn.mapRect(475, -1987 - 50, 550, 50); + //ceiling zone + spawn.mapRect(1200, 1575, 400, 25); + spawn.mapRect(-75, 1700, 1075, 25); + spawn.mapRect(-575, 1625 - 25, 450, 25); + spawn.mapRect(-1075, 1850 - 25, 450, 25); + + spawn.mapRect(-1075, 1425 - 25, 450, 25); + spawn.mapRect(-1675, 1588 - 25, 550, 25); + } + let flipAndRemove = function () { + simulation.translatePlayerAndCamera({ x: player.position.x, y: -player.position.y }) + level.enter.y = -level.enter.y + level.exit.y = -level.exit.y + for (let i = body.length - 1; i > -1; i--) { + if (body[i].isRotor) body.splice(i, 1); + } + + function removeAll(array) { + for (let i = 0; i < array.length; ++i) Matter.Composite.remove(engine.world, array[i]); + } + removeAll(map); + map = []; + removeAll(balance); + balance = [] + removeAll(buttons); + buttons = [] + lasers = [] + + function invertVertical(array) { + for (let i = 0; i < array.length; ++i) { + Matter.Body.setPosition(array[i], { x: array[i].position.x, y: -array[i].position.y }) + } + } + invertVertical(body); + invertVertical(powerUp); + invertVertical(bullet); + invertVertical(mob); + //fields + if (m.fieldMode === 9 && m.hole.isOn) { + m.hole.pos1.y *= -1 + m.hole.pos2.y *= -1 + } else if (m.fieldMode === 2) { + m.fieldPosition.y *= -1 + m.fieldAngle *= -1 + } + //history + for (let i = 0; i < m.history.length; i++) { + m.history[i].position.y *= -1 + m.history[i].angle *= -1 + m.history[i].velocity.y *= -1 + } + for (let i = 0; i < mob.length; i++) { + //stun to wipe history of all mobs, so they don't get confused about player position vertical swap + mobs.statusStun(mob[i], 1) + //edge cases + if (mob[i].history) { + for (let j = 0; j < mob[i].history.length; j++) mob[i].history[j].y *= -1 + } + if (mob[i].laserArray) { + for (let j = 0; j < mob[i].laserArray.length; j++) { + mob[i].laserArray[j].a.y *= -1 + mob[i].laserArray[j].b.y *= -1 + } + } + if (mob[i].springTarget2) { + mob[i].springTarget.y *= -1 + mob[i].springTarget2.y *= -1 + } + } + } + buildMapOutline() + buildNormalMap() + level.custom = () => { + elevator.move() + // console.log(elevator) + lasers[lasers.length - 1].look.y = elevator.position.y + lasers[lasers.length - 1].position.y = elevator.position.y + + for (let i = 0; i < buttons.length; i++) { + buttons[i].draw() + if (buttons[i].isUp && !isFlipping) { + // buttons[i].query(); + buttons[i].queryPlayer(); + if (!buttons[i].isUp) { + isFlipping = true + if (level.isFlipped) { + const normalMap = function () { + level.isFlipped = false + flipAndRemove() + buildMapOutline() + buildNormalMap(); //rewrite flipped version of map + simulation.draw.setPaths() //update map graphics + level.addToWorld() + } + simulation.unFlipCameraVertical(flipAnimationCycles, normalMap) + } else { + const flipMap = function () { + level.isFlipped = true + flipAndRemove() + buildMapOutline() + buildVerticalFLippedMap(); //rewrite flipped version of map + simulation.draw.setPaths() //update map graphics + level.addToWorld() + if (!isSpawned) { + isSpawned = true + //spawn second wave of flipped mobs only once + spawn.randomMob(-1500, -1425, 0); + spawn.randomMob(-950, -1425, 0); + spawn.randomMob(-800, -1475, 0); + spawn.randomMob(-425, -1425, 0); + spawn.randomMob(850, -1750, 0.1); + spawn.randomMob(325, -850, 0.1); + spawn.randomMob(400, -400, 0.2); + spawn.randomMob(825, -475, 0.2); + spawn.randomMob(875, -1050, 0.3); + spawn.randomMob(1425, 1425, 0.4); + spawn.randomMob(675, 1450, 0.5); + spawn.randomMob(225, 1475, 0.6); + spawn.randomMob(-275, 1425, 1); + spawn.randomMob(-800, 1375, 1); + + spawn.secondaryBossChance(700, 1100) + } + } + simulation.flipCameraVertical(flipAnimationCycles, flipMap) + } + break + } + } + } + + if (level.isFlipped) { + //background structure + ctx.fillStyle = "#c3c7c7" + ctx.fillRect(1487, -75 - 1925, 25, 1925); + ctx.fillRect(1925, -2050, 125, 4100); + + //exit room + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(-2000, -1325 - 350, 375, 350) + level.exit.drawAndCheck(); + //draw flipped entrance + // ctx.translate(0, -3940) + ctx.beginPath(); + ctx.moveTo(level.enter.x, level.enter.y - 30); + ctx.lineTo(level.enter.x, level.enter.y + 80); + ctx.bezierCurveTo(level.enter.x, level.enter.y + 170, level.enter.x + 100, level.enter.y + 170, level.enter.x + 100, level.enter.y + 80); + ctx.lineTo(level.enter.x + 100, level.enter.y - 30); + ctx.lineTo(level.enter.x, level.enter.y - 30); + ctx.fillStyle = "#ccc"; + ctx.fill(); + // ctx.translate(0, 3940) + } else { + //background structure + ctx.fillStyle = "#c5c9c9" + ctx.fillRect(1487, 75, 25, 1925); + ctx.fillRect(1925, -2050, 125, 4100); + + //draw flipped exit + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(-2000, 1325, 375, 350) + ctx.beginPath(); + ctx.moveTo(level.exit.x, level.exit.y - 30); + ctx.lineTo(level.exit.x, level.exit.y + 80); + ctx.bezierCurveTo(level.exit.x, level.exit.y + 170, level.exit.x + 100, level.exit.y + 170, level.exit.x + 100, level.exit.y + 80); + ctx.lineTo(level.exit.x + 100, level.exit.y - 30); + ctx.lineTo(level.exit.x, level.exit.y - 30); + ctx.fillStyle = "#0ff"; + ctx.fill(); + level.enter.draw(); + } + }; + level.customTopLayer = () => { + for (let i = 0; i < lasers.length; i++) lasers[i].query() + ctx.fillStyle = "#233" //balances center dot + ctx.beginPath(); + for (let i = 0; i < balance.length; i++) { + ctx.moveTo(balance[i].center.x, balance[i].center.y) + ctx.arc(balance[i].center.x, balance[i].center.y, 9, 0, 2 * Math.PI); + //rotor spins and stops at vertical and horizontal angles + if ((simulation.cycle % 90) < 15) { + balance[i].torque = 0.0002 * balance[i].inertia + } else if (Math.floor(10 * (balance[i].angle % (Math.PI / 2))) === 0) { + Matter.Body.setAngularVelocity(balance[i], balance[i].angularVelocity * 0.1) + } + } + ctx.fill(); + ctx.fillStyle = `rgba(255,255,255,${0 + 0.3 * Math.random()})` + if (level.isFlipped) { + ctx.fillRect(-2025, 2025 - 450, 400, 450); + //shadows + ctx.fillStyle = "rgba(0,0,0,0.08)" + ctx.fillRect(-2025, -2075, 900, 775); + ctx.fillRect(-1075, -2025, 450, 725); + ctx.fillRect(-575, -2025, 450, 725); + + ctx.fillRect(-25, -250 - 725, 525, 725); + ctx.fillRect(650, -350 - 975, 475, 975); + ctx.fillRect(375, -1650 - 400, 750, 400); + //ceiling + ctx.fillStyle = "rgba(0,0,0,0.04)" + ctx.fillRect(1225, 2025 - 450, 350, 450); + ctx.fillRect(-50, 1700, 1025, 325); + ctx.fillRect(-550, 2025 - 425, 400, 425); + ctx.fillRect(-1050, 2025 - 625, 400, 625); + ctx.fillRect(-1625, 2025 - 450, 475, 450); + } else { + ctx.fillRect(-2025, -2025, 400, 450); + //shadows + ctx.fillStyle = "rgba(0,0,0,0.08)" + ctx.fillRect(-2025, 1300, 900, 775); + ctx.fillRect(-1075, 1300, 450, 725); + ctx.fillRect(-575, 1300, 450, 725); + + ctx.fillRect(-25, 250, 525, 725); + ctx.fillRect(650, 350, 475, 975); + ctx.fillRect(375, 1650, 750, 400); + //ceiling + ctx.fillStyle = "rgba(0,0,0,0.04)" + ctx.fillRect(1225, -2025, 350, 450); + ctx.fillRect(-50, -2025, 1025, 325); + ctx.fillRect(-550, -2025, 400, 425); + ctx.fillRect(-1050, -2025, 400, 625); + ctx.fillRect(-1625, -2025, 475, 450); + } + }; + spawn.bodyRect(1325, -1775, 175, 175); + spawn.bodyRect(-375, -1725, 100, 75, 0.5); + spawn.bodyRect(-900, -1625, 125, 200, 0.5); + + spawn.bodyRect(-1662, 1325, 25, 175); + spawn.bodyRect(-1662, 1825, 25, 175); + // spawn.bodyRect(-1662, -1825, 25, 225); + + spawn.bodyRect(1900, 1875, 100, 125, 0.5); + spawn.bodyRect(400, 1925, 225, 50, 0.1); + spawn.bodyRect(950, 750, 75, 50, 0.1); + spawn.bodyRect(200, -25, 150, 100, 0.1); + spawn.bodyRect(300, 900, 75, 50, 0.1); + spawn.bodyRect(1475, 1025, 100, 100, 0.1); + spawn.bodyRect(250, 450, 75, 75, 0.1); + spawn.bodyRect(775, 75, 75, 75, 0.1); + spawn.bodyRect(1200, 1900, 125, 100, 0.1); + + spawn.randomMob(125, -1900, 0); + spawn.randomMob(-375, -1875, 0); + spawn.randomMob(-1350, -1750, 0); + spawn.randomMob(-875, -1575, 0); + spawn.randomMob(500, -1875, 0); + spawn.randomMob(350, 825, 0); + spawn.randomMob(375, 400, 0); + spawn.randomMob(1500, -25, 0.1); + spawn.randomMob(650, -1950, 0.2); + spawn.randomMob(775, 700, 0.2); + spawn.randomMob(275, -50, 0.3); + spawn.randomMob(75, -1750, 0.3); + spawn.randomMob(1750, -1425, 0.4); + spawn.randomMob(950, 50, 0.4); + spawn.randomMob(-1375, 175, 0.4); + spawn.randomMob(-350, 175, 0.5); + spawn.randomMob(725, 1175, 0.5); + spawn.randomMob(-850, -1950, 0.6); + spawn.randomMob(-1400, -1725, 0.7); + spawn.randomMob(1400, -1700, 0.7); + spawn.randomMob(-800, 200, 0.7); + spawn.randomMob(1475, 1550, 0.8); + spawn.randomMob(1475, 500, 0.8); + + powerUps.spawnStartingPowerUps(-875, -1925); + spawn.randomLevelBoss(-875, -200); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + gravitron() { + mobs.maxMobBody = 25 //normally 40, but set lower to avoid too much clutter + level.isVerticalFLipLevel = true + simulation.fallHeight = 4000 + level.announceMobTypes() + level.setPosToSpawn(-2375, 950); + level.exit.x = 3750 + level.exit.y = 165 + level.defaultZoom = 2600 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#c3d6e1"; + color.map = "#444" + + let buttons = [] + level.isFlipped = false; + let isFlipping = false; + const flipAnimationCycles = 60 + + let buildMapOutline = function () { + //boxes center on zero,zero with deep walls to hide background + spawn.mapRect(4000, -2000, 2000, 4000); //right map wall + spawn.mapRect(-6000, -2000, 2000, 4000); //left map wall + spawn.mapRect(-6000, -4000, 12000, 3000); //map ceiling + spawn.mapRect(-6000, 1000, 12000, 3000); //floor + } + let buildNormalMap = function () { + buttons.push(level.button(-3350, 985, 126, true, false, "hsl(330, 100%, 50%)")) + buttons.push(level.button(-3350, -985, 126, true, true, "hsl(330, 100%, 50%)")) + buttons.push(level.button(150, 985, 126, true, false, "hsl(330, 100%, 50%)")) + buttons.push(level.button(150, -985, 126, true, true, "hsl(330, 100%, 50%)")) + buttons.push(level.button(3725, 985, 126, true, false, "hsl(330, 100%, 50%)")) + buttons.push(level.button(3725, -985, 126, true, true, "hsl(330, 100%, 50%)")) + for (let i = 0; i < buttons.length; i++) buttons[i].isUp = false + simulation.ephemera.push({ + name: "buttons up", + count: flipAnimationCycles, + do() { + this.count-- + if (this.count < 0) { + for (let i = 0; i < buttons.length; i++) buttons[i].isUp = true + simulation.removeEphemera(this.name); + isFlipping = false + } + }, + }) + //far left zone + spawn.mapRect(-2575, 987, 375, 100); + spawn.mapRect(-2575, -600, 600, 1325); + spawn.mapRect(-2200, 650, 225, 475); + spawn.mapRect(-2575, 700, 35, 125); + spawn.mapRect(-3500, -1050, 425, 63); + spawn.mapRect(-3500, 987, 425, 50); + spawn.mapVertex(-2275, -1000, "-400 0 -300 150 300 150 400 0"); + + spawn.mapVertex(-3287, 0, "-213 -500 0 -550 213 -500 213 500 0 550 -213 500"); + spawn.mapVertex(-3750, -100, "-100 -200 -50 -250 50 -250 100 -200 100 200 50 250 -50 250 -100 200"); + spawn.mapVertex(-2825, 0, "-100 -400 -50 -450 50 -450 100 -400 100 400 50 450 -50 450 -100 400"); + + //dense center left zone + spawn.mapVertex(-1150, -750, "400 -75 425 0 400 75 -400 75 -425 0 -400 -75"); + spawn.mapVertex(-550, -450, "400 -75 425 0 400 75 -400 75 -425 0 -400 -75"); + + spawn.mapVertex(-1685, 153, "-150 -500 0 -550 150 -500 150 750 -150 450"); + spawn.mapVertex(-1106, 707, "500 -150 550 0 500 150 -500 150 -800 -150"); + spawn.mapRect(-1645, 470, 200, 200); + Matter.Body.setAngle(map[map.length - 1], Math.PI / 4) + spawn.mapRect(-2085, 910, 200, 200); + Matter.Body.setAngle(map[map.length - 1], Math.PI / 4) + + //open center right area with both bosses + // spawn.mapRect(0, -450, 425, 1100); + spawn.mapVertex(213, 0, "-213 -700 0 -650 213 -600 213 700 0 650 -213 600"); + spawn.mapRect(0, -1050, 425, 63); + spawn.mapRect(0, 987, 425, 50); + spawn.mapVertex(1700, -1000, "-600 0 -400 400 400 400 600 0"); + spawn.mapVertex(2800, -1000, "-500 0 -400 150 400 150 500 0"); + spawn.mapVertex(1700, 700, "-400 -100 -450 0 -400 100 400 100 450 0 400 -100"); + spawn.mapVertex(2800, 375, "-400 -100 -450 0 -400 100 400 100 450 0 400 -100"); + + //far right exit structure + spawn.mapRect(3575, -1050, 425, 63); + spawn.mapRect(3575, 987, 425, 50); + spawn.mapVertex(3840, 450, "-250 -300 250 -300 250 300 -250 100"); + spawn.mapVertex(3840, -450, "-250 300 250 300 250 -300 -250 -100"); + spawn.mapRect(3750, 185, 100, 25); + } + let buildVerticalFLippedMap = function () { // flip Y with this -> spawn.mapRect(x, -y - h, w, h); + buttons.push(level.button(-3350, 985, 126, true, false, "hsl(330, 100%, 50%)")) + buttons.push(level.button(-3350, -985, 126, true, true, "hsl(330, 100%, 50%)")) + buttons.push(level.button(150, 985, 126, true, false, "hsl(330, 100%, 50%)")) + buttons.push(level.button(150, -985, 126, true, true, "hsl(330, 100%, 50%)")) + buttons.push(level.button(3725, 985, 126, true, false, "hsl(330, 100%, 50%)")) + buttons.push(level.button(3725, -985, 126, true, true, "hsl(330, 100%, 50%)")) + for (let i = 0; i < buttons.length; i++) buttons[i].isUp = false + + simulation.ephemera.push({ + name: "buttons up", + count: flipAnimationCycles, + do() { + this.count-- + if (this.count < 0) { + for (let i = 0; i < buttons.length; i++) buttons[i].isUp = true + simulation.removeEphemera(this.name); + isFlipping = false + } + }, + }) + + //far left zone + spawn.mapRect(-2575, -1087, 375, 100); + spawn.mapRect(-2575, 600 - 1325, 600, 1325); + spawn.mapRect(-2200, -650 - 475, 225, 475); + spawn.mapRect(-2575, -700 - 125, 35, 125); + spawn.mapRect(-3500, 1050 - 63, 425, 63); + spawn.mapRect(-3500, -987 - 50, 425, 50); + spawn.mapVertex(-2275, 1000, "-300 0 -400 150 400 150 300 0"); + + spawn.mapVertex(-3287, 0, "-213 -500 0 -550 213 -500 213 500 0 550 -213 500"); + spawn.mapVertex(-3750, 100, "-100 -200 -50 -250 50 -250 100 -200 100 200 50 250 -50 250 -100 200"); + spawn.mapVertex(-2825, 0, "-100 -400 -50 -450 50 -450 100 -400 100 400 50 450 -50 450 -100 400"); + + //dense center left zone + spawn.mapVertex(-1150, 750, "400 -75 425 0 400 75 -400 75 -425 0 -400 -75"); + spawn.mapVertex(-550, 450, "400 -75 425 0 400 75 -400 75 -425 0 -400 -75"); + + spawn.mapVertex(-1685, -153, "-150 500 0 550 150 500 150 -750 -150 -450"); + spawn.mapVertex(-1106, -707, "500 150 550 0 500 -150 -500 -150 -800 150"); + spawn.mapRect(-1645, -470 - 200, 200, 200); + Matter.Body.setAngle(map[map.length - 1], Math.PI / 4) + spawn.mapRect(-2085, -910 - 200, 200, 200); + Matter.Body.setAngle(map[map.length - 1], Math.PI / 4) + + //open center right area with both bosses + spawn.mapVertex(213, 0, "-213 -600 0 -650 213 -700 213 600 0 650 -213 700"); + spawn.mapRect(0, 1050 - 63, 425, 63); + spawn.mapRect(0, -987 - 50, 425, 50); + spawn.mapVertex(1700, 1000, "-400 0 -600 400 600 400 400 0"); + spawn.mapVertex(2800, 1000, "-400 0 -500 150 500 150 400 0"); + spawn.mapVertex(1700, -700, "-400 -100 -450 0 -400 100 400 100 450 0 400 -100"); + spawn.mapVertex(2800, -375, "-400 -100 -450 0 -400 100 400 100 450 0 400 -100"); + //far right building like exit structure + spawn.mapRect(3575, 1050 - 63, 425, 63); + spawn.mapRect(3575, -987 - 50, 425, 50); + spawn.mapVertex(3840, 450, "-250 -300 250 -300 250 300 -250 100"); + spawn.mapVertex(3840, -450, "-250 300 250 300 250 -300 -250 -100"); + spawn.mapRect(3750, -210, 100, 25); + } + let flipAndRemove = function () { + + level.enter.y = -level.enter.y + level.exit.y = -level.exit.y + for (let i = body.length - 1; i > -1; i--) { + if (body[i].isRotor) body.splice(i, 1); + } + + function removeAll(array) { + for (let i = 0; i < array.length; ++i) Matter.Composite.remove(engine.world, array[i]); + } + removeAll(map); + map = []; + removeAll(buttons); + buttons = [] + + simulation.translatePlayerAndCamera({ x: player.position.x, y: -player.position.y }, false) + function invertVertical(array) { + for (let i = 0; i < array.length; ++i) { + Matter.Body.setPosition(array[i], { x: array[i].position.x, y: -array[i].position.y }) + } + } + invertVertical(body); + invertVertical(powerUp); + invertVertical(bullet); + invertVertical(mob); + + //fields + if (m.fieldMode === 9 && m.hole.isOn) { + m.hole.pos1.y *= -1 + m.hole.pos2.y *= -1 + } else if (m.fieldMode === 2) { + m.fieldPosition.y *= -1 + m.fieldAngle *= -1 + } + //history + for (let i = 0; i < m.history.length; i++) { + m.history[i].position.y *= -1 + m.history[i].angle *= -1 + m.history[i].velocity.y *= -1 + } + for (let i = 0; i < mob.length; i++) { + //stun to wipe history of all mobs, so they don't get confused about player position vertical swap + mobs.statusStun(mob[i], 1) + //edge cases + if (mob[i].history) { + for (let j = 0; j < mob[i].history.length; j++) mob[i].history[j].y *= -1 + } + if (mob[i].laserArray) { + for (let j = 0; j < mob[i].laserArray.length; j++) { + mob[i].laserArray[j].a.y *= -1 + mob[i].laserArray[j].b.y *= -1 + } + } + if (mob[i].springTarget2) { + mob[i].springTarget.y *= -1 + mob[i].springTarget2.y *= -1 + } + } + } + buildMapOutline() + buildNormalMap() + level.custom = () => { + //stuff floats near buttons + // if ((player.position.x > -3505 && player.position.x < -3075) || + // (player.position.x > 0 && player.position.x < 425) || + // (player.position.x > 3575)) { + // if (player.position.y > 0) { + // player.force.y -= 0.8 * simulation.g * player.mass + // } + // } + for (let i = 0; i < body.length; i++) { + if ((body[i].position.x > -3505 && body[i].position.x < -3075) || + (body[i].position.x > 0 && body[i].position.x < 425) || + (body[i].position.x > 3575) + ) { + if (body[i].position.y > 0) { + body[i].force.y -= 1.04 * simulation.g * body[i].mass + } else { + body[i].force.y += 1.04 * simulation.g * body[i].mass + } + } + } + for (let i = 0; i < powerUp.length; i++) { + if ((powerUp[i].position.x > -3505 && powerUp[i].position.x < -3075) || + (powerUp[i].position.x > 0 && powerUp[i].position.x < 425) || + (powerUp[i].position.x > 3575) + ) { + if (powerUp[i].position.y > 0) { + powerUp[i].force.y -= 1.04 * simulation.g * powerUp[i].mass + } else { + powerUp[i].force.y += 1.04 * simulation.g * powerUp[i].mass + } + } + } + for (let i = 0; i < buttons.length; i++) { + buttons[i].draw() + if (buttons[i].isUp && !isFlipping) { + // buttons[i].query(); + buttons[i].queryPlayer(); + if (!buttons[i].isUp) { + isFlipping = true + if (level.isFlipped) { + const normalMap = function () { + level.isFlipped = false + flipAndRemove() + buildMapOutline() + buildNormalMap(); //rewrite flipped version of map + simulation.draw.setPaths() //update map graphics + level.addToWorld() + } + simulation.unFlipCameraVertical(flipAnimationCycles, normalMap) + } else { + const flipMap = function () { + level.isFlipped = true + flipAndRemove() + buildMapOutline() + buildVerticalFLippedMap(); //rewrite flipped version of map + simulation.draw.setPaths() //update map graphics + level.addToWorld() + } + simulation.flipCameraVertical(flipAnimationCycles, flipMap) + } + break + } + } + } + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(3575, -300, 475, 575); + if (level.isFlipped) { + //draw flipped entrance + ctx.beginPath(); + ctx.moveTo(level.enter.x, level.enter.y - 30); + ctx.lineTo(level.enter.x, level.enter.y + 80); + ctx.bezierCurveTo(level.enter.x, level.enter.y + 170, level.enter.x + 100, level.enter.y + 170, level.enter.x + 100, level.enter.y + 80); + ctx.lineTo(level.enter.x + 100, level.enter.y - 30); + ctx.lineTo(level.enter.x, level.enter.y - 30); + ctx.fillStyle = "#ccc"; + ctx.fill(); + //draw flipped exit + ctx.fillStyle = "#d4f4f4" + // ctx.fillRect(-2000, 1325, 375, 350) + ctx.beginPath(); + ctx.moveTo(level.exit.x, level.exit.y - 30); + ctx.lineTo(level.exit.x, level.exit.y + 80); + ctx.bezierCurveTo(level.exit.x, level.exit.y + 170, level.exit.x + 100, level.exit.y + 170, level.exit.x + 100, level.exit.y + 80); + ctx.lineTo(level.exit.x + 100, level.exit.y - 30); + ctx.lineTo(level.exit.x, level.exit.y - 30); + ctx.fillStyle = "#0ff"; + ctx.fill(); + } else { + level.exit.drawAndCheck(); + level.enter.draw(); + } + }; + level.customTopLayer = () => { + ctx.fillStyle = `rgba(255,255,255,${0 + 0.3 * Math.random()})` + ctx.fillRect(-3500, -1075, 425, 2100); + ctx.fillRect(0, -1075, 425, 2100); + ctx.fillRect(3575, -1075, 425, 2100); + ctx.fillStyle = "rgba(0,0,0,0.08)" + ctx.fillRect(-2575, -1025, 600, 2050); + ctx.fillRect(1300, -1050, 800, 2100); + ctx.fillRect(2400, -1050, 800, 2100); + }; + + // spawn.bodyRect(1900, 1875, 100, 125, 0.5); + spawn.bodyRect(-2569, 825, 25, 165); + + spawn.randomMob(-2275, -675, 0); + spawn.randomMob(-1200, 475, 0); + spawn.randomMob(525, 875, 0.1); + spawn.randomMob(1975, 900, 0.2); + spawn.randomMob(2800, 875, 0.2); + spawn.randomMob(-3275, -600, 0.3); + spawn.randomMob(-1250, -900, 0.3); + spawn.randomMob(-475, -600, 0.3); + spawn.randomMob(-1750, 850, 0.4); + spawn.randomMob(1700, 525, 0.4); + spawn.randomMob(2925, 175, 0.5); + spawn.randomMob(-2300, -825, 0.5); + spawn.randomMob(-1625, -450, 0.6); + spawn.randomMob(-225, 900, 0.6); + spawn.randomMob(275, -775, 0.7); + spawn.randomMob(2800, 875, 0.8); + spawn.randomMob(3825, -750, 0.9); + spawn.randomMob(2825, 150, 1); + spawn.randomMob(-1900, 875, 1); + + powerUps.spawnStartingPowerUps(-825, -600); + spawn.randomLevelBoss(1550, 200); + spawn.secondaryBossChance(2675, -125) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + substructure() { + // simulation.fallHeight = 4000 + level.announceMobTypes() + level.setPosToSpawn(-3800, -750); + level.exit.x = 3750 + level.exit.y = -625 + level.defaultZoom = 2000 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d0d5d5"; + color.map = "#444" + + const boost1 = level.boost(-2225, 1000, 1750) + const boost2 = level.boost(3400, 1000, 1750) + + const lasers = [] + const center = { x: 2800, y: 200 } + map[map.length] = Matter.Bodies.polygon(center.x, center.y, 20, 100) //center circle with lasers + lasers.push(level.laser({ x: center.x, y: center.y }, { x: center.x, y: center.y })) //oscillating laser + lasers[lasers.length - 1].oscillate = function () { + const angle = -0.45 + Math.PI / 2 - 1.47 * Math.sin(0.02 * simulation.cycle) //oscillate around circle + this.position = { + x: center.x + 102 * Math.cos(angle), + y: center.y + 102 * Math.sin(angle) + } + this.look = { + x: center.x + 2000 * Math.cos(angle), + y: center.y + 2000 * Math.sin(angle) + } + } + lasers.push(level.laser({ x: center.x, y: center.y }, { x: center.x, y: center.y })) //oscillating laser + lasers[lasers.length - 1].oscillate = function () { + const angle = -0.45 + -Math.PI / 2 + 1.47 * Math.sin(0.02 * simulation.cycle) //oscillate around circle + this.position = { + x: center.x + 102 * Math.cos(angle), + y: center.y + 102 * Math.sin(angle) + } + this.look = { + x: center.x + 2000 * Math.cos(angle), + y: center.y + 2000 * Math.sin(angle) + } + } + + lasers.push(level.laser({ x: -1500, y: -963 }, { x: -1500, y: 0 })) //oscillating laser + lasers[lasers.length - 1].oscillate = function () { + // if (this.countDown === 0) {} + const angle = Math.PI / 2 + 0.6 * Math.sin(simulation.cycle * 0.02) //oscillate around down + this.look = { + x: this.position.x + 600 * Math.cos(angle), + y: this.position.y + 600 * Math.sin(angle) + } + } + + lasers.push(level.laser({ x: 600, y: 580 }, { x: 600, y: 1000 })) //scrolling laser + lasers[lasers.length - 1].oscillate = function () { + this.position.x = 600 + 200 * Math.sin(simulation.cycle * 0.03) + this.look.x = 600 + 400 * Math.sin(simulation.cycle * 0.03) + } + + lasers.push(level.laser({ x: -115, y: -853 }, { x: 600, y: -50 })) + if (Math.random() < 0.33) { + lasers[lasers.length - 1].oscillate = function () { this.look.x = 300 + Math.abs(600 * Math.sin(simulation.cycle * 0.017)) } + } else if (Math.random() < 0.5) { + lasers[lasers.length - 1].oscillate = function () { this.look.x = 600 + 300 * Math.sin(simulation.cycle * 0.017) } + } else { + lasers[lasers.length - 1].oscillate = function () { this.look.x = 300 + (4 * simulation.cycle % 600) } + } + lasers.push(level.laser({ x: 2375, y: -876 }, { x: 2375, y: -300 })) //exit top + lasers[lasers.length - 1].oscillate = function () { + const angle = 1.4 + 1.15 * Math.sin(simulation.cycle * 0.021) //oscillate around down + this.look = { + x: this.position.x + 2000 * Math.cos(angle), + y: this.position.y + 2000 * Math.sin(angle) + } + } + lasers.push(level.laser({ x: 2375, y: -876 }, { x: 2375, y: -876 })) //exit top + lasers[lasers.length - 1].oscillate = function () { + const angle = 1.4 + 1.15 * Math.cos(simulation.cycle * 0.021) //oscillate around down + this.look = { + x: this.position.x + 2000 * Math.cos(angle), + y: this.position.y + 2000 * Math.sin(angle) + } + } + + lasers.push(level.laser({ x: -3565, y: -915 }, { x: -3565, y: -710 })) //entrance door + lasers.push(level.laser({ x: 3535, y: -915 }, { x: 3535, y: -575 })) //exit door + + if (Math.random() < 0.33) { + lasers.push(level.laser({ x: -400, y: -713 }, { x: -400, y: -295 })) //pillar top + } else if (Math.random() < 0.5) { + lasers.push(level.laser({ x: -400, y: -250 }, { x: -400, y: 200 })) //pillar mid + } else { + lasers.push(level.laser({ x: -400, y: 250 }, { x: -400, y: 750 })) //pillar low + } + + level.custom = () => { + boost1.query(); + boost2.query(); + + ctx.fillStyle = "#cacfcf" + ctx.fillRect(2787, -425, 25, 650); + ctx.fillRect(-600, -1050, 400, 1800); + + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,255,255,0.1)" //"#d4f4f4" //exit + ctx.fillRect(3535, -1050, 500, 475); + + //shadows + ctx.fillStyle = "rgba(0,20,60,0.09)" + ctx.fillRect(-4025, -1050, 1750, 2275); + ctx.fillRect(-2025, -1050, 1050, 2175); + ctx.fillRect(200, 0, 800, 975); + ctx.fillRect(1400, -150, 650, 1175); + ctx.fillRect(2200, -425, 1175, 1475); + + //rotate angle of lasers + for (let i = 0; i < 7; i++) lasers[i].oscillate() + for (let i = 0; i < lasers.length; i++) { + lasers[i].motionQuery() + } + }; + //boxes center on zero,zero with deep walls to hide background + spawn.mapRect(4000, -2000, 2000, 4000); //right map wall + spawn.mapRect(-6000, -2000, 2000, 4000); //left map wall + spawn.mapRect(-6000, -4000, 12000, 3000); //map ceiling + spawn.mapRect(-6000, 1000, 12000, 3000); //floor + //entrance + spawn.mapRect(-4000, -710, 450, 1800); + spawn.mapVertex(-3565, -1013, "-140 0 -8 150 8 150 140 0"); //entrance door + spawn.mapVertex(-3975, -975, "0 0 100 0 0 100"); //triangle at corner + spawn.mapVertex(-2900, 268, "-650 0 0 -40 650 0 650 2000 -650 2000 "); //angled floating structure + spawn.mapVertex(-2900, -990, "-600 0 0 40 600 0"); //wide ceiling triangle + //pillar 1 + spawn.mapVertex(-1500, -350, "-550 0 0 -40 550 0 550 350 0 390 -550 350 "); + spawn.mapVertex(-1500, 535, "-550 0 0 -40 550 0 550 500 0 540 -550 500 "); + spawn.mapVertex(-1500, -990, "-600 0 0 40 600 0"); + spawn.mapVertex(-1500, 990, "-550 0 0 -40 550 0 550 20 -550 20"); + //pillar 2 + spawn.mapVertex(-400, -875, "225 0 -225 0 -350 -300 350 -300"); + spawn.mapRect(-600, 200, 400, 50); + spawn.mapRect(-600, -300, 400, 50); + spawn.mapVertex(-400, 900, "350 0 -350 0 -225 -300 225 -300"); + //pillar 3 + spawn.mapVertex(600, 1000, "575 0 -575 0 -450 -100 450 -100"); + spawn.mapVertex(600, 500, "325 0 250 80 -250 80 -325 0 -250 -80 250 -80"); + spawn.mapRect(175, 450, 850, 100); + spawn.mapVertex(600, 0, "425 -20 425 20 390 50 -390 50 -425 20 -425 -20 -390 -50 390 -50"); + //far right building + spawn.mapRect(1600, 990, 450, 100); + spawn.mapRect(2200, 990, 1175, 100); + spawn.mapVertex(1500, 1015, "200 0 -200 0 -100 -100 100 -100"); + spawn.mapVertex(1500, 200, "-100 100 0 0 100 0 100 1000 -100 1000"); //left wall + spawn.mapRect(1550, -300, 500, 200); + spawn.mapVertex(2303.5, -350, "-100 100 0 0 100 0 100 500 -100 500"); //left wall + spawn.mapRect(2350, -600, 1025, 200); + spawn.mapVertex(2375, -975, "-140 0 -8 150 8 150 140 0"); //laser mount + //exit + spawn.mapRect(3525, -600, 550, 1675); + spawn.mapRect(3750, -610, 100, 50); + spawn.mapVertex(3535, -1013, "-140 0 -8 150 8 150 140 0"); //entrance door + spawn.mapVertex(3975, -990, "0 0 100 0 100 100"); //triangle at corner + + spawn.randomMob(-1150, 900, 0.1); + spawn.randomMob(675, 750, 0.1); + spawn.randomMob(3100, 875, 0.2); + spawn.randomMob(2975, -775, 0.2); + spawn.randomMob(1675, -550, 0.3); + spawn.randomMob(700, -300, 0.3); + spawn.randomMob(-325, -425, 0.4); + spawn.randomMob(-1375, -675, 0.4); + spawn.randomMob(-1425, 100, 0.5); + spawn.randomMob(-500, 75, 0.6); + spawn.randomMob(625, 250, 0.7); + spawn.randomMob(2125, 375, 0.7); + spawn.randomMob(-500, 600, 0.8); + spawn.randomMob(-1950, 875, 0.8); + spawn.randomMob(800, -400, 0.9); + spawn.randomMob(1675, -600, 0.9); + spawn.randomMob(2825, 75, 0.9); + spawn.randomLevelBoss(2400, 600); + spawn.secondaryBossChance(800, -300) + powerUps.spawnStartingPowerUps(600, 375); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + powerUps.directSpawn(2825, 175, "heal"); + powerUps.directSpawn(2475, -650, "heal"); + powerUps.directSpawn(2100, 925, "heal"); + powerUps.directSpawn(625, -100, "heal"); + }, + corridor() { + // simulation.fallHeight = 4000 + level.announceMobTypes() + level.defaultZoom = 2400 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d0d5d5"; + color.map = "#444" + + // level.isHorizontalFlipped = true + if (level.isHorizontalFlipped) { + level.setPosToSpawn(14075, -625); + level.exit.x = -350 + level.exit.y = 505 + spawn.bodyRect(13525, -675, 50, 100); + var color1 = "rgba(0,20,60,0.09)" + var color2 = "rgba(0,255,255,0.1)" + } else { + level.setPosToSpawn(-350, 475); + level.exit.x = 14025 + level.exit.y = -600 + spawn.bodyRect(-225, 475, 50, 50); + var color1 = "rgba(0,255,255,0.1)" + var color2 = "rgba(0,20,60,0.09)" + } + spawn.mapRect(14015, -585, 120, 75); //exit/entrance platform + + const buttonLeft = level.button(-4100, 991) + const buttonRight = level.button(4050, 991) + buttonLeft.isUp = true + // const buttonCamera = level.button(940, -1545) + // buttonRight.isUp = false + const boosts = [] + boosts.push(level.boost(-3650, 990, 2700, 1.45)) + boosts.push(level.boost(3325, 990, 1600, 1.4)) + boosts.push(level.boost(7960, -1110, 1650, 2.3)) + boosts.push(level.boost(13345, -460, 2070, 2.35)) + + const fizzlers = [] + fizzlers.push(level.fizzler({ x: -135, y: 265 }, { x: -135, y: 535 })) + fizzlers.push(level.fizzler({ x: -3850, y: 650 }, { x: -3850, y: 1025 })) + fizzlers.push(level.fizzler({ x: 3875, y: 675 }, { x: 3875, y: 1025 })) + fizzlers.push(level.fizzler({ x: 13425, y: -1275 }, { x: 13425, y: -550 })) + + const movers = [] + const baseMoverSpeed = 15 + movers.push(level.mover(-3550, 995, 6875, 150, -baseMoverSpeed)) + movers.push(level.mover(225, -1190, 2450, 50, -baseMoverSpeed)) + movers.push(level.mover(-3000, -1190, 3000, 50, baseMoverSpeed)) + movers.push(level.mover(4000, -2025, 2000, 150, -23)) + movers.push(level.mover(8000, -1125, 2000, 150, -23)) + movers.push(level.mover(3775, -425, 1650, 150, 20)) + movers.push(level.mover(5425, -425, 1925, 150, 40)) + movers.push(level.mover(7350, -425, 6000, 150, 60)) + + function setMoverDirection(index, VxGoal, force) { + movers[index].VxGoal = VxGoal + movers[index].force = force + } + level.custom = () => { + // buttonCamera.query() + // if (!buttonCamera.isUp) { + // simulation.setCameraPosition(100, -1000, 0.29) + // //block spawner + // spawn.mapRect(0, -2375, 200, 100); + // if (!(simulation.cycle % 10) && !m.isTimeDilated && body.length < 200) { + // const where = { x: 112, y: -3800 } + // // simulation.drawList.push({ x: where.x + 100 * (Math.random() - 0.5), y: where.y + 100 * (Math.random() - 0.5), radius: 11, color: "rgba(0,160,255,0.5)", time: 10 }); + + // let makeBlock = function (where, size) { + // const sides = Math.floor(4 + 6 * Math.random() * Math.random()) + // body[body.length] = Matter.Bodies.polygon(where.x, where.y, sides, size, { + // friction: 0.05, + // frictionAir: 0.001, + // collisionFilter: { + // category: cat.body, + // mask: cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + // }, + // classType: "body", + // density: 0.001, + // }); + // const who = body[body.length - 1] + // Composite.add(engine.world, who); //add to world + // } + // makeBlock({ x: where.x, y: where.y }, Math.floor(20 + 35 * Math.random() * Math.random())) + // } + // } + ctx.fillStyle = "#c8cccc"//background color is "#d0d5d5" + ctx.fillRect(-2150, 675, 500, 400); + ctx.fillRect(-1050, 675, 500, 400); + ctx.fillRect(750, 675, 500, 400); + ctx.fillRect(1850, 675, 500, 400); + ctx.fillRect(-2250, -2425, 700, 1325); + ctx.fillRect(-1150, -2400, 700, 1300); + ctx.fillRect(650, -2375, 700, 1325); + ctx.fillRect(1750, -2375, 700, 1350); + ctx.fillRect(8000, -2425, 2000, 2225); + ctx.fillRect(4000, -2375, 2000, 2100); + ctx.fillRect(11125, -2425, 1000, 2150) + level.exit.drawAndCheck(); + level.enter.draw(); + if (buttonRight.isUp) { + buttonRight.query(); + if (!buttonRight.isUp) { + requestAnimationFrame(() => buttonLeft.isUp = true); + setMoverDirection(0, -baseMoverSpeed, -0.0005) + const list = Matter.Query.region(body, buttonLeft) //are any blocks colliding with this + if (list.length > 0) Matter.Body.setVelocity(list[0], { x: baseMoverSpeed, y: -20 }); + } + } else if (buttonLeft.isUp) { + buttonLeft.query(); + if (!buttonLeft.isUp) { + requestAnimationFrame(() => buttonRight.isUp = true); + setMoverDirection(0, 20, 0.0005) + const list = Matter.Query.region(body, buttonRight) //are any blocks colliding with this + if (list.length > 0) Matter.Body.setVelocity(list[0], { x: -15, y: -20 }); + } + } + buttonRight.draw(); + buttonLeft.draw(); + for (let i = 0; i < movers.length; i++) movers[i].push(); + for (let i = 0; i < boosts.length; i++) boosts[i].query(); + }; + level.customTopLayer = () => { + for (let i = 0; i < fizzlers.length; i++) fizzlers[i].query(); + ctx.fillStyle = color1 //exit + ctx.fillRect(13400, -1325, 1000, 825); + //shadows + ctx.fillStyle = color2 + ctx.fillRect(-500, 225, 494, 350); + ctx.fillStyle = "rgba(0,5,10,0.06)" + ctx.beginPath(); + ctx.moveTo(0, -1180) + ctx.lineTo(225, -1180) + ctx.lineTo(3220, 669) + ctx.lineTo(3180, 1010) + ctx.lineTo(-2960, 1010) + ctx.lineTo(-2995, 674) + ctx.fill() + ctx.beginPath(); + //right button room + ctx.beginPath(); + ctx.moveTo(3780, 720) + ctx.lineTo(4325, 720) + ctx.lineTo(4325, 1010) + ctx.lineTo(3810, 1010) + ctx.fill() + //left button room + ctx.beginPath(); + ctx.moveTo(-3755, 675) + ctx.lineTo(-3785, 1010) + ctx.lineTo(-4250, 1010) + ctx.lineTo(-4250, 675) + ctx.fill() + ctx.fillStyle = "rgba(68, 68, 68,0.9)" + ctx.fillRect(-50, -4300, 325, 1950); + for (let i = 0; i < movers.length; i++) movers[i].draw(); + }; + spawn.mapRect(-6000, 1000, 12000, 3000); //floor + spawn.mapRect(-6000, -4300, 6020, 1950); + spawn.mapRect(205, -4300, 15120, 1950); + spawn.mapVertex(-250, 602.5, "-200 0 235 0 400 50 400 150 -200 150"); + spawn.mapVertex(-3675, -2275, "0 0 500 0 0 500"); + spawn.mapVertex(13275, -2275, "0 0 -500 0 0 500"); + spawn.mapRect(-525, -1175, 525, 1450); + spawn.mapRect(225, -1175, 3000, 1850); + spawn.mapRect(-3000, -1175, 2525, 1850); + spawn.mapRect(-4350, -2500, 600, 3175); + spawn.mapRect(-6000, -2350, 1775, 3350); + spawn.mapVertex(-1900, 675, "-350 0 -250 100 250 100 350 0"); + spawn.mapVertex(-800, 675, "-350 0 -250 100 250 100 350 0"); + spawn.mapVertex(1000, 675, "-350 0 -250 100 250 100 350 0"); + spawn.mapVertex(2100, 675, "-350 0 -250 100 250 100 350 0"); + + spawn.mapVertex(-1900, -1450, "-400 -40 -350 -90 350 -90 400 -40 400 40 350 90 -350 90 -400 40"); + spawn.mapVertex(-800, -1450, "-400 -40 -350 -90 350 -90 400 -40 400 40 350 90 -350 90 -400 40"); + spawn.mapVertex(1000, -1450, "-400 -40 -350 -90 350 -90 400 -40 400 40 350 90 -350 90 -400 40"); + spawn.mapVertex(2100, -1450, "-400 -40 -350 -90 350 -90 400 -40 400 40 350 90 -350 90 -400 40"); + + spawn.mapVertex(-1900, -2350, "-450 0 -350 100 350 100 450 0"); + spawn.mapVertex(-800, -2350, "-450 0 -350 100 350 100 450 0"); + spawn.mapVertex(1000, -2350, "-450 0 -350 100 350 100 450 0"); + spawn.mapVertex(2100, -2350, "-450 0 -350 100 350 100 450 0"); + spawn.mapRect(-1500, 840, 300, 20); + spawn.mapRect(1400, 840, 300, 20); + //ramp to catch blocks + spawn.mapVertex(3001, -1260, "0 0 400 -200 550 -200 550 75 0 75"); + spawn.mapVertex(4100, -1100, "-625 0 -600 -60 600 -60 625 0 600 60 -600 60"); + spawn.mapVertex(5550, -750, "-625 0 -600 -60 600 -60 625 0 600 60 -600 60"); + spawn.mapVertex(11625, -900, "-525 0 -500 -50 500 -50 525 0 500 50 -500 50"); + //base for mover + spawn.mapVertex(5000, -1935, "-1050 0 -1000 -90 1000 -90 1050 0 1000 90 -1000 90"); + spawn.mapVertex(9000, -1035, "-1050 0 -1000 -90 1000 -90 1050 0 1000 90 -1000 90"); + spawn.mapVertex(5000, -2370, "-1200 0 -1000 100 1000 100 1200 0"); + spawn.mapVertex(9000, -2310, "-1200 0 -1000 100 1000 100 1200 0"); + spawn.mapVertex(11625, -2310, "-600 0 -500 100 500 100 600 0"); + spawn.mapRect(3775, -400, 675, 1125); + spawn.mapRect(4300, -400, 11025, 4400); + //exit + spawn.mapRect(13400, -575, 1925, 300); + spawn.mapRect(14275, -2375, 1050, 2050); + spawn.mapRect(13400, -2375, 900, 1125); + + + //blocks on movers + spawn.bodyRect(-200, 950, 50, 50); + spawn.bodyRect(-1100, 925, 65, 75); + spawn.bodyRect(-2275, 975, 70, 25); + spawn.bodyRect(-3325, 925, 75, 75); + spawn.bodyRect(-2950, -1225, 90, 25); + spawn.bodyRect(-1425, -1275, 45, 75); + spawn.bodyRect(600, -1275, 70, 75); + spawn.bodyRect(1900, -1225, 90, 50); + spawn.bodyRect(4250, -2100, 115, 50); + spawn.bodyRect(2175, 900, 100, 65); + spawn.bodyRect(4075, -450, 75, 20); + spawn.bodyRect(8350, -1175, 90, 50); + spawn.bodyRect(6525, -525, 70, 100); + spawn.bodyRect(12025, -475, 130, 50); + spawn.bodyRect(625, 950, 55, 45); + spawn.bodyRect(6250, -450, 55, 25); + spawn.bodyRect(3950, -475, 46, 53); + //other blocks + spawn.bodyRect(3525, -1300, 100, 125, 0.6); + spawn.bodyRect(11550, -1150, 100, 200, 0.4); + + spawn.randomMob(-1775, -1650, 0); + spawn.randomMob(950, -1775, 0); + spawn.randomMob(1550, 775, 0); + spawn.randomMob(4500, -1250, 0); + spawn.randomMob(11400, -1300, 0); + spawn.randomMob(-800, -1675, 0); + spawn.randomMob(-1325, 775, 0.1); + spawn.randomMob(2050, -1625, 0.1); + spawn.randomMob(3100, -1475, 0.2); + spawn.randomMob(5400, -900, 0.2); + spawn.randomMob(11950, -1025, 0.3); + spawn.randomMob(-925, -1700, 0.3); + spawn.randomMob(2025, -1725, 0.4); + spawn.randomMob(1575, 775, 0.4); + spawn.randomMob(-1350, 775, 0.6); + spawn.randomMob(11925, -1275, 0.6); + spawn.randomMob(4325, -1425, 0.6); + spawn.randomMob(5425, -950, 0.6); + spawn.randomMob(3575, 375, 0.6); + spawn.randomGroup(5300, -1400, 1.3); + + spawn.randomLevelBoss(2025, -1825); + spawn.secondaryBossChance(-1900, -1800); + powerUps.spawnStartingPowerUps(11750, -1000); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + lock() { + level.announceMobTypes() + level.setPosToSpawn(0, -65); //lower start + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.y = 2010; + level.exit.x = 2625; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + level.defaultZoom = 2200 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "hsl(138, 5%, 82%)"; + color.map = "#444" + powerUps.spawnStartingPowerUps(1768, 870); //on left side + const portal = level.portal({ x: 1070, y: -1485 }, -0.9, { x: 475, y: 50 }, -Math.PI / 2) + const doorCenterRight = level.door(2787, 775, 25, 225, 195, 5) //x, y, width, height, distance, speed = 1 + const doorCenterLeft = level.door(2537, 775, 25, 225, 195, 5) + const doorButtonRight = level.door(4462, 1010, 25, 225, 195, 5) + const doorLeft = level.door(2538, 1825, 25, 225, 195, 5) + const buttonLeft = level.button(4565, 1235) + const buttonRight = level.button(4142, -355) + // spawn.mapRect(4000, -350, 700, 125); //button platform + spawn.mapRect(4000, -350, 600, 75); + buttonLeft.isUp = true + buttonRight.isUp = true + const hazardSlimeLeft = level.hazard(900, -300, 1638, 2450) //hazard(x, y, width, height, damage = 0.002) { + const hazardSlimeRight = level.hazard(2812, -300, 1650, 2450) //hazard(x, y, width, height, damage = 0.002) { + //set slime to empty + // hazardSlimeLeft.height -= hazardSlimeLeft.maxHeight //start slime at zero + // hazardSlimeLeft.min.y += hazardSlimeLeft.maxHeight + // hazardSlimeLeft.max.y = hazardSlimeLeft.min.y + hazardSlimeLeft.height + // hazardSlimeRight.height -= hazardSlimeRight.maxHeight //start slime at zero + // hazardSlimeRight.min.y += hazardSlimeRight.maxHeight + // hazardSlimeRight.max.y = hazardSlimeRight.min.y + hazardSlimeRight.height + const balance = [] + level.custom = () => { + ctx.fillStyle = "hsl(175, 35%, 76%)" //exit + ctx.fillRect(2537, 1775, 275, 275) + level.exit.drawAndCheck(); + level.enter.draw(); + + doorButtonRight.isClosing = hazardSlimeRight.min.y < 1275 + doorCenterRight.isClosing = hazardSlimeRight.min.y < 1000 + doorCenterLeft.isClosing = hazardSlimeLeft.min.y < 1000 + doorLeft.isClosing = hazardSlimeLeft.min.y < 2050 + doorButtonRight.openClose(); + doorCenterRight.openClose(); + doorCenterLeft.openClose(); + doorLeft.openClose(); + if (buttonRight.isUp) { + buttonRight.query(); + if (!buttonRight.isUp) spawnRightMobs() + } + if (buttonLeft.isUp) { + buttonLeft.query(); + if (!buttonLeft.isUp) spawnLeftMobs() + } + buttonRight.draw(); + buttonLeft.draw(); + if (hazardSlimeLeft.min.y < 2050) { + const drainRate = Math.min(Math.max(0.25, 4 - hazardSlimeLeft.min.y / 500), 4) + hazardSlimeLeft.level(buttonLeft.isUp, drainRate) + } + if (hazardSlimeRight.min.y < 2050) { + const drainRate = Math.min(Math.max(0.25, 4 - hazardSlimeRight.min.y / 500), 4) + hazardSlimeRight.level(buttonRight.isUp, drainRate) + } + portal[2].query() + portal[3].query() + }; + level.customTopLayer = () => { + doorButtonRight.draw(); + doorCenterRight.draw(); + doorCenterLeft.draw(); + doorLeft.draw(); + hazardSlimeLeft.query(); + hazardSlimeRight.query(); + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + ctx.fillStyle = color.map //below portal + ctx.fillRect(375, 150, 200, 2525); + ctx.fillStyle = "rgba(0,0,0,0.1)" //shadows + ctx.fillRect(-250, -1550, 1250, 1575); + ctx.fillRect(2537, -350, 275, 2425); + ctx.fillStyle = "rgba(0,0,0,0.05)" //exit + ctx.fillRect(-175, -300, 375, 300) + ctx.fillRect(4460, 950, 350, 325); + ctx.fillStyle = "#233" //balances center dot + ctx.beginPath(); + for (let i = 0; i < balance.length; i++) { + ctx.arc(balance[i].center.x, balance[i].center.y, 9, 0, 2 * Math.PI); + } + ctx.fill(); + // for (let i = 0, len = vanish.length; i < len; i++) vanish[i].query() + }; + //entrance and outer walls + spawn.mapRect(-1400, 0, 1800, 2675); + spawn.mapRect(-1400, -1025, 1225, 1500); + spawn.mapRect(-325, -15, 525, 225); + spawn.mapRect(150, -350, 50, 175); + + spawn.mapRect(-1400, -3525, 1600, 3225); + spawn.mapRect(550, 0, 450, 2675); + + spawn.mapRect(550, -1550, 450, 125); + spawn.mapRect(150, -1550, 250, 125); + spawn.mapRect(750, -1425, 1100, 175); + spawn.mapRect(750, -1400, 250, 825); + spawn.mapRect(750, -350, 250, 575); + spawn.mapRect(625, 2100, 4300, 575); //floor + spawn.mapRect(-1400, -4425, 7250, 1000); //ceiling + // const vanish = [] + // vanish.push(level.vanish(400, -1512, 150, 50)) + // vanish.push(level.vanish(825, -625, 100, 325)) + + //left button room (on the far right in the + spawn.mapRect(4450, -3525, 1400, 4500); + spawn.mapRect(4450, 1235, 1400, 1440); + spawn.mapRect(4775, 750, 1075, 825); + spawn.mapRect(4450, 950, 50, 75); + + + //other ideas for left and right alternate setups + //just a floor covered with boosts + //something focused on funnel shapes + //several rooms with tunnels connecting them + //spinners + + //right side + if (Math.random() < 1) { + spawn.mapVertex(3350, 350, "-100 0 100 0 100 700 0 750 -100 700"); + balance.push(level.rotor(3463, 150, 300, 25, 0.001, 0)) //balance(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + balance.push(level.rotor(3463, 500, 300, 25, 0.001, 0)) + spawn.mapVertex(3875, 350, "-100 0 100 0 100 700 0 750 -100 700"); + + spawn.mapVertex(2900, 1743, "-100 0 70 0 100 30 100 1000 -100 1000"); + spawn.mapVertex(3025, 1811, "-150 0 120 0 150 30 150 600 -150 600"); + spawn.mapVertex(3200, 2079, "-150 0 120 0 150 30 150 600 -150 600"); + spawn.mapVertex(4425, 1743, "-150 30 -120 0 150 0 150 1000 -150 1000"); + spawn.mapVertex(4250, 1811, "-150 30 -120 0 150 0 150 600 -150 600"); + spawn.mapVertex(4075, 2079, "-150 30 -120 0 150 0 150 600 -150 600"); + + //escape ledge when drowning + spawn.mapRect(2750, 525, 100, 25); + spawn.mapRect(2750, 125, 100, 25); + spawn.mapRect(4425, 800, 75, 25); + spawn.mapRect(4425, 325, 75, 25); + // spawn.mapRect(4425, -100, 75, 25); + // spawn.mapRect(4425, -550, 75, 25); + // spawn.mapRect(4425, -1000, 75, 25); + + + // if (Math.random() < 0.5) { + // spawn.mapRect(2775, 525, 100, 25); + // spawn.mapRect(3200, 75, 125, 25); + // } else { + // spawn.mapRect(4400, 800, 100, 25); + // spawn.mapRect(3925, 400, 100, 25); + // } + } + //left side + if (Math.random() < 1) { + // spawn.mapVertex(2325, 1325, "-150 0 150 0 150 150 0 225 -150 150"); + spawn.mapVertex(1285, 1275, "-150 0 150 0 150 150 0 225 -150 150"); + spawn.mapVertex(1033, 1750, "0 200 200 200 300 50 300 -50 200 -200 0 -200"); + spawn.mapVertex(1575, 1750, "0 200 -200 200 -300 50 -300 -50 -200 -200 0 -200 100 -50 100 50"); //larger "0 400 -250 400 -400 100 -400 -100 -250 -400 0 -400" + + spawn.mapVertex(1287, 2185, "-100 30 -80 0 80 0 100 30 100 300 -100 300"); + spawn.mapVertex(2050, 2050, "-150 30 -120 0 120 0 150 30 150 300 -150 300"); + + // spawn.mapRect(1700, 1550, 275, 25); + // spawn.mapRect(2175, 1275, 325, 25); + spawn.mapRect(1600, 950, 375, 25); + + spawn.mapRect(1025, -50, 50, 25); + spawn.mapRect(1025, 275, 175, 25); + spawn.mapRect(1025, 600, 325, 25); + spawn.mapRect(2450, -50, 50, 25); + spawn.mapRect(2325, 275, 175, 25); + spawn.mapRect(2175, 600, 325, 25); + // spawn.mapVertex(3400, 1250, "-100 -300 0 -350 100 -300 100 300 0 350 -100 300"); + } + + //left button room in center divider + spawn.mapRect(2525, -350, 300, 1100); + spawn.mapRect(2525, 975, 300, 800); + spawn.mapRect(2775, 650, 50, 125); + spawn.mapRect(2525, 650, 50, 125); + + //exit room + spawn.mapRect(2475, 2040, 350, 200); + spawn.mapRect(2800, 1750, 25, 325); + spawn.mapRect(2525, 1750, 50, 75); + + //safety edge blocks //maybe remove? + // spawn.mapRect(2525, -375, 25, 50); + // spawn.mapRect(2800, -375, 25, 50); + // spawn.mapRect(1825, -1450, 25, 50); + // spawn.mapRect(4000, -375, 25, 50); + + //blocks + spawn.bodyRect(150, -175, 50, 165, 0.2); //block at entrance + spawn.bodyRect(1275, 825, 100, 100, 0.2); + spawn.bodyRect(2600, -425, 150, 50, 0.2); + spawn.bodyRect(3900, -150, 50, 100, 0.2); + spawn.bodyRect(3350, 1950, 75, 100, 0.2); + spawn.bodyRect(3850, 1975, 75, 75, 0.2); + spawn.bodyRect(1600, 1950, 75, 100, 0.2); + spawn.bodyRect(725, -1650, 150, 100, 0.2); + spawn.bodyRect(800, -1700, 75, 50, 0.2); + + const spawnRightMobs = () => { + spawn.randomMob(4200, 100, 1); + spawn.randomMob(4200, 600, 1); + spawn.randomMob(2975, 625, 0.5); + spawn.randomMob(3050, 100, 0.5); + spawn.randomMob(3400, -100, 0.4); + spawn.randomMob(3825, -100, 0.4); + spawn.randomMob(3625, 1950, 0.4); + spawn.randomMob(3275, 1650, 0.4); + spawn.randomMob(3075, 1375, 0.3); + spawn.randomMob(4000, 1650, 0.1); + spawn.randomMob(4100, 1425, 0); + spawn.randomGroup(3025, 325, 1); + if (simulation.difficulty > 1) spawn.secondaryBossChance(3520, 1169) + } + + const spawnLeftMobs = () => { + spawn.randomMob(2375, 1900, 1); + spawn.randomMob(1825, 1325, 0.5); + spawn.randomMob(2250, 1050, 0.5); + spawn.randomMob(1675, 825, 0.4); + spawn.randomMob(1250, 575, 0.4); + spawn.randomMob(2400, 575, 0.4); + spawn.randomMob(1250, 1575, 0.3); + spawn.randomMob(1075, -100, 0.3); + spawn.randomMob(2450, -100, 0.2); + spawn.randomGroup(1350, -775, 1); + if (simulation.difficulty > 1) spawn.randomLevelBoss(1491, 495); + } + spawn.randomMob(2650, -750, 0.4); + spawn.randomMob(300, -1725, 0.4); + spawn.randomMob(750, -1775, 0.4); + spawn.randomMob(550, -2225, 0.4); + spawn.randomMob(2700, -475, 0.4); + spawn.randomMob(2375, -200, 0.2); + spawn.randomMob(3350, -225, 0.3); + + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + sewers() { + level.announceMobTypes() + const button1 = level.button(6600, 2675) + // const hazard = level.hazard(4550, 2750, 4550, 150) + const hazard = level.hazard(simulation.isHorizontalFlipped ? -4550 - 4550 : 4550, 2750, 4550, 150) + let balance1, balance2, balance3, balance4, rotor + + const drip1 = level.drip(6100, 1900, 2900, 100) // drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + const drip2 = level.drip(7300, 1900, 2900, 150) + const drip3 = level.drip(8750, 1900, 2900, 70) + level.custom = () => { + drip1.draw(); + drip2.draw(); + drip3.draw(); + button1.query(); + button1.draw(); + ctx.fillStyle = "hsl(175, 15%, 76%)" + ctx.fillRect(9100, 2200, 800, 400) + ctx.fillStyle = "rgba(0,0,0,0.03)" //shadows + ctx.fillRect(6250, 2025, 700, 650) + ctx.fillRect(8000, 2025, 600, 575) + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + rotor.rotate(); + + ctx.fillStyle = "#233" + ctx.beginPath(); + ctx.arc(balance1.center.x, balance1.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance2.center.x, balance2.center.y) + ctx.arc(balance2.center.x, balance2.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance3.center.x, balance3.center.y) + ctx.arc(balance3.center.x, balance3.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance4.center.x, balance4.center.y) + ctx.arc(balance4.center.x, balance4.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance5.center.x, balance5.center.y) + ctx.arc(balance5.center.x, balance5.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(rotor.center.x, rotor.center.y) + ctx.arc(rotor.center.x, rotor.center.y, 9, 0, 2 * Math.PI); + ctx.fill(); + hazard.query(); + hazard.level(button1.isUp) + }; + + level.setPosToSpawn(0, -50); //normal spawn + + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 9700; + level.exit.y = 2560; + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "hsl(138, 3%, 74%)"; + color.map = "#3d4240" + powerUps.spawnStartingPowerUps(3475, 1775); + spawn.debris(4575, 2550, 1600, 9); //16 debris per level + spawn.debris(7000, 2550, 2000, 7); //16 debris per level + + spawn.mapRect(-500, -600, 200, 800); //left entrance wall + spawn.mapRect(-400, -600, 3550, 200); //ceiling + spawn.mapRect(-400, 0, 3000, 200); //floor + // spawn.mapRect(300, -500, 50, 400); //right entrance wall + // spawn.bodyRect(312, -100, 25, 100); + spawn.bodyRect(1450, -300, 150, 50); + + const xPos = shuffle([600, 1250, 2000]); + spawn.mapRect(xPos[0], -200, 300, 100); + spawn.mapRect(xPos[1], -250, 300, 300); + spawn.mapRect(xPos[2], -150, 300, 200); + + spawn.bodyRect(3100, 410, 75, 100); + spawn.bodyRect(2450, -25, 250, 25); + + spawn.mapRect(3050, -600, 200, 800); //right down tube wall + spawn.mapRect(3100, 0, 1200, 200); //tube right exit ceiling + spawn.mapRect(4200, 0, 200, 1900); + spawn.mapVertex(3500, 1000, "-500 -500 -400 -600 400 -600 500 -500 500 500 400 600 -400 600 -500 500"); + spawn.mapVertex(3600, 1940, "-400 -40 -350 -90 350 -90 400 -40 400 40 350 90 -350 90 -400 40"); + spawn.mapRect(3925, 2288, 310, 50); + spawn.mapRect(3980, 2276, 200, 50); + + spawn.mapRect(2625, 2288, 650, 50); + spawn.mapRect(2700, 2276, 500, 50); + + spawn.mapRect(2400, 0, 200, 1925); //left down tube wall + spawn.mapRect(600, 2300, 3750, 200); + spawn.bodyRect(3800, 275, 125, 125); + + spawn.mapRect(4200, 1700, 5000, 200); + spawn.mapRect(4150, 2300, 200, 400); + + spawn.mapRect(600, 1700, 2000, 200); //bottom left room ceiling + spawn.mapRect(500, 1700, 200, 800); //left wall + spawn.mapRect(675, 1875, 325, 150, 0.5); + + spawn.mapRect(4450, 2900, 4900, 200); //boss room floor + spawn.mapRect(4150, 2600, 400, 500); + spawn.mapRect(6250, 2675, 700, 325); + spawn.mapRect(8000, 2600, 600, 400); + spawn.bodyRect(5875, 2725, 200, 200); + spawn.bodyRect(6800, 2490, 50, 50); + spawn.bodyRect(6800, 2540, 50, 50); + spawn.bodyRect(6800, 2590, 50, 50); + spawn.bodyRect(8225, 2225, 100, 100); + spawn.mapRect(6250, 1875, 700, 150); + spawn.mapRect(8000, 1875, 600, 150); + + spawn.mapRect(9100, 1700, 900, 500); //exit + spawn.mapRect(9100, 2600, 900, 500); + spawn.mapRect(9900, 1700, 200, 1400); //back wall + // spawn.mapRect(9300, 2150, 50, 250); + spawn.mapRect(9300, 2590, 650, 25); + spawn.mapRect(9700, 2580, 100, 50); + + + spawn.randomGroup(1300, 2100, 0.1); + spawn.randomMob(8300, 2100, 0.1); + spawn.randomSmallMob(2575, -75, 0.1); //entrance + spawn.randomMob(8125, 2450, 0.1); + spawn.randomSmallMob(3200, 250, 0.1); + spawn.randomMob(2425, 2150, 0.1); + spawn.randomSmallMob(3500, 250, 0.2); + spawn.randomMob(3800, 2175, 0.2); + spawn.randomSmallMob(2500, -275, 0.2); //entrance + spawn.randomMob(4450, 2500, 0.2); + spawn.randomMob(6350, 2525, 0.2); + spawn.randomGroup(9200, 2400, 0.3); + spawn.randomSmallMob(1900, -250, 0.3); //entrance + spawn.randomMob(1500, 2100, 0.4); + spawn.randomSmallMob(1700, -150, 0.4); //entrance + spawn.randomMob(8800, 2725, 0.5); + spawn.randomMob(7300, 2200, 0.5); + spawn.randomMob(2075, 2025, 0.5); + spawn.randomMob(3475, 2175, 0.5); + spawn.randomMob(8900, 2825, 0.5); + spawn.randomMob(9600, 2425, 0.9); + spawn.randomMob(3600, 1725, 0.9); + spawn.randomMob(4100, 1225, 0.9); + spawn.randomMob(2825, 400, 0.9); + if (simulation.difficulty > 1) spawn.randomLevelBoss(6000, 2300, ["dragonFlyBoss", "beetleBoss", "spiderBoss", "launcherBoss", "laserTargetingBoss", "blinkBoss", "streamBoss", "historyBoss", "orbitalBoss", "grenadierBoss", "blockBoss", "revolutionBoss", "slashBoss"]); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(7725, 2275) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + // rotor(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + // rotor = level.rotor(-5100, 2475, 0.001) //rotates other direction because flipped + rotor = level.rotor(-5600, 2390, 850, 50, 0.001, 0, 0.01, 0, 0.001) //balance(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + balance1 = level.rotor(-300 - 25, -395, 25, 390, 0.001) //entrance + balance2 = level.rotor(-2605 - 390, 500, 390, 25, 0.001) //falling + balance3 = level.rotor(-2608 - 584, 1900, 584, 25, 0.001) //falling + balance4 = level.rotor(-9300 - 25, 2205, 25, 380, 0.001) //exit + balance5 = level.rotor(-2605 - 390, 1100, 390, 25, 0.001) //falling + // boost1.boostBounds.min.x = -boost1.boostBounds.min.x - 100 + // boost1.boostBounds.max.x = -boost1.boostBounds.max.x + 100 + // level.setPosToSpawn(300, -700); //-x // no need since 0 + button1.min.x = -button1.min.x - 126 // flip the button horizontally + button1.max.x = -button1.max.x + 126 // flip the button horizontally + drip1.x *= -1 + drip2.x *= -1 + drip3.x *= -1 + level.custom = () => { + drip1.draw(); + drip2.draw(); + drip3.draw(); + + button1.query(); + button1.draw(); + rotor.rotate(); + + ctx.fillStyle = "hsl(175, 15%, 76%)" + ctx.fillRect(-9900, 2200, 800, 400) + ctx.fillStyle = "rgba(0,0,0,0.03)" //shadows + ctx.fillRect(-6950, 2025, 700, 650) + ctx.fillRect(-8600, 2025, 600, 575) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + // level.customTopLayer = () => {}; + } else { + // rotor = level.rotor(5100, 2475, -0.001) + rotor = level.rotor(4700, 2390, 850, 50, 0.001, 0, 0.01, 0, -0.001) //balance(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + balance1 = level.rotor(300, -395, 25, 390, 0.001) //entrance + balance2 = level.rotor(2605, 500, 390, 25, 0.001) //falling + balance3 = level.rotor(2608, 1900, 584, 25, 0.001) //falling + balance4 = level.rotor(9300, 2205, 25, 380, 0.001) //exit + balance5 = level.rotor(2605, 1100, 390, 25, 0.001) //falling + } + + }, + flocculation() { + level.announceMobTypes() + const button0 = level.button(1125, 795) + const button1 = level.button(6538, 2670) + const button2 = level.button(1225, -100) + button0.isUp = true + button1.isUp = true + button2.isUp = true + // const hazard = level.hazard(4550, 2750, 4550, 150) + const hazard = level.hazard(simulation.isHorizontalFlipped ? -7200 : 675, 50, 7500, 3000) //1869 + // hazard.min.y = 3000 //REMOVE THIS IN LIVE VERSION!!!!! set slime to lowest level + let balance1, balance2, balance3, rotor1, rotor2 + + const drip1 = level.drip(6100, 1900, 2900, 100) // drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + const drip2 = level.drip(7300, 1900, 2900, 150) + const drip3 = level.drip(8750, 1900, 2900, 70) + + //up mode triggered by player contact + const elevator0 = level.elevator(700, 1865, 200, 490, 1400, 0.011, { up: 0.01, down: 0.7 }) + const elevator1 = level.elevator(3995, 2335, 210, 150, 1700, 0.011, { up: 0.01, down: 0.7 }) + + level.custom = () => { + drip1.draw(); + drip2.draw(); + drip3.draw(); + if (button0.isUp) { + button0.query(); + if (!button0.isUp) { //summon second set of mobs + //1 boss, 1-2 groups, 11 mobs (all on lower ground level, where the slime is leaving) + spawn.randomMob(918, 2695, 0.1); + spawn.randomMob(1818, 2719, 0.2); + spawn.randomMob(2530, 2460, 0.2); + spawn.randomMob(3109, 2665, 0.3); + spawn.randomMob(3909, 2191, 0.3); + spawn.randomMob(4705, 2711, 0.4); + spawn.randomMob(5800, 2796, 0.5); + spawn.randomMob(7287, 2757, 0.6); + spawn.randomMob(5759, 2691, 0.9); + spawn.randomMob(5675, 2225, 0.8); + spawn.randomMob(7450, 2775, 0.8); + + spawn.randomGroup(6600, 2400, 0.1); + if (simulation.difficulty > 1) spawn.randomLevelBoss(6076, 2341); + } + } + button0.draw(); + if (button1.isUp) button1.query(); + button1.draw(); + if (button2.isUp) button2.query(); + button2.draw(); + ctx.fillStyle = "hsl(175, 15%, 76%)" + ctx.fillRect(7625, 2625, 400, 300) + ctx.fillStyle = "rgba(0,0,0,0.03)" //shadows + ctx.fillRect(6250, 1875, 700, 875) + ctx.fillRect(900, 1200, 600, 1725) //900, 1350, 600, 1600); + ctx.fillRect(3000, 1200, 1000, 1750); + ctx.fillRect(2200, 625, 400, 2050); + + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + elevator0.moveOnTouch() + elevator1.moveOnTouch() + rotor1.rotate(); + rotor2.rotate(); + + ctx.fillStyle = "#233" + ctx.beginPath(); + ctx.arc(balance1.center.x, balance1.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance2.center.x, balance2.center.y) + ctx.arc(balance2.center.x, balance2.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance3.center.x, balance3.center.y) + ctx.arc(balance3.center.x, balance3.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(balance5.center.x, balance5.center.y) + ctx.arc(balance5.center.x, balance5.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(rotor1.center.x, rotor1.center.y) + ctx.arc(rotor1.center.x, rotor1.center.y, 9, 0, 2 * Math.PI); + ctx.moveTo(rotor2.center.x, rotor2.center.y) + ctx.arc(rotor2.center.x, rotor2.center.y, 9, 0, 2 * Math.PI); + ctx.fill(); + hazard.query(); + const drainRate = Math.max(1, 4 - hazard.min.y / 800) + hazard.level( + (button2.isUp || hazard.height < 1150) && + (button0.isUp || hazard.height < 350) && + button1.isUp + , drainRate) //true = hold, false = lower + exitDoor.isClosing = hazard.min.y < 2900 + exitDoor.openClose(); + exitDoor.draw(); + }; + + level.setPosToSpawn(0, -50); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 7800; + level.exit.y = 2865; + const exitDoor = level.door(7637, 2680, 25, 225, 195, 5) + + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "hsl(138, 3%, 74%)"; + color.map = "#3d4240" + powerUps.spawnStartingPowerUps(3475, 1775); + spawn.debris(4575, 2550, 1600, 6); //16 debris per level + spawn.debris(750, 2550, 2250, 6); //16 debris per level + + spawn.mapRect(-500, -600, 200, 800); //left entrance wall + spawn.mapRect(-400, -600, 3550, 200); //ceiling + spawn.mapRect(-400, 0, 1400, 600); + + spawn.mapRect(575, 475, 250, 250); + Matter.Body.setAngle(map[map.length - 1], map[map.length - 1].angle - Math.PI / 4); + spawn.mapRect(4075, 75, 250, 250); + Matter.Body.setAngle(map[map.length - 1], map[map.length - 1].angle - Math.PI / 4); + spawn.mapRect(4259, 1559, 282.5, 282.5); + Matter.Body.setAngle(map[map.length - 1], map[map.length - 1].angle - Math.PI / 4); + + spawn.mapRect(3140, -600, 200, 800); //right down tube wall + spawn.mapRect(3150, 0, 1200, 200); //tube right exit ceiling + spawn.mapVertex(2400, 500, "-200 -100 -100 -200 100 -200 200 -100 200 200 -200 200"); + spawn.mapVertex(2400, 1200, "-200 -200 200 -200 200 100 100 200 -100 200 -200 100"); + spawn.mapVertex(1200, 2150, "-300 -300 300 -300 300 200 200 300 -200 300 -300 200"); + spawn.mapVertex(1200, 1100, "-300 -200 -200 -300 200 -300 300 -200 300 300 -300 300"); + spawn.mapVertex(3500, 950, "-500 -450 -400 -550 400 -550 500 -450 500 450 400 550 -400 550 -500 450"); + spawn.mapVertex(3500, 1990, "-300 -40 -230 -110 230 -110 300 -40 300 40 230 110 -230 110 -300 40"); + // spawn.mapVertex(2400, 1940, "-200 -40 -150 -90 150 -90 200 -40 200 40 150 90 -150 90 -200 40"); + spawn.mapRect(2200, 1850, 400, 200); + spawn.bodyRect(3825, 2240, 150, 75, 0.5); + + spawn.mapVertex(3500, 2452, "-500 -135 500 -135 500 35 400 135 -400 135 -500 35"); + spawn.mapVertex(1200, 2875, "-400 0 -300 -100 300 -100 400 0"); + spawn.mapVertex(1317, 275, "-500 0 -300 -200 300 -200 550 50 550 500 -500 500"); + spawn.mapVertex(1300, -357, "-300 0 -400 -100 400 -100 300 0"); + spawn.bodyRect(1550, -308, 50, 208, 0.5); + spawn.bodyRect(2000, 965, 525, 25, 0.5); + spawn.mapVertex(2400, 2850, "-350 -50 -300 -100 300 -100 350 -50 350 300 -350 300"); + spawn.mapVertex(6600, 1925, "-350 0 -450 -100 450 -100 350 0"); + spawn.mapVertex(6600, 2875, "-400 -50 -350 -100 350 -100 400 -50 400 300 -400 300"); + + spawn.bodyRect(2375, 300, 100, 100, 0.6); + spawn.bodyRect(1025, 1775, 100, 75, 0.6); + spawn.bodyRect(1250, 1825, 50, 25, 0.6); + spawn.bodyRect(3700, 275, 125, 125, 0.6); + spawn.bodyRect(5875, 2725, 200, 200, 0.6); + spawn.bodyRect(6900, 2590, 50, 50, 0.6); + spawn.mapRect(4200, 2325, 250, 625); + spawn.mapRect(-500, 50, 1200, 3050); + spawn.mapRect(-500, 2900, 9600, 775); + + spawn.mapRect(4400, 0, 4700, 1900); + spawn.mapRect(4200, 0, 200, 1700); + // spawn.mapRect(6250, 2675, 700, 325); + // spawn.mapRect(6250, 1875, 700, 150); + + //exit room + spawn.mapRect(8000, 1775, 1100, 1375); + spawn.mapRect(7625, 1825, 450, 825); + spawn.mapRect(7625, 2625, 50, 75); + spawn.mapRect(7625, 2890, 400, 25); + spawn.mapRect(7800, 2880, 100, 25); + + spawn.randomMob(2450, 250, 0.2); + spawn.randomMob(3250, 325, 0.2); + spawn.randomMob(3625, 350, 0.3); + spawn.randomMob(1750, -25, 0.4); + spawn.randomMob(1300, 1750, 0.5); + spawn.randomMob(2350, 1725, 0.6); + spawn.randomMob(3350, 1775, 0.7); + spawn.randomMob(1025, 750, 0.8); + spawn.randomMob(2400, 1775, 0.8); + spawn.randomMob(1250, 1725, 0.8); + spawn.randomMob(775, 1775, 0.9); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(1822, 1336) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + rotor1 = level.rotor(-5600, 2390, 850, 50, 0.001, 0, 0.01, 0, 0.001) //balance(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + rotor2 = level.rotor(-2175, 1900, 650, 50, 0.001, 0, 0.01, 0, 0.0007) + + balance1 = level.rotor(-800 - 25, -395, 25, 390, 0.001) //entrance + balance2 = level.rotor(-2605 - 390, 500, 390, 25, 0.001) //falling + balance3 = level.rotor(-2608 - 584, 1950, 584, 25, 0.001) //falling + balance5 = level.rotor(-2605 - 390, 1020, 390, 25, 0.001) //falling + + button1.min.x = -button1.min.x - 126 + button1.max.x = -button1.max.x + 126 + button0.min.x = -button0.min.x - 126 + button0.max.x = -button0.max.x + 126 + button2.min.x = -button2.min.x - 126 + button2.max.x = -button2.max.x + 126 // flip the button horizontally + drip1.x *= -1 + drip2.x *= -1 + drip3.x *= -1 + elevator0.holdX *= -1 + elevator1.holdX *= -1 + // console.log(hazard) + hazard.min.x -= 840 + hazard.max.x -= 840 + + level.custom = () => { + drip1.draw(); + drip2.draw(); + drip3.draw(); + + if (button0.isUp) { + button0.query(); + if (!button0.isUp) { //summon second set of mobs + //1 boss, 1-2 groups, 11 mobs (all on lower ground level, where the slime is leaving) + spawn.randomMob(-7475, 2800, 0.1); + spawn.randomMob(-6475, 2500, 0.2); + spawn.randomMob(-4575, 2775, 0.3); + spawn.randomMob(-7575, 2850, 0.3); + spawn.randomMob(-6425, 2575, 0.3); + spawn.randomMob(-5750, 2775, 0.4); + spawn.randomMob(-4675, 2800, 0.5); + spawn.randomMob(-3425, 2800, 0.6); + spawn.randomMob(-2475, 2475, 0.7); + spawn.randomMob(-3350, 2250, 0.8); + spawn.randomMob(-1275, 2725, 0.9); + spawn.randomGroup(-6225, 2400, 0.1); + if (simulation.difficulty > 1) spawn.randomLevelBoss(-6250, 2350); + } + } + button0.draw(); + if (button1.isUp) button1.query(); + button1.draw(); + if (button2.isUp) button2.query(); + button2.draw(); + rotor1.rotate(); + rotor2.rotate(); + ctx.fillStyle = "hsl(175, 15%, 76%)" + ctx.fillRect(-8025, 2625, 400, 300) + ctx.fillStyle = "rgba(0,0,0,0.03)" //shadows + ctx.fillRect(-6950, 1875, 700, 875) + ctx.fillRect(-4000, 1400, 1000, 1550); + ctx.fillRect(-2600, 675, 400, 2025); + ctx.fillRect(-1500, 1375, 600, 1500); + + level.exit.drawAndCheck(); + level.enter.draw(); + }; + // level.customTopLayer = () => {}; + } else { + rotor1 = level.rotor(4700, 2390, 850, 50, 0.001, 0, 0.01, 0, -0.001) //balance(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + rotor2 = level.rotor(1525, 1900, 650, 50, 0.001, 0, 0.01, 0, -0.0007) + balance1 = level.rotor(800, -395, 25, 390, 0.001) //entrance + balance2 = level.rotor(2605, 500, 390, 25, 0.001) //falling + balance3 = level.rotor(2608, 1950, 584, 25, 0.001) //falling + balance5 = level.rotor(2605, 1020, 390, 25, 0.001) //falling + } + + }, + satellite() { + level.announceMobTypes() + level.fallMode = "start"; + const boost1 = level.boost(5825, 235, 1400) + const elevator = level.elevator(4210, -1265, 380, 50, -3450) //, 0.003, { up: 0.01, down: 0.2 } + level.custom = () => { + boost1.query(); + + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(-250, -750, 420, 450) + ctx.fillStyle = "#d0d4d6" + ctx.fillRect(-300, -1900, 500, 1100) + ctx.fillRect(900, -2450, 450, 2050) + ctx.fillRect(2000, -2800, 450, 2500) + ctx.fillRect(3125, -3100, 450, 3300) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,20,40,0.25)" + ctx.fillRect(-250, -400, 1800, 775) + ctx.fillRect(1800, -275, 850, 775) + ctx.fillRect(5200, 125, 450, 200) + ctx.fillStyle = "rgba(0,20,40,0.1)" + ctx.fillRect(4000, -1200, 1050, 1500) + ctx.fillRect(4100, -3450, 600, 2250) + elevator.move() + }; + + level.setPosToSpawn(-100, 210); //normal spawn + spawn.mapRect(-150, 240, 100, 30); + level.exit.x = -100; + level.exit.y = -425; + spawn.mapRect(level.exit.x, level.exit.y + 15, 100, 50); //exit bump + + level.defaultZoom = 1700 // 4500 // 1400 + simulation.zoomTransition(level.defaultZoom) + + powerUps.spawnStartingPowerUps(4900, -500); //1 per level + spawn.debris(1000, 20, 1800, 6); //16 debris per level + // spawn.debris(4830, -1330, 850, 3); //16 debris per level + // spawn.debris(3035, -3900, 1500, 3); //16 debris per level + + document.body.style.backgroundColor = "#dbdcde"; + + //spawn start building + spawn.mapRect(-350, -800, 100, 1100); + // spawn.mapRect(-300, -10, 500, 50); + spawn.mapRect(150, -510, 50, 365); + spawn.bodyRect(170, -140, 20, 163, 1, spawn.propsFriction); //door to starting room + spawn.mapVertex(175, 200, "625 0 300 0 425 -300 500 -300"); //entrance ramp + // spawn.mapRect(-300, 0, 1000, 300); //ground + spawn.mapRect(-350, 250, 6350, 300); //deeper ground + spawn.bodyRect(2100, 50, 80, 80); + spawn.bodyRect(2000, 50, 60, 60); + // spawn.bodyRect(1650, 50, 300, 200); + // spawn.mapRect(1800, Math.floor(Math.random() * 200), 850, 300); //stops above body from moving to right + spawn.mapVertex(2225, 250, "575 0 -575 0 -450 -100 450 -100"); //base + + //exit building + // spawn.mapRect(-100, -410, 100, 30); + spawn.mapRect(-350, -850, 550, 100); + spawn.mapRect(150, -800, 50, 110); + spawn.bodyRect(170, -690, 14, 180, 1, spawn.propsFriction); //door to exit room + spawn.mapRect(-300, -400, 500, 150); //far left starting ceiling + + //tall platform above exit + spawn.mapRect(-500, -1900, 400, 50); //super high shade + spawn.mapRect(0, -1900, 400, 50); //super high shade + spawn.mapRect(-150, -1350, 200, 25); //super high shade + spawn.bodyRect(140, -2100, 150, 200); //shield from laser + + //tall platform + spawn.mapVertex(1125, -450, "325 0 250 80 -250 80 -325 0 -250 -80 250 -80"); //base + spawn.mapRect(150, -500, 1410, 100); //far left starting ceiling + spawn.mapRect(625, -2450, 1000, 50); //super high shade + spawn.bodyRect(1300, -3600, 150, 150); //shield from laser + //tall platform + spawn.mapVertex(2225, -250, "325 0 250 80 -250 80 -325 0 -250 -80 250 -80"); //base + spawn.mapRect(1725, -2800, 1000, 50); //super high shade + spawn.mapRect(1790, -300, 870, 100); //far left starting ceiling + spawn.bodyRect(2400, -2950, 150, 150); //shield from laser + + //tall platform + spawn.mapVertex(3350, 175, "425 0 -425 0 -275 -300 275 -300"); //base + spawn.bodyRect(3350, -150, 200, 120); + spawn.mapRect(2850, -3150, 1000, 50); //super high shade + spawn.bodyRect(3675, -3470, 525, 20); //plank + spawn.bodyRect(3600, -3450, 200, 300); //plank support block + + //far right structure + spawn.mapRect(5200, -725, 100, 870); + spawn.mapRect(5300, -1075, 350, 1220); + + //structure bellow tall stairs + spawn.mapRect(3900, -300, 450, 50); + spawn.mapRect(4675, -375, 450, 50); + + // spawn.mapRect(4000, -1300, 1050, 100); + spawn.mapRect(4000, -1300, 200, 100); + spawn.mapRect(4600, -1300, 450, 100); + + //steep stairs + spawn.mapRect(4100, -2250, 100, 650); + spawn.mapRect(4100, -3450, 100, 850); //left top shelf + spawn.mapRect(4600, -3450, 100, 1850); + + //steps up and down + spawn.mapVertex(4525, 250, "-650 0 -625 -20 625 -20 650 0"); + spawn.mapVertex(4525, 237, "-550 0 -525 -20 525 -20 550 0"); + // spawn.mapVertex(4525, 225, "-400 0 -375 -20 375 -20 400 0"); + + spawn.randomSmallMob(4400, -3500); + spawn.randomSmallMob(4800, -800); + spawn.randomMob(800, -2600); + spawn.randomMob(700, -600, 0.3); + spawn.randomMob(3100, -3600, 0.3); + spawn.randomMob(3300, -1000, 0.3); + spawn.randomMob(4200, -250, 0.3); + spawn.randomMob(4900, -1500, 0.3); + spawn.randomMob(3800, 175, 0.4); + spawn.randomMob(5750, 125, 0.4); + spawn.randomMob(5900, -1500, 0.4); + spawn.randomMob(4700, -800, 0.4); + spawn.randomMob(1400, 200, 0.3); + spawn.randomMob(2850, 175, 0.4); + spawn.randomMob(2000, -2800, 0.4); + spawn.randomMob(2400, -400, 0.4); + spawn.randomMob(4475, -3550, 0.3); + spawn.randomGroup(5000, -2150, 1); + spawn.randomGroup(3700, -4100, 0.3); + spawn.randomGroup(2700, -1600, 0.1); + spawn.randomGroup(1600, -100, 0); + spawn.randomGroup(5000, -3900, -0.3); + if (simulation.difficulty > 1) { + if (Math.random() < 0.25) { + spawn.randomLevelBoss(2800, -1400); + } else if (Math.random() < 0.25) { + spawn.laserBoss(2900 + 300 * Math.random(), -2950 + 150 * Math.random()); + } else if (Math.random() < 0.33) { + spawn.laserBoss(1800 + 250 * Math.random(), -2600 + 150 * Math.random()); + } else if (Math.random() < 0.5) { + spawn.laserBoss(3500 + 250 * Math.random(), -2600 + 1000 * Math.random()); + } else { + spawn.laserBoss(600 + 200 * Math.random(), -2150 + 250 * Math.random()); + } + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(3950, -850) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + boost1.boostBounds.min.x = -boost1.boostBounds.min.x - 100 + boost1.boostBounds.max.x = -boost1.boostBounds.max.x + 100 + level.setPosToSpawn(100, 210); //-x + elevator.holdX = -elevator.holdX // flip the elevator horizontally + level.custom = () => { + boost1.query(); + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(250 - 420, -750, 420, 450) + ctx.fillStyle = "#d0d4d6" + ctx.fillRect(300 - 500, -1900, 500, 1100) + ctx.fillRect(-900 - 450, -2450, 450, 2050) + ctx.fillRect(-2000 - 450, -2800, 450, 2500) + ctx.fillRect(-3125 - 450, -3100, 450, 3300) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + elevator.move() + ctx.fillStyle = "rgba(0,20,40,0.25)" + ctx.fillRect(250 - 1800, -400, 1800, 775) + ctx.fillRect(-1800 - 850, -275, 850, 775) + ctx.fillRect(-5200 - 450, 125, 450, 200) + ctx.fillStyle = "rgba(0,20,40,0.1)" + ctx.fillRect(-4000 - 1050, -1200, 1050, 1500) + ctx.fillRect(-4100 - 600, -3450, 600, 2250) + }; + } + }, + rooftops() { + level.announceMobTypes() + + // level.fallPosition = { x: 5000, y:-4000} + const elevator = level.elevator(1450, -990, 235, 45, -2000) + const boost1 = level.boost(4950, 0, 1100) + + level.custom = () => { + boost1.query(); + elevator.move(); + elevator.drawTrack(); + ctx.fillStyle = "#d4f4f4" + if (isBackwards) { + ctx.fillRect(-650, -2300, 440, 300) + } else { + ctx.fillRect(3460, -700, 1090, 800) + } + level.exit.drawAndCheck(); + level.enter.draw(); + }; + + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(710, -2225, 580, 225) + ctx.fillRect(3510, -1550, 330, 300) + ctx.fillRect(1735, -900, 1515, 1900) + ctx.fillRect(1735, -1550, 1405, 550) + ctx.fillRect(1860, -1950, 630, 350) + ctx.fillRect(-700, -1950, 2100, 2950) + ctx.fillRect(3400, 100, 2150, 900) + ctx.fillRect(4550, -725, 900, 725) + ctx.fillRect(3460, -1250, 1080, 550) + if (isBackwards) { + ctx.fillRect(3460, -700, 1090, 800) + } else { + ctx.fillRect(-650, -2300, 440, 300) + } + }; + + level.defaultZoom = 1700 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#dcdcde"; + + + + // level.fallMode = "start"; + let isBackwards = false + if (Math.random() < 0.75) { + //normal direction start in top left + level.setPosToSpawn(-450, -2060); + level.exit.x = 3600; + level.exit.y = -300; + spawn.mapRect(3600, -285, 100, 50); //ground bump wall + //mobs that spawn in exit room + spawn.bodyRect(4850, -750, 300, 25, 0.6); // + spawn.randomSmallMob(4100, -100); + spawn.randomSmallMob(4600, -100); + spawn.randomMob(3765, -450, 0.3); + } else { + isBackwards = true + //reverse direction, start in bottom right + level.setPosToSpawn(3650, -325); + level.exit.x = -550; + level.exit.y = -2030; + spawn.mapRect(-550, -2015, 100, 50); //ground bump wall + } + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + + spawn.debris(1650, -1800, 3800, 16); //16 debris per level + powerUps.spawnStartingPowerUps(2450, -1675); + + //spawn.mapRect(-700, 0, 6250, 100); //ground + spawn.mapRect(3400, 0, 2150, 100); //ground + spawn.mapRect(-700, -2000, 2125, 50); //Top left ledge + spawn.bodyRect(1300, -2125, 50, 125, 0.8); + spawn.bodyRect(1307, -2225, 50, 100, 0.8); + spawn.mapRect(-700, -2350, 50, 400); //far left starting left wall + spawn.mapRect(-700, -2010, 500, 50); //far left starting ground + spawn.mapRect(-700, -2350, 500, 50); //far left starting ceiling + spawn.mapRect(-250, -2350, 50, 200); //far left starting right part of wall + spawn.bodyRect(-240, -2150, 30, 36); //door to starting room + spawn.bodyRect(-240, -2115, 30, 36); //door to starting room + spawn.bodyRect(-240, -2080, 30, 35); //door to starting room + spawn.bodyRect(-240, -2045, 30, 35); //door to starting room + spawn.mapRect(1850, -2000, 650, 50); + spawn.bodyRect(200, -2150, 80, 220, 0.8); + spawn.mapRect(700, -2275, 600, 50); + spawn.mapRect(1000, -1350, 410, 50); + spawn.bodyRect(1050, -2350, 30, 30, 0.8); + // spawn.bodyRect(1625, -1100, 100, 75); + // spawn.bodyRect(1350, -1025, 400, 25); // ground plank + spawn.mapRect(-725, -1000, 2150, 100); //lower left ledge + spawn.bodyRect(350, -1100, 200, 100, 0.8); + spawn.bodyRect(370, -1200, 100, 100, 0.8); + spawn.bodyRect(360, -1300, 100, 100, 0.8); + spawn.bodyRect(950, -1050, 300, 50, 0.8); + spawn.bodyRect(-575, -1150, 125, 150, 0.8); + spawn.mapRect(1710, -1000, 1565, 100); //middle ledge + spawn.mapRect(3400, -1000, 75, 25); + spawn.bodyRect(2600, -1950, 100, 250, 0.8); + spawn.bodyRect(2700, -1125, 125, 125, 0.8); + spawn.bodyRect(2710, -1250, 125, 125, 0.8); + spawn.bodyRect(2705, -1350, 75, 100, 0.8); + spawn.mapRect(3500, -1600, 350, 50); + spawn.mapRect(1725, -1600, 1435, 50); + spawn.bodyRect(3100, -1015, 375, 15); + spawn.bodyRect(3500, -850, 75, 125, 0.8); + spawn.mapRect(3450, -1000, 50, 580); //left building wall + spawn.bodyRect(3460, -420, 30, 144); + spawn.mapRect(5450, -775, 100, 875); //right building wall + spawn.bodyRect(3925, -1400, 100, 150, 0.8); + spawn.mapRect(3450, -1250, 1090, 50); + // spawn.mapRect(3450, -1225, 50, 75); + spawn.mapRect(4500, -1250, 50, 415); + spawn.mapRect(3450, -725, 1500, 50); + spawn.mapRect(5100, -725, 400, 50); + spawn.mapRect(4500, -735, 50, 635); + spawn.bodyRect(4500, -100, 50, 100); + spawn.mapRect(4500, -885, 100, 50); + spawn.spawnStairs(3800, 0, 3, 150, 206); //stairs top exit + spawn.mapRect(3400, -275, 450, 275); //exit platform + + spawn.randomSmallMob(2200, -1775); + spawn.randomSmallMob(4000, -825); + spawn.randomSmallMob(-350, -3400); + spawn.randomMob(4250, -1350, 0.8); + spawn.randomMob(2550, -1350, 0.8); + spawn.randomMob(1875, -1075, 0.3); + spawn.randomMob(1120, -1200, 0.3); + spawn.randomMob(3000, -1150, 0.2); + spawn.randomMob(3200, -1150, 0.3); + spawn.randomMob(3300, -1750, 0.3); + spawn.randomMob(3650, -1350, 0.3); + spawn.randomMob(3600, -1800, 0.1); + spawn.randomMob(5200, -100, 0.3); + spawn.randomMob(5275, -900, 0.2); + spawn.randomMob(0, -1075, 0.3); + spawn.randomGroup(600, -1575, 0); + spawn.randomGroup(2225, -1325, 0.4); + spawn.randomGroup(4900, -1200, 0); + if (simulation.difficulty > 1) spawn.randomLevelBoss(3200, -1900); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(2175, -2425) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + + boost1.boostBounds.min.x = -boost1.boostBounds.min.x - 100 + boost1.boostBounds.max.x = -boost1.boostBounds.max.x + 100 + elevator.holdX = -elevator.holdX // flip the elevator horizontally + + if (isBackwards) { + level.setPosToSpawn(-3650, -325); //-x + } else { + level.setPosToSpawn(450, -2060); //-x + } + level.custom = () => { + boost1.query(); + elevator.move(); + elevator.drawTrack(); + + ctx.fillStyle = "#d4f4f4" + if (isBackwards) { + ctx.fillRect(650 - 440, -2300, 440, 300) + } else { + ctx.fillRect(-3460 - 1090, -700, 1090, 800) + } + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-710 - 580, -2225, 580, 225) + ctx.fillRect(-3510 - 330, -1550, 330, 300) + ctx.fillRect(-1735 - 1515, -900, 1515, 1900) + ctx.fillRect(-1735 - 1405, -1550, 1405, 550) + ctx.fillRect(-1860 - 630, -1950, 630, 350) + ctx.fillRect(700 - 2100, -1950, 2100, 2950) + ctx.fillRect(-3400 - 2150, 100, 2150, 900) + ctx.fillRect(-4550 - 900, -725, 900, 725) + ctx.fillRect(-3460 - 1080, -1250, 1080, 550) + if (isBackwards) { + ctx.fillRect(-3460 - 1090, -700, 1090, 800) + } else { + ctx.fillRect(650 - 440, -2300, 440, 300) + } + }; + } + level.fallMode = "position"; //must set level.fallModeBounds in this mode to prevent player getting stuck left or right + if (level.enter.x > level.exit.x) { + level.fallModeBounds = { left: level.exit.x, right: level.enter.x } //used with level.fallMode = "position"; + } else { + level.fallModeBounds = { left: level.enter.x, right: level.exit.x } //used with level.fallMode = "position"; + } + }, + aerie() { + level.announceMobTypes() + level.fallMode = "start"; + const boost1 = level.boost(-425, 100, 1400) + const boost2 = level.boost(5350, 275, 2850); + + level.custom = () => { + boost1.query(); + boost2.query(); + if (backwards) { + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(-275, -1275, 425, 300) + } else { + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(3750, -3650, 550, 400) + } + ctx.fillStyle = "#c7c7ca" + ctx.fillRect(4200, -2200, 100, 2600) + // ctx.fillStyle = "#c7c7ca" + ctx.fillRect(-100, -1000, 1450, 1400) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + if (backwards) { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(3750, -3650, 550, 400) + } else { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-275, -1275, 425, 300) + } + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(3700, -3150, 1100, 950) + ctx.fillRect(2000, -1110, 450, 1550) + + ctx.fillStyle = "rgba(0,0,0,0.04)" + ctx.beginPath() + ctx.moveTo(-100, -900) + ctx.lineTo(300, -900) + ctx.lineTo(150, 100) + ctx.lineTo(-100, 100) + + ctx.moveTo(600, -900) + ctx.lineTo(1350, -900) + ctx.lineTo(1350, 100) + ctx.lineTo(750, 100) + ctx.fill() + }; + + level.defaultZoom = 2100 + simulation.zoomTransition(level.defaultZoom) + + const backwards = (Math.random() < 0.25 && simulation.difficulty > 8) ? true : false; + if (backwards) { + level.setPosToSpawn(4000, -3300); //normal spawn + level.exit.x = -100; + level.exit.y = -1025; + } else { + level.setPosToSpawn(-50, -1050); //normal spawn + level.exit.x = 3950; + level.exit.y = -3275; + } + + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + spawn.mapRect(level.exit.x, level.exit.y + 15, 100, 20); + + powerUps.spawnStartingPowerUps(1075, -550); + document.body.style.backgroundColor = "#dcdcde"; + + // starting room + spawn.mapRect(-300, -1000, 600, 100); + spawn.mapRect(-300, -1300, 450, 50); + spawn.mapRect(-300, -1300, 50, 350); + if (!backwards) spawn.bodyRect(100, -1250, 200, 240); //remove on backwards + //left building + spawn.mapRect(-100, -975, 100, 975); + spawn.mapRect(-500, 100, 1950, 400); + spawn.mapRect(600, -1000, 750, 100); + spawn.mapRect(900, -500, 550, 100); + spawn.mapRect(1250, -975, 100, 375); + spawn.bodyRect(1250, -600, 100, 100, 0.7); + spawn.mapRect(1250, -450, 100, 450); + spawn.bodyRect(1250, -1225, 100, 200, 0.7); //remove on backwards + spawn.bodyRect(1200, -1025, 350, 35); //remove on backwards + //middle super tower + if (backwards) { + spawn.bodyRect(2000, -800, 700, 35); + } else { + spawn.bodyRect(1750, -800, 700, 35); + } + spawn.mapVertex(2225, -2100, "0 0 450 0 300 -2500 150 -2500") + spawn.mapRect(2000, -700, 450, 300); + spawn.bodyRect(2360, -450, 100, 300, 0.6); + spawn.mapRect(2000, -75, 450, 275); + spawn.bodyRect(2450, 150, 150, 150, 0.4); + spawn.mapRect(1550, 300, 4600, 200); //ground + // spawn.mapRect(6050, -700, 450, 1200); + spawn.mapRect(6050, -1060, 450, 1560); + spawn.mapVertex(6275, -2100, "0 0 450 0 300 -2500 150 -2500") + + //right tall tower + spawn.mapRect(3700, -3200, 100, 800); + spawn.mapRect(4700, -2910, 100, 510); + spawn.mapRect(3700, -2600, 300, 50); + spawn.mapRect(4100, -2900, 900, 50); + spawn.mapRect(3450, -2300, 750, 100); + spawn.mapRect(4300, -2300, 750, 100); + spawn.mapRect(4150, -1600, 200, 25); + spawn.mapRect(4150, -700, 200, 25); + //exit room on top of tower + spawn.mapRect(3700, -3700, 600, 50); + spawn.mapRect(3700, -3700, 50, 500); + spawn.mapRect(4250, -3700, 50, 300); + spawn.mapRect(3700, -3250, 1100, 100); + + spawn.randomGroup(350, -500, 1) + spawn.randomSmallMob(-225, 25); + spawn.randomSmallMob(2100, -900); + + spawn.randomSmallMob(4000, -250); + spawn.randomSmallMob(4450, -3000); + spawn.randomSmallMob(5600, 100); + spawn.randomMob(4275, -2600, 0.8); + spawn.randomMob(1050, -700, 0.8) + spawn.randomMob(6050, -850, 0.7); + spawn.randomMob(2150, -300, 0.6) + spawn.randomMob(3900, -2700, 0.8); + spawn.randomMob(3600, -500, 0.8); + spawn.randomMob(3400, -200, 0.8); + // spawn.randomMob(1650, -1300, 0.7) + spawn.randomMob(425, 0, 0.7); + spawn.randomMob(4100, -50, 0.7); + spawn.randomMob(4100, -50, 0.5); + spawn.randomMob(1700, -50, 0.3) + spawn.randomMob(2350, -900, 0.3) + spawn.randomMob(4700, -150, 0.2); + spawn.randomGroup(4000, -350, 0.6); + spawn.randomGroup(2750, -550, 0.1); + spawn.randomMob(2175, -925, 0.5); + spawn.randomMob(2750, 100, 0.5); + spawn.randomMob(4250, -1725, 0.5); + spawn.randomMob(3575, -2425, 0.5); + spawn.randomMob(3975, -3900, 0.5); + spawn.randomMob(1725, 125, 0.5); + if (simulation.difficulty > 1) { + if (Math.random() < 0.5) { + spawn.randomLevelBoss(4250, -250); + spawn.debris(-250, 50, 1650, 2); //16 debris per level + spawn.debris(2475, 0, 750, 2); //16 debris per level + spawn.debris(3450, 0, 2000, 16); //16 debris per level + spawn.debris(3500, -2350, 1500, 2); //16 debris per level + } else { + powerUps.chooseRandomPowerUp(4000, 200); + powerUps.chooseRandomPowerUp(4000, 200); + //floor below right tall tower + spawn.bodyRect(3000, 50, 150, 250, 0.9); + spawn.bodyRect(4500, -500, 300, 250, 0.7); + spawn.bodyRect(3500, -100, 100, 150, 0.7); + spawn.bodyRect(4200, -500, 110, 30, 0.7); + spawn.bodyRect(3800, -500, 150, 130, 0.7); + spawn.bodyRect(4000, 50, 200, 150, 0.9); + spawn.bodyRect(4500, 50, 300, 200, 0.9); + spawn.bodyRect(4200, -350, 200, 50, 0.9); + spawn.bodyRect(4700, -350, 50, 200, 0.9); + spawn.bodyRect(4900, -100, 300, 300, 0.7); + spawn.suckerBoss(4500, -400); + } + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(5350, -325) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + + boost1.boostBounds.min.x = -boost1.boostBounds.min.x - 100 + boost1.boostBounds.max.x = -boost1.boostBounds.max.x + 100 + boost2.boostBounds.min.x = -boost2.boostBounds.min.x - 100 + boost2.boostBounds.max.x = -boost2.boostBounds.max.x + 100 + + + if (backwards) { + level.setPosToSpawn(-4000, -3300); //-x + } else { + level.setPosToSpawn(50, -1050); //-x + } + level.custom = () => { + boost1.query(); + boost2.query(); + if (backwards) { + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(275 - 425, -1275, 425, 300) + } else { + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(-3750 - 550, -3650, 550, 400) + } + ctx.fillStyle = "#c7c7ca" + ctx.fillRect(-4200 - 100, -2200, 100, 2600) + // ctx.fillStyle = "#c7c7ca" + ctx.fillRect(100 - 1450, -1000, 1450, 1400) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + if (backwards) { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-3750 - 550, -3650, 550, 400) + } else { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(275 - 425, -1275, 425, 300) + } + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-3700 - 1100, -3150, 1100, 950) + ctx.fillRect(-2000 - 450, -1110, 450, 1550) + ctx.fillStyle = "rgba(0,0,0,0.04)" + ctx.beginPath() + ctx.moveTo(100, -900) + ctx.lineTo(-300, -900) + ctx.lineTo(-150, 100) + ctx.lineTo(100, 100) + ctx.moveTo(-600, -900) + ctx.lineTo(-1350, -900) + ctx.lineTo(-1350, 100) + ctx.lineTo(-750, 100) + ctx.fill() + }; + } + }, + skyscrapers() { + level.announceMobTypes() + level.fallMode = "start"; + const boost1 = level.boost(475, 0, 1300) + const boost2 = level.boost(4450, 0, 1300); + level.custom = () => { + boost1.query(); + boost2.query(); + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(1350, -2100, 400, 250) + ctx.fillStyle = "#d4d4d7" + ctx.fillRect(3350, -1300, 50, 1325) + ctx.fillRect(1300, -1800, 750, 1800) + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(2500, -1100, 450, 250) + ctx.fillRect(2400, -550, 600, 150) + ctx.fillRect(2550, -1650, 250, 200) + ctx.fillStyle = "rgba(0,0,0,0.2)" + ctx.fillRect(700, -110, 400, 110) + ctx.fillRect(3800, -110, 400, 110) + ctx.fillStyle = "rgba(0,0,0,0.15)" + ctx.fillRect(-250, -300, 450, 300) + }; + level.setPosToSpawn(-50, -60); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 1500; + level.exit.y = -1875; + level.defaultZoom = 2000 + simulation.zoomTransition(level.defaultZoom) + powerUps.spawnStartingPowerUps(1475, -1175); + spawn.debris(750, -2200, 3700, 16); //16 debris per level + document.body.style.backgroundColor = "#dcdcde"; + + spawn.mapRect(-300, 0, 5100, 300); //***********ground + spawn.mapRect(-300, -350, 50, 400); //far left starting left wall + spawn.mapRect(-300, -10, 500, 50); //far left starting ground + spawn.mapRect(-300, -350, 500, 50); //far left starting ceiling + spawn.mapRect(150, -350, 50, 200); //far left starting right part of wall + spawn.bodyRect(170, -130, 14, 140, 1, spawn.propsFriction); //door to starting room + spawn.mapRect(700, -1100, 400, 990); //far left building + spawn.mapRect(1600, -400, 1500, 500); //long center building + spawn.mapRect(1345, -1100, 250, 25); //left platform + spawn.mapRect(1755, -1100, 250, 25); //right platform + spawn.mapRect(1300, -1850, 800, 50); //left higher platform + spawn.mapRect(1300, -2150, 50, 350); //left higher platform left edge wall + spawn.mapRect(1300, -2150, 450, 50); //left higher platform roof + spawn.mapRect(1500, -1860, 100, 50); //ground bump wall + spawn.mapRect(2400, -850, 600, 300); //center floating large square + //spawn.bodyRect(2500, -1100, 25, 250); //wall before chasers + spawn.mapRect(2500, -1450, 450, 350); //higher center floating large square + spawn.mapRect(2500, -1675, 50, 300); //left wall on higher center floating large square + spawn.mapRect(2500, -1700, 300, 50); //roof on higher center floating large square + spawn.mapRect(3275, -750, 200, 25); //ledge by far right building + spawn.mapRect(3275, -1300, 200, 25); //higher ledge by far right building + spawn.mapRect(3800, -1100, 400, 990); //far right building + + spawn.bodyRect(3200, -1375, 300, 25, 0.9); + spawn.bodyRect(1825, -1875, 400, 25, 0.9); + // spawn.bodyRect(1800, -575, 250, 150, 0.8); + spawn.bodyRect(1800, -600, 110, 150, 0.8); + spawn.bodyRect(2557, -450, 35, 55, 0.7); + spawn.bodyRect(2957, -450, 30, 15, 0.7); + spawn.bodyRect(2900, -450, 60, 45, 0.7); + spawn.bodyRect(915, -1200, 60, 100, 0.95); + spawn.bodyRect(925, -1300, 50, 100, 0.95); + if (Math.random() < 0.9) { + spawn.bodyRect(2300, -1720, 400, 20); + spawn.bodyRect(2590, -1780, 80, 80); + } + spawn.bodyRect(2925, -1100, 25, 250, 0.8); + spawn.bodyRect(3325, -1550, 50, 200, 0.3); + if (Math.random() < 0.8) { + spawn.bodyRect(1400, -75, 200, 75); //block to get up ledge from ground + spawn.bodyRect(1525, -125, 50, 50); //block to get up ledge from ground + } + spawn.bodyRect(1025, -1110, 400, 25, 0.9); //block on far left building + spawn.bodyRect(1425, -1110, 115, 25, 0.9); //block on far left building + spawn.bodyRect(1540, -1110, 300, 25, 0.9); //block on far left building + + spawn.randomMob(-100, -1300, 0.5); + spawn.randomSmallMob(1850, -600); + spawn.randomSmallMob(3200, -100); + spawn.randomSmallMob(4450, -100); + spawn.randomSmallMob(2700, -475); + spawn.randomMob(2650, -975, 0.8); + spawn.randomMob(2650, -1550, 0.8); + spawn.randomMob(4150, -200, 0.15); + spawn.randomMob(1700, -1300, 0.2); + spawn.randomMob(1850, -1950, 0.25); + spawn.randomMob(2610, -1880, 0.25); + spawn.randomMob(3350, -950, 0.25); + spawn.randomMob(1690, -2250, 0.25); + spawn.randomMob(2200, -600, 0.2); + spawn.randomMob(850, -1300, 0.25); + spawn.randomMob(-100, -1700, -0.2); + spawn.randomGroup(3700, -1500, 0.4); + spawn.randomGroup(1700, -900, 0.4); + if (simulation.difficulty > 1) spawn.randomLevelBoss(2800 + 200 * Math.random(), -2200 + 200 * Math.random()); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(4000, -1825) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + boost1.boostBounds.min.x = -boost1.boostBounds.min.x - 100 + boost1.boostBounds.max.x = -boost1.boostBounds.max.x + 100 + boost2.boostBounds.min.x = -boost2.boostBounds.min.x - 100 + boost2.boostBounds.max.x = -boost2.boostBounds.max.x + 100 + + level.setPosToSpawn(50, -60); //-x + level.custom = () => { + boost1.query(); + boost2.query(); + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(-1350 - 400, -2100, 400, 250) + ctx.fillStyle = "#d4d4d7" + ctx.fillRect(-3350 - 50, -1300, 50, 1325) + ctx.fillRect(-1300 - 750, -1800, 750, 1800) + + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-2500 - 450, -1100, 450, 250) + ctx.fillRect(-2400 - 600, -550, 600, 150) + ctx.fillRect(-2550 - 250, -1650, 250, 200) + ctx.fillStyle = "rgba(0,0,0,0.2)" + ctx.fillRect(-700 - 400, -110, 400, 110) + ctx.fillRect(-3800 - 400, -110, 400, 110) + ctx.fillStyle = "rgba(0,0,0,0.15)" + ctx.fillRect(250 - 450, -300, 450, 300) + }; + } + }, + highrise() { + level.announceMobTypes() + level.fallMode = "start"; + const elevator1 = level.elevator(-790, -190, 180, 25, -1150, 0.0025, { up: 0.01, down: 0.2 }, true) //x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + elevator1.addConstraint(); + // const button1 = level.button(-500, -200) + const toggle1 = level.toggle(-300, -200) //(x,y,isOn,isLockOn = true/false) + + const elevator2 = level.elevator(-3630, -970, 180, 25, -1740, 0.004) //x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + elevator2.addConstraint(); + // const button2 = level.button(-3100, -1330) + const toggle2 = level.toggle(-3100, -1330) //(x,y,isOn, isLockOn = true/false) + + + level.custom = () => { + // ctx.fillStyle = "#d0d0d2" + // ctx.fillRect(-2475, -2450, 25, 750) + // ctx.fillRect(-2975, -2750, 25, 600) + // ctx.fillRect(-3375, -2875, 25, 725) + ctx.fillStyle = "#cff" //exit + ctx.fillRect(-4425, -3050, 425, 275) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + // button1.draw(); + toggle1.query(); + if (!toggle1.isOn) { + if (elevator1.isOn) { + elevator1.isOn = false + elevator1.frictionAir = 0.2 + elevator1.addConstraint(); + } + } else if (!elevator1.isOn) { + elevator1.isOn = true + elevator1.isUp = false + elevator1.removeConstraint(); + elevator1.frictionAir = 0.2 //elevator.isUp ? 0.01 : 0.2 + } + if (elevator1.isOn) { + elevator1.move(); + ctx.fillStyle = "#444" + } else { + ctx.fillStyle = "#aaa" + } + ctx.fillRect(-700, -1140, 1, 975) + + toggle2.query(); + // button2.draw(); + if (!toggle2.isOn) { + if (elevator2.isOn) { + elevator2.isOn = false + elevator2.frictionAir = 0.2 + elevator2.addConstraint(); + } + } else if (!elevator2.isOn) { + elevator2.isOn = true + elevator2.isUp = false + elevator2.removeConstraint(); + elevator2.frictionAir = 0.2 //elevator.isUp ? 0.01 : 0.2 + } + + if (elevator2.isOn) { + elevator2.move(); + ctx.fillStyle = "#444" + } else { + ctx.fillStyle = "#aaa" + } + ctx.fillRect(-3540, -1720, 1, 770) + + ctx.fillStyle = "rgba(64,64,64,0.97)" //hidden section + ctx.fillRect(-4450, -750, 800, 200) + ctx.fillStyle = "rgba(0,0,0,0.12)" + ctx.fillRect(-2500, -1975, 150, 300); + ctx.fillRect(-1830, -1150, 2030, 1150) + ctx.fillRect(-3410, -2150, 495, 1550) + ctx.fillRect(-2585, -1675, 420, 1125) + ctx.fillRect(-1650, -1575, 750, 450) + }; + + level.setPosToSpawn(-300, -700); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = -4275; + level.exit.y = -2805; + + level.defaultZoom = 1500 + simulation.zoomTransition(level.defaultZoom) + + powerUps.spawnStartingPowerUps(-2550, -700); + document.body.style.backgroundColor = "#dcdcde" //"#fafcff"; + + spawn.debris(-2325, -1825, 2400); //16 debris per level + spawn.debris(-2625, -600, 600, 5); //16 debris per level + spawn.debris(-2000, -60, 1200, 5); //16 debris per level + + //3 platforms that lead to exit + // spawn.mapRect(-3440, -2875, 155, 25); + // spawn.mapRect(-3025, -2775, 125, 25); + // spawn.mapRect(-2525, -2475, 125, 25); + // spawn.bodyRect(-2600, -2500, 225, 20, 0.7); + // spawn.bodyRect(-3350, -2900, 25, 25, 0.5); + // spawn.bodyRect(-3400, -2950, 50, 75, 0.5); + + powerUps.spawn(-4300, -700, "heal"); + powerUps.spawn(-4200, -700, "ammo"); + powerUps.spawn(-4000, -700, "ammo"); + spawn.mapRect(-4450, -1000, 100, 500); + spawn.bodyRect(-3300, -750, 150, 150); + + //building 1 + spawn.bodyRect(-1000, -675, 25, 25); + spawn.mapRect(-2225, 0, 2475, 150); + spawn.mapRect(175, -1000, 75, 1100); + spawn.mapRect(-600, -1075, 50, 475); + spawn.mapRect(-600, -650, 625, 50); + spawn.mapRect(-1300, -650, 500, 50); + spawn.bodyRect(-75, -300, 50, 50); + + spawn.mapRect(-600, -200, 500, 250); //ledge for boarding elevator + spawn.bodyRect(-500, -300, 100, 100, 0.6); //a nice block near the elevator + + spawn.bodyRect(-425, -1375, 400, 225); + spawn.mapRect(-925, -1575, 50, 475); + spawn.bodyRect(-1475, -1275, 250, 125); + + // spawn.mapRect(-1650, -1575, 600, 50); + // spawn.mapRect(-1875, -1575, 850, 50); + spawn.mapRect(-1675, -1575, 650, 50); + spawn.mapRect(-600, -1150, 850, 175); + spawn.mapRect(-1850, -1150, 1050, 175); + spawn.bodyRect(-1907, -1600, 550, 25); + if (simulation.difficulty < 4) { + spawn.bodyRect(-1600, -125, 125, 125); + spawn.bodyRect(-1560, -200, 75, 75); + } else { + spawn.bodyRect(-1200, -125, 125, 125); + spawn.bodyRect(-1160, -200, 75, 75); + } + //building 2 + spawn.mapRect(-4450, -600, 2300, 750); + spawn.mapRect(-2225, -450, 175, 550); + // spawn.mapRect(-2600, -975, 450, 50); + spawn.mapRect(-3425, -1325, 525, 75); + spawn.mapRect(-3425, -2200, 525, 50); + spawn.mapRect(-2600, -1700, 450, 50); + // spawn.mapRect(-2600, -2450, 450, 50); + spawn.bodyRect(-2275, -2700, 50, 60); + + // spawn.bodyRect(-2560, -1925, 250, 225); + // spawn.mapRect(-2525, -2025, 125, 25); + // spawn.mapRect(-2525, -1900, 125, 225); + // spawn.mapRect(-2600, -1975, 250, 25); + spawn.mapRect(-2515, -2000, 180, 50); + + spawn.bodyRect(-3410, -1425, 50, 50); + spawn.bodyRect(-3390, -1525, 40, 60); + // spawn.bodyRect(-3245, -1425, 100, 100); + //building 3 + spawn.mapRect(-4450, -1750, 800, 1050); + // spawn.mapRect(-3850, -2000, 125, 400); + spawn.mapRect(-4000, -2390, 200, 800); + // spawn.mapRect(-4450, -2650, 475, 1000); + spawn.mapRect(-4450, -2775, 475, 1125); + spawn.bodyRect(-3715, -2050, 50, 50); + // spawn.bodyRect(-3570, -1800, 50, 50); + spawn.bodyRect(-2970, -2250, 50, 50); + spawn.bodyRect(-3080, -2250, 40, 40); + spawn.bodyRect(-3420, -650, 50, 50); + + //exit + spawn.mapRect(-4450, -3075, 25, 300); + spawn.mapRect(-4450, -3075, 450, 25); + spawn.mapRect(-4025, -3075, 25, 100); + spawn.mapRect(-4275, -2785, 100, 25); + spawn.bodyRect(-3900, -2400, 50, 50); + + //mobs + spawn.randomMob(-2500, -2700, 1); + spawn.randomMob(-3200, -750, 1); + spawn.randomMob(-1875, -775, 0.2); + spawn.randomMob(-950, -1675, 0.2); + spawn.randomMob(-1525, -1750, 0.2); + spawn.randomMob(-1375, -1400, 0.2); + spawn.randomMob(-1625, -1275, 0.2); + spawn.randomMob(-1900, -1250, 0.2); + spawn.randomMob(-2250, -1850, 0.2); + spawn.randomMob(-2475, -2200, 0.2); + spawn.randomMob(-3000, -1475, 0.2); + spawn.randomMob(-3850, -2500, 0.2); + spawn.randomMob(-3650, -2125, 0.2); + spawn.randomMob(-4010, -3200, 0.2); + spawn.randomMob(-3500, -1825, 0.2); + spawn.randomMob(-975, -100, 0); + spawn.randomMob(-1050, -725, 0.2); + spawn.randomMob(-1525, -100, 0); + spawn.randomMob(-525, -1700, -0.1); + spawn.randomMob(-125, -1500, -0.1); + spawn.randomMob(-325, -1900, -0.1); + spawn.randomMob(-550, -100, -0.1); + spawn.randomGroup(-3250, -2700, 0.2); + spawn.randomGroup(-2450, -1100, 0); + + if (simulation.difficulty > 1) spawn.randomLevelBoss(-2400, -2650); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(-1825, -1975) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + // boost1.boostBounds.min.x = -boost1.boostBounds.min.x - 100 + // boost1.boostBounds.max.x = -boost1.boostBounds.max.x + 100 + level.setPosToSpawn(300, -700); //-x + elevator1.holdX = -elevator1.holdX // flip the elevator horizontally + elevator1.removeConstraint(); + elevator1.addConstraint(); + elevator2.holdX = -elevator2.holdX // flip the elevator horizontally + elevator2.removeConstraint(); + elevator2.addConstraint(); + + level.custom = () => { + ctx.fillStyle = "#cff" //exit + ctx.fillRect(4425 - 425, -3050, 425, 275) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + toggle1.query(); + if (!toggle1.isOn) { + if (elevator1.isOn) { + elevator1.isOn = false + elevator1.frictionAir = 0.2 + elevator1.addConstraint(); + } + } else if (!elevator1.isOn) { + elevator1.isOn = true + elevator1.isUp = false + elevator1.removeConstraint(); + elevator1.frictionAir = 0.2 //elevator.isUp ? 0.01 : 0.2 + } + if (elevator1.isOn) { + elevator1.move(); + ctx.fillStyle = "#444" + ctx.fillRect(700 - 1, -1140, 1, 975) + } else { + ctx.fillStyle = "#aaa" + ctx.fillRect(700 - 1, -1140, 1, 975) + } + + toggle2.query(); + if (!toggle2.isOn) { + if (elevator2.isOn) { + elevator2.isOn = false + elevator2.frictionAir = 0.2 + elevator2.addConstraint(); + } + } else if (!elevator2.isOn) { + elevator2.isOn = true + elevator2.isUp = false + elevator2.removeConstraint(); + elevator2.frictionAir = 0.2 //elevator.isUp ? 0.01 : 0.2 + } + + if (elevator2.isOn) { + elevator2.move(); + ctx.fillStyle = "#444" + ctx.fillRect(3540 - 1, -1720, 1, 740) + } else { + ctx.fillStyle = "#aaa" + ctx.fillRect(3540 - 1, -1720, 1, 740) + } + + ctx.fillStyle = "rgba(64,64,64,0.97)" //hidden section + ctx.fillRect(4450 - 800, -750, 800, 200) + ctx.fillStyle = "rgba(0,0,0,0.12)" + ctx.fillRect(2500 - 150, -1975, 150, 300); + ctx.fillRect(1830 - 2030, -1150, 2030, 1150) + ctx.fillRect(3410 - 495, -2150, 495, 1550) + ctx.fillRect(2585 - 420, -1675, 420, 1125) + ctx.fillRect(1650 - 750, -1575, 750, 450) + }; + } + }, + warehouse() { + level.announceMobTypes() + level.fallMode = "start"; + level.custom = () => { + ctx.fillStyle = "#444" //light fixtures + ctx.fillRect(-920, -505, 40, 10) + ctx.fillRect(-920, 95, 40, 10) + ctx.fillRect(180, 95, 40, 10) + ctx.fillRect(-20, 695, 40, 10) + ctx.fillRect(-2320, 945, 40, 10) + + ctx.fillStyle = "#cff" //exit + ctx.fillRect(300, -250, 350, 250) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + + const lightingPath = new Path2D() //pre-draw the complex lighting path to save processing + lightingPath.moveTo(-1800, -500) + lightingPath.lineTo(-910, -500) //3rd floor light + lightingPath.lineTo(-1300, 0) + lightingPath.lineTo(-500, 0) + lightingPath.lineTo(-890, -500) + lightingPath.lineTo(-175, -500) + lightingPath.lineTo(-175, -250) + lightingPath.lineTo(175, -250) + lightingPath.lineTo(175, 0) + lightingPath.lineTo(-910, 100) //2nd floor light left + lightingPath.lineTo(-1300, 600) + lightingPath.lineTo(-500, 600) + lightingPath.lineTo(-890, 100) + lightingPath.lineTo(190, 100) //2nd floor light right + lightingPath.lineTo(-200, 600) + lightingPath.lineTo(600, 600) + lightingPath.lineTo(210, 100) + lightingPath.lineTo(1100, 100) + lightingPath.lineTo(1100, 1400) + lightingPath.lineTo(600, 1400) //1st floor light right + lightingPath.lineTo(10, 700) + lightingPath.lineTo(-10, 700) + lightingPath.lineTo(-600, 1400) + lightingPath.lineTo(-1950, 1400) //1st floor light left + lightingPath.lineTo(-2290, 950) + lightingPath.lineTo(-2310, 950) + lightingPath.lineTo(-2650, 1400) + lightingPath.lineTo(-3025, 1400) + lightingPath.lineTo(-3025, 150) + lightingPath.lineTo(-2590, 150) + lightingPath.lineTo(-2600, -150) + lightingPath.lineTo(-1800, -150) + lightingPath.lineTo(-1800, -500) //top left end/start of path + + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.15)"; //shadows and lights + ctx.fill(lightingPath); + }; + + level.setPosToSpawn(25, -55); //normal spawn + level.exit.x = 425; + level.exit.y = -30; + + level.defaultZoom = 1300 + simulation.zoomTransition(level.defaultZoom) + + spawn.debris(-2250, 1330, 3000, 6); //16 debris per level + spawn.debris(-3000, -800, 3280, 6); //16 debris per level + spawn.debris(-1400, 410, 2300, 5); //16 debris per level + powerUps.spawnStartingPowerUps(25, 500); + document.body.style.backgroundColor = "#dcdcde" //"#f2f5f3"; + + spawn.mapRect(-1500, 0, 2750, 100); + spawn.mapRect(175, -270, 125, 300); + spawn.mapRect(-1900, -600, 1775, 100); + spawn.mapRect(-1900, -550, 100, 1250); + //house + spawn.mapRect(-225, -550, 100, 400); + spawn.mapRect(-225, -10, 400, 50); + spawn.mapRect(-25, -20, 100, 50); + + //exit house + spawn.mapRect(300, -10, 350, 50); + spawn.mapRect(-150, -350, 800, 100); + spawn.mapRect(600, -275, 50, 75); + spawn.mapRect(425, -20, 100, 25); + // spawn.mapRect(-1900, 600, 2700, 100); + spawn.mapRect(1100, 0, 150, 1500); + spawn.mapRect(-3150, 1400, 4400, 100); + spawn.mapRect(-2375, 875, 1775, 75); + spawn.mapRect(-1450, 865, 75, 435); + spawn.mapRect(-1450, 662, 75, 100); + spawn.bodyRect(-1418, 773, 11, 102, 1, spawn.propsFriction); //blocking path + spawn.mapRect(-3150, 50, 125, 1450); + spawn.mapRect(-2350, 600, 3150, 100); + spawn.mapRect(-2125, 400, 250, 275); + // spawn.mapRect(-1950, -400, 100, 25); + spawn.mapRect(-3150, 50, 775, 100); + spawn.mapRect(-2600, -250, 775, 100); + + let isElevators = false + let elevator1, elevator2, elevator3 + if (Math.random() < 0.5) { + isElevators = true + elevator1 = level.elevator(-1780, 500, 260, 40, 7, 0.0003) // x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + elevator2 = level.elevator(820, 1300, 260, 40, 607, 0.0003) + elevator3 = level.elevator(-2850, 1250, 160, 40, 600, 0.007) + if (simulation.isHorizontalFlipped) { + spawn.mapVertex(-2900, 225, "0 0 0 -500 -500 -500") + } else { + spawn.mapVertex(-2900, 225, "0 0 0 -500 500 -500") + } + spawn.mapRect(-3050, 1175, 175, 300); + spawn.bodyRect(-2375, 1300, 100, 100); + spawn.bodyRect(-2325, 1250, 50, 50); + spawn.bodyRect(-2275, 1350, 125, 50); + + + level.custom = () => { + elevator1.move(); + elevator1.drawTrack(); + elevator2.move(); + elevator2.drawTrack(); + elevator3.move(); + elevator3.drawTrack(); + + ctx.fillStyle = "#444" //light fixtures + ctx.fillRect(-920, -505, 40, 10) + ctx.fillRect(-920, 95, 40, 10) + ctx.fillRect(180, 95, 40, 10) + ctx.fillRect(-20, 695, 40, 10) + ctx.fillRect(-2320, 945, 40, 10) + + ctx.fillStyle = "#cff" //exit + ctx.fillRect(300, -250, 350, 250) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + } else { + spawn.mapRect(-2950, 1250, 175, 250); + spawn.mapRect(-3050, 1100, 150, 400); + + spawn.bodyRect(-1450, -125, 125, 125, 1, spawn.propsSlide); //weight + spawn.bodyRect(-1800, 0, 300, 100, 1, spawn.propsHoist); //hoist + cons[cons.length] = Constraint.create({ + pointA: { + x: -1650, + y: -500 + }, + bodyB: body[body.length - 1], + stiffness: 0.0001815, + length: 1 + }); + Composite.add(engine.world, cons[cons.length - 1]); + + spawn.bodyRect(600, 525, 125, 125, 1, spawn.propsSlide); //weight + spawn.bodyRect(800, 600, 300, 100, 1, spawn.propsHoist); //hoist + cons[cons.length] = Constraint.create({ + pointA: { + x: 950, + y: 100 + }, + bodyB: body[body.length - 1], + stiffness: 0.0001815, + length: 1 + }); + Composite.add(engine.world, cons[cons.length - 1]); + + spawn.bodyRect(-2700, 1150, 100, 160, 1, spawn.propsSlide); //weight + spawn.bodyRect(-2550, 1200, 150, 150, 1, spawn.propsSlide); //weight + spawn.bodyRect(-2763, 1300, 350, 100, 1, spawn.propsHoist); //hoist + cons[cons.length] = Constraint.create({ + pointA: { + x: -2575, + y: 150 + }, + bodyB: body[body.length - 1], + stiffness: 0.0004, + length: 566 + }); + Composite.add(engine.world, cons[cons.length - 1]); + } + //blocks + spawn.bodyRect(-212, -150, 30, 35, 1); + spawn.bodyRect(-212, -115, 30, 35, 1); + spawn.bodyRect(-212, -80, 30, 35, 1); + spawn.bodyRect(-212, -45, 30, 35, 1); + + spawn.bodyRect(-750, 400, 150, 150, 0.5); + spawn.bodyRect(-400, 1175, 100, 250, 1); //block to get to top path on bottom level + + spawn.bodyRect(-2525, -50, 145, 100, 0.5); + spawn.bodyRect(-2325, -300, 150, 100, 0.5); + spawn.bodyRect(-1275, -750, 200, 150, 0.5); //roof block + spawn.bodyRect(-525, -700, 125, 100, 0.5); //roof block + + //mobs + spawn.randomSmallMob(-1125, 550); + spawn.randomSmallMob(-2950, -50); + spawn.randomMob(-2025, 175, 0.3); + spawn.randomMob(-2325, 450, 0.3); + spawn.randomMob(-2925, 675, 0.2); + spawn.randomMob(-2700, 300, 0.1); + spawn.randomMob(-2500, 300, 0.1); + spawn.randomMob(-2075, -425, 0.1); + spawn.randomMob(-1550, -725, 0.1); + spawn.randomMob(375, 1100, 0); + spawn.randomMob(-1575, 1100, 0); + spawn.randomSmallMob(825, 300); + spawn.randomMob(-800, -1750, 0); + spawn.randomMob(400, -750, -0.1); + spawn.randomMob(650, 1300, -0.1); + spawn.randomMob(-2450, 1050, -0.1); + spawn.randomMob(500, 400, -0.1); + spawn.randomMob(-75, -1700, -0.1); + spawn.randomMob(900, -800, -0.2); + spawn.randomGroup(-75, 1050, -0.1); + spawn.randomGroup(-900, 1000, 0.2); + spawn.randomGroup(-1300, -1100, -0.3); + spawn.randomSmallMob(-2325, 800); + spawn.randomSmallMob(-900, 825); + + if (simulation.difficulty > 1) { + if (Math.random() < 0.80) { + spawn.randomLevelBoss(-800, -1300) + } else { + spawn.dragonFlyBoss(-1000 + Math.random() * 2500, -1300); //boss snake with head + } + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(300, -800) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + + // boost1.boostBounds.min.x = -boost1.boostBounds.min.x - 100 + // boost1.boostBounds.max.x = -boost1.boostBounds.max.x + 100 + level.setPosToSpawn(-25, -55); //-x + + if (isElevators) { + elevator1.holdX = -elevator1.holdX // flip the elevator horizontally + elevator2.holdX = -elevator2.holdX // flip the elevator horizontally + elevator3.holdX = -elevator3.holdX // flip the elevator horizontally + level.custom = () => { + elevator1.move(); + elevator1.drawTrack(); + elevator2.move(); + elevator2.drawTrack(); + elevator3.move(); + elevator3.drawTrack(); + + ctx.fillStyle = "#444" //light fixtures + ctx.fillRect(920 - 40, -505, 40, 10) + ctx.fillRect(920 - 40, 95, 40, 10) + ctx.fillRect(-180 - 40, 95, 40, 10) + ctx.fillRect(20 - 40, 695, 40, 10) + ctx.fillRect(2320 - 40, 945, 40, 10) + + ctx.fillStyle = "#cff" //exit + ctx.fillRect(-300 - 350, -250, 350, 250) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + } else { + level.custom = () => { + ctx.fillStyle = "#444" //light fixtures + ctx.fillRect(920 - 40, -505, 40, 10) + ctx.fillRect(920 - 40, 95, 40, 10) + ctx.fillRect(-180 - 40, 95, 40, 10) + ctx.fillRect(20 - 40, 695, 40, 10) + ctx.fillRect(2320 - 40, 945, 40, 10) + + ctx.fillStyle = "#cff" //exit + ctx.fillRect(-300 - 350, -250, 350, 250) + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + } + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.15)"; //shadows and lights + ctx.beginPath() + ctx.moveTo(1800, -500) + ctx.lineTo(910, -500) //3rd floor light + ctx.lineTo(1300, 0) + ctx.lineTo(500, 0) + ctx.lineTo(890, -500) + ctx.lineTo(175, -500) + ctx.lineTo(175, -250) + ctx.lineTo(-175, -250) + ctx.lineTo(-175, 0) + ctx.lineTo(910, 100) //2nd floor light left + ctx.lineTo(1300, 600) + ctx.lineTo(500, 600) + ctx.lineTo(890, 100) + ctx.lineTo(-190, 100) //2nd floor light right + ctx.lineTo(200, 600) + ctx.lineTo(-600, 600) + ctx.lineTo(-210, 100) + ctx.lineTo(-1100, 100) + ctx.lineTo(-1100, 1400) + ctx.lineTo(-600, 1400) //1st floor light right + ctx.lineTo(-10, 700) + ctx.lineTo(10, 700) + ctx.lineTo(600, 1400) + ctx.lineTo(1950, 1400) //1st floor light left + ctx.lineTo(2290, 950) + ctx.lineTo(2310, 950) + ctx.lineTo(2650, 1400) + ctx.lineTo(3025, 1400) + ctx.lineTo(3025, 150) + ctx.lineTo(2590, 150) + ctx.lineTo(2600, -150) + ctx.lineTo(1800, -150) + ctx.lineTo(1800, -500) //top left end/start of path + ctx.fill() + }; + } + }, + office() { + level.announceMobTypes() + let button, door + let isReverse = false + if (Math.random() < 0.75) { //normal direction start in top left + button = level.button(525, 0) + door = level.door(1362, -400, 25, 400, 355, 1.5) //door(x, y, width, height, distance, speed = 1) { + level.setPosToSpawn(1375, -1550); //normal spawn + level.exit.x = 3088; + level.exit.y = -630; + } else { //reverse direction, start in bottom right + isReverse = true + button = level.button(3800, 0) + door = level.door(3012, -400, 25, 400, 355, 1.5) + level.setPosToSpawn(3137, -650); //normal spawn + level.exit.x = 1375; + level.exit.y = -1530; + } + level.custom = () => { + button.query(); + button.draw(); + if (button.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + ctx.fillStyle = "#ccc" + ctx.fillRect(2495, -500, 10, 525) + ctx.fillStyle = "#dff" + if (isReverse) { + ctx.fillRect(725, -1950, 825, 450) + } else { + ctx.fillRect(3050, -950, 625, 500) + } + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(3650, -1300, 1300, 1300) + ctx.fillRect(3000, -1000, 650, 1000) + ctx.fillRect(750, -1950, 800, 450) + ctx.fillRect(750, -1450, 650, 1450) + ctx.fillRect(-550, -1700, 1300, 1700) + // ctx.fillRect(0, 0, 0, 0) + door.draw(); + }; + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom) + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 50); //ground bump wall + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + document.body.style.backgroundColor = "#e0e5e0"; + + spawn.debris(-300, -200, 1000, 6); //ground debris //16 debris per level + spawn.debris(3500, -200, 800, 5); //ground debris //16 debris per level + spawn.debris(-300, -650, 1200, 5); //1st floor debris //16 debris per level + powerUps.spawnStartingPowerUps(-525, -700); + + spawn.mapRect(-600, 0, 2000, 325); //ground + spawn.mapRect(1400, 25, 1600, 300); //ground + spawn.mapRect(3000, 0, 2000, 325); //ground + spawn.mapRect(-600, -1700, 50, 2000 - 100); //left wall + spawn.bodyRect(-295, -1540, 40, 40); //center block under wall + spawn.bodyRect(-298, -1580, 40, 40); //center block under wall + spawn.bodyRect(1500, -1540, 30, 30); //left of entrance + spawn.mapRect(1550, -2000, 50, 550); //right wall + // spawn.mapRect(1350, -2000 + 505, 50, 1295); + spawn.mapRect(1350, -1500, 50, 1125); //right wall + spawn.mapRect(-600, -2000 + 250, 2000 - 700, 50); //roof left + spawn.mapRect(-600 + 1300, -2000, 50, 300); //right roof wall + spawn.mapRect(-600 + 1300, -2000, 900, 50); //center wall + + map[map.length] = Bodies.polygon(725, -1700, 0, 15); //circle above door + spawn.bodyRect(720, -1675, 15, 170, 1, spawn.propsDoor); // door + body[body.length - 1].isNotHoldable = true; + //makes door swing + consBB[consBB.length] = Constraint.create({ + bodyA: body[body.length - 1], + pointA: { + x: 0, + y: -90 + }, + bodyB: map[map.length - 1], + stiffness: 1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + + spawn.mapRect(-600 + 300, -2000 * 0.75, 1900, 50); //3rd floor + spawn.mapRect(-600 + 2000 * 0.7, -2000 * 0.74, 50, 375); //center wall + spawn.bodyRect(-600 + 2000 * 0.7, -2000 * 0.5 - 106, 50, 106); //center block under wall + spawn.mapRect(-600, -1000, 1100, 50); //2nd floor + spawn.mapRect(600, -1000, 500, 50); //2nd floor + spawn.spawnStairs(-600, -1000, 4, 250, 350); //stairs 2nd + spawn.mapRect(375, -600, 350, 150); //center table + spawn.mapRect(-300, -2000 * 0.25, 1690, 50); //1st floor + spawn.spawnStairs(-610 + 2000 - 50, -500, 4, 250, 350, true); //stairs + spawn.spawnStairs(-600, 0, 4, 250, 350); //stairs ground + spawn.bodyRect(700, -200, 100, 100); //center block under wall + spawn.bodyRect(700, -300, 100, 100); //center block under wall + spawn.bodyRect(700, -400, 100, 100); //center block under wall + spawn.mapRect(1390, 13, 30, 20); //step left + spawn.mapRect(2980, 13, 30, 20); //step right + spawn.bodyRect(4250, -700, 50, 100); + spawn.mapRect(3000, -1000, 50, 625); //left wall + spawn.mapRect(3000 + 2000 - 50, -1300, 50, 1100); //right wall + spawn.mapRect(4150, -600, 350, 150); //table + spawn.mapRect(3650, -1300, 50, 700); //exit wall + spawn.mapRect(3650, -1300, 1350, 50); //exit wall + spawn.bodyRect(3665, -600, 20, 100); //door + + spawn.mapRect(3025, -600, 250, 125); + spawn.mapRect(3175, -550, 175, 75); + // spawn.mapVertex(3160, -525, "625 0 300 0 300 -140 500 -140"); //entrance/exit ramp + + spawn.mapRect(3000, -2000 * 0.5, 700, 50); //exit roof + spawn.mapRect(3010, -2000 * 0.25, 1690, 50); //1st floor + spawn.spawnStairs(3000 + 2000 - 50, 0, 4, 250, 350, true); //stairs ground + spawn.randomSmallMob(4575, -560, 1); + spawn.randomSmallMob(1315, -880, 1); + spawn.randomSmallMob(800, -600); + spawn.randomMob(4100, -225, 0.8); + spawn.randomMob(-250, -700, 0.8); + spawn.randomMob(4500, -225, 0.15); + spawn.randomMob(3250, -225, 0.15); + spawn.randomMob(-100, -225, 0.1); + spawn.randomMob(1150, -225, 0.15); + spawn.randomMob(2000, -225, 0.15); + spawn.randomMob(450, -225, 0.15); + spawn.randomMob(100, -1200, 1); + spawn.randomMob(950, -1150, -0.1); + spawn.randomGroup(1800, -800, -0.2); + spawn.randomGroup(4150, -1000, 0.6); + if (simulation.difficulty > 1) { + if (Math.random() < 0.5) { + spawn.tetherBoss(2850, -80, { x: 2500, y: -500 }) + } else { + spawn.randomLevelBoss(2200, -450) + } + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(1875, -675) + + if (simulation.isHorizontalFlipped) { //flip the map horizontally + level.flipHorizontal(); //only flips map,body,mob,powerUp,cons,consBB, exit + level.setPosToSpawn(50, -60); + + if (!isReverse) { //normal direction start in top left + level.setPosToSpawn(-1375, -1550); //normal spawn //-x + } else { //reverse direction, start in bottom right + level.setPosToSpawn(-3137, -650); //normal spawn + } + button.min.x = -button.min.x - 126 // flip the button horizontally + button.max.x = -button.max.x + 126 // flip the button horizontally + level.custom = () => { + button.query(); + button.draw(); + if (button.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + ctx.fillStyle = "#ccc" + ctx.fillRect(-2495 - 10, -500, 10, 525) + ctx.fillStyle = "#dff" + if (isReverse) { + ctx.fillRect(-725 - 825, -1950, 825, 450) + } else { + ctx.fillRect(-3050 - 625, -950, 625, 500) + } + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-3650 - 1300, -1300, 1300, 1300) + ctx.fillRect(-3000 - 650, -1000, 650, 1000) + ctx.fillRect(-750 - 800, -1950, 800, 450) + ctx.fillRect(-750 - 650, -1450, 650, 1450) + ctx.fillRect(550 - 1300, -1700, 1300, 1700) + // ctx.fillRect(0, 0, 0, 0) + door.draw(); + }; + } + + }, + stronghold() { // player made level by Francois 👑 from discord + simulation.inGameConsole(`stronghold by Francois`); + + const boost1 = level.boost(1470, -250, 1080) + const boost2 = level.boost(-370, 0, 800) + const boost3 = level.boost(4865, 0, 1800) + level.custom = () => { + boost1.query(); + boost2.query(); + boost3.query(); + ctx.fillStyle = "#edf9f9"; + ctx.fillRect(-500, -1220, 550, -480); + ctx.fillStyle = "rgba(0,0,0,0.1)"; + ctx.fillRect(0, -700, 1050, 700); + ctx.fillRect(-550, -1170, 550, 1170); + ctx.fillRect(1150, -1700, 250, 1700); + ctx.fillRect(1100, -1700, 50, 450); + ctx.fillRect(1050, -1200, 100, 1200); + ctx.fillRect(1400, -250, 200, -1500); + ctx.fillRect(1600, -550, 600, -1150); + ctx.fillRect(2530, -550, 430, -1450); + ctx.fillRect(3270, -1700, 80, 600); + ctx.fillRect(3350, -1350, 700, 230); + ctx.fillRect(4050, -1700, 600, 1290); + ctx.fillRect(3650, -110, 1000, 170); + ctx.fillRect(4865, -55, 100, 55); + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + + }; + + level.setPosToSpawn(1900, -40); //normal spawn + level.exit.x = -350; + level.exit.y = -1250; + + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom) + + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 20); //exit bump + spawn.debris(3800, -1480, 300, 12); + spawn.debris(3600, -1130, 200, 2); + document.body.style.backgroundColor = "#dbdcde"; + // simulation.draw.mapFill = "#444" + // simulation.draw.bodyFill = "rgba(140,140,140,0.85)" + // simulation.draw.bodyStroke = "#222" + + // __________________________________________________________________________________________________ + // Spawn Box + spawn.mapRect(1600, -500, 50, 500); //Left Wall + spawn.mapRect(1600, -550, 1500, 50); //Roof + spawn.mapRect(2300, -500, 50, 300); //Right Wall + + spawn.mapRect(-550, 0, 4300, 200); //ground + spawn.mapRect(3700, 55, 1300, 145); //2nd ground + spawn.mapRect(5000, 0, 50, 200); //Last small part of the ground + spawn.mapRect(3100, -1070, 50, 570); // vertical 2nd roof + spawn.mapRect(3100, -1120, 950, 50); // Horizontal 2nd Roof + spawn.mapRect(4050, -1750, 600, 50); // Roof after lift + spawn.mapRect(4600, -1700, 50, 100); // Petit retour de toit, après ascenseur + + //Spawn "Upstairs" + spawn.mapRect(3650, -160, 400, 50); //Thin Walk + spawn.mapRect(4050, -410, 600, 300); //Large staircase block + spawn.mapRect(4600, -1120, 50, 710); //Left Wall Wall upstairs + spawn.mapRect(4550, -1170, 100, 50); //Bloque ascenseur + spawn.mapVertex(3700, 35, "0 0 450 0 300 -60 150 -60"); //first slope + spawn.mapVertex(4850, 35, "0 0 370 0 370 -65 150 -65"); //second slope + + spawn.bodyRect(3950, -280, 170, 120); //Bloc Marche Pour Monter À Ascenseur + // spawn.bodyRect(-2700, 1150, 100, 160, 1, spawn.propsSlide); //weight + // spawn.bodyRect(-2550, 1150, 200, 100, 1, spawn.propsSlide); //weight + spawn.bodyRect(4050, -500, 275, 100, 1, spawn.propsSlide); //weight + spawn.bodyRect(4235, -500, 275, 100, 1, spawn.propsSlide); //weight + // spawn.bodyRect(-2775, 1300, 400, 100, 1, spawn.propsHoist); //hoist + spawn.bodyRect(4025, -450, 550, 100, 1, spawn.propsHoist); //hoist + cons[cons.length] = Constraint.create({ + pointA: { + x: 4325, + y: -1700, + }, + bodyB: body[body.length - 1], + stiffness: 0.0002, //1217, + length: 200 + }); + Composite.add(engine.world, cons[cons.length - 1]); + + spawn.bodyRect(2799, -870, 310, 290); //Gros bloc angle toit + spawn.mapRect(4000, -1750, 50, 400); //Right Wall Cuve + spawn.mapRect(3400, -1400, 600, 50); // Bottom Cuve + spawn.mapRect(3350, -1750, 50, 400); // Left Wall Cuve + spawn.bodyRect(3400, -1470, 110, 70); //Moyen bloc dans la cuve + spawn.mapRect(3270, -1750, 80, 50); // Rebord gauche cuve + + spawn.mapRect(2530, -2000, 430, 50); //First Plateforme + spawn.mapRect(1600, -1750, 600, 50); // Middle plateforme + spawn.mapRect(1100, -1750, 300, 50); //Derniere plateforme // Toit petite boite en [ + spawn.bodyRect(1830, -1980, 190, 230); // Fat bloc plateforme middle + spawn.bodyRect(1380, -1770, 250, 20) // Pont last plateforme + + spawn.mapRect(1000, -1250, 400, 50); //Sol de la petite boite en [ + spawn.mapRect(1100, -1550, 50, 190); //Mur gauche petite boite en [ + spawn.bodyRect(1100, -1380, 48, 109); //Bloc-porte petite boite en [ + + spawn.mapRect(-100, -750, 1100, 50); //Sol last salle + spawn.mapRect(1000, -1200, 50, 500) // Mur droit last salle + spawn.mapRect(50, -1550, 1050, 50); // Toit last salle + spawn.bodyRect(1, -900, 48, 150); //Bloc porte last salle + spawn.mapRect(0, -1170, 50, 270); //Mur gauche en bas last salle + spawn.bodyRect(920, -900, 120, 120); //Gros bloc last salle + + spawn.mapRect(0, -1700, 50, 320); // Mur droit salle exit / Mur gauche last salle + spawn.mapRect(-550, -1220, 600, 50); // Sol exit room + spawn.mapRect(-500, -1750, 550, 50); // Toit exit room + spawn.mapRect(-550, -1750, 50, 530); // Mur gauche exit room + spawn.bodyRect(-503, -1250, 30, 30); // Petit bloc exit room + + spawn.mapRect(500, -700, 100, 590); //Bloc noir un dessous last salle + spawn.mapRect(1350, -250, 250, 250); //Black Block left from the spawn + + + map[map.length] = Bodies.polygon(2325, -205, 0, 15); //circle above door + spawn.bodyRect(2325, -180, 15, 170, 1, spawn.propsDoor); // door + body[body.length - 1].isNotHoldable = true; + //makes door swing + consBB[consBB.length] = Constraint.create({ + bodyA: body[body.length - 1], + pointA: { + x: 0, + y: -90 + }, + bodyB: map[map.length - 1], + stiffness: 1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + spawn.bodyRect(650, 50, 70, 50); + spawn.bodyRect(300, 0, 100, 60); + spawn.bodyRect(400, 0, 100, 150); + spawn.bodyRect(2545, -50, 70, 50); + spawn.bodyRect(2550, 0, 100, 30); + + spawn.randomSmallMob(200, -1300, 0.5); + spawn.randomSmallMob(300, -1300, 0.9); + spawn.randomSmallMob(470, -650, 1); + spawn.randomSmallMob(1000, -400, 1); + spawn.randomSmallMob(2550, -560, 1); + spawn.randomSmallMob(3350, -900, 1); + spawn.randomSmallMob(3600, -1210, 1); + spawn.randomSmallMob(700, -1950, 0.2); + spawn.randomSmallMob(5050, -550); + spawn.randomMob(-250, -250, 0.8); + spawn.randomMob(-300, -600, 0.6); + spawn.randomMob(350, -900, 0.5); + spawn.randomMob(770, -950, 0.8) + spawn.randomMob(900, -160, 1); + spawn.randomMob(2360, -820, 0.8); + spawn.randomMob(2700, -2020, 0.8); + spawn.randomMob(3050, -1650, 0.8); + spawn.randomMob(3350, -600, 0.8); + spawn.randomMob(4400, -50, 1); + spawn.randomGroup(1500, -1900, 0.5); + spawn.randomGroup(2350, -850, 1); + spawn.randomGroup(100, -450, 0.9); + + if (simulation.difficulty > 1) spawn.randomLevelBoss(1850, -1400); + spawn.secondaryBossChance(1850, -1400) + + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + basement() { // player made level by Francois 👑 from discord + simulation.inGameConsole(`basement by Francois`); + let button, door, buttonDoor, buttonPlateformEnd, doorPlateform + let isLevelReversed = Math.random(); + if (isLevelReversed < 0.7) { + isLevelReversed = false; + } else { + isLevelReversed = true; + } + const elevator = level.elevator(4545, -220, 110, 30, -3000) + const hazard = level.hazard(1675, -1050, 800, 150); + const portal = level.portal({ + x: -620, + y: -257 + }, Math.PI / 2, { //down + x: 500, + y: 2025 + }, -Math.PI / 2) //up + spawn.mapRect(350, 2025, 300, 300); //Bloc portail n°2 + + if (isLevelReversed === false) { /// Normal Spawn + button = level.button(2700, -1150); + level.setPosToSpawn(2600, -2050); //normal spawn + level.exit.x = level.enter.x + 4510; + level.exit.y = level.enter.y + 600; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + } else { /// Reversed spawn + button = level.button(1450, -1150); + buttonPlateformEnd = level.button(3530, -1150); + buttonDoor = level.button(8033, -3625); + door = level.door(7700, -3905, 25, 184, 184); + doorPlateform = level.door(3200, -1225, 299, 80, 525); + level.setPosToSpawn(7110, -1450); //normal spawn + level.exit.x = level.enter.x - 4510; + level.exit.y = level.enter.y - 600; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + spawn.mapRect(7675, -3935, 75, 25); + spawn.mapRect(7675, -3715, 75, 25); + spawn.bodyRect(8075, -3675, 50, 25); + } + const boost1 = level.boost(8290, -2100, 1800) + level.custom = () => { + boost1.query(); + + level.exit.drawAndCheck(); + portal[2].query() + portal[3].query() + button.query(); + button.draw(); + if (isLevelReversed === true) { ///Reversed spawn + buttonDoor.draw(); + buttonDoor.query(); + buttonPlateformEnd.draw(); + buttonPlateformEnd.query(); + // hazard.query(); //bug reported from discord? + if (buttonDoor.isUp) { + door.isClosing = false + } else { + door.isClosing = true + } + door.openClose(); + if (buttonPlateformEnd.isUp) { + doorPlateform.isClosing = true; + } else { + doorPlateform.isClosing = false; + } + door.openClose(); + doorPlateform.openClose(); + } + hazard.level(button.isUp) + + + level.enter.draw(); + elevator.move(); + elevator.drawTrack(); + }; + + level.customTopLayer = () => { + ctx.fillStyle = "rgba(61,62,62,0.95)"; + ctx.fillRect(-750, -900, 750, 450); + + if (isLevelReversed === true) { + door.draw(); + doorPlateform.draw(); + } + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + hazard.query(); + }; + + level.defaultZoom = 1300 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#c7c7c7"; + + // GROUND // + spawn.mapRect(-400, -2000, 400, 1430); //Gros left wall + spawn.mapRect(3700, -3000, 700, 2650); //Gros right wall //Puit + spawn.mapRect(-400, -2000, 3700, 250); //Ground + spawn.mapRect(2475, -1150, 1225, 250); + spawn.mapRect(500, -1150, 1175, 250); //Ground level 3 + spawn.mapRect(350, -180, 4600, 1255); // Last ground + spawn.mapRect(-400, -458, 750, 3337); //mur left sous-sol + spawn.mapRect(-2850, -3375, 5300, 1375); + spawn.mapRect(-2850, -4200, 8000, 825); + spawn.mapRect(3700, -3375, 550, 375); + spawn.mapRect(-2850, -5200, 10200, 1000); + spawn.mapRect(5600, -1250, 3550, 2000); + spawn.mapRect(9150, -5200, 1725, 5800); + // SPAWN BOX // + spawn.mapRect(2300, -3375, 950, 1000); + spawn.mapRect(3550, -3375, 150, 1625); + spawn.mapVertex(2020, -791, " 250 250 -860 250 -2200 0 250 0"); //map vertex en haut + spawn.mapVertex(690, -295, "1700 0 -200 0 -200 -284 500 -284"); //map vertex en bas + spawn.mapRect(2950, -900, 750, 250); //Extension ground apres map vertex + if (isLevelReversed === false) { + spawn.mapRect(3250, -1800, 50, 150); //Petit picot en haut, à gauche + spawn.mapRect(3400, -1800, 50, 150); //Petit picot en haut, à droite + spawn.mapRect(3150, -1300, 50, 200) //Petit picot en bas, à gauche + spawn.mapRect(3500, -1300, 50, 200) //Petit picot en bas, à droite + spawn.mapRect(3050, -3375, 500, 1260); + spawn.mapRect(3400, -2265, 150, 515); //Mur fond tunnel + spawn.bodyRect(3625, -1225, 75, 75); //Pitit bloc à droite en bas spawn + } else { + spawn.mapRect(3050, -3375, 500, 1000); + spawn.mapRect(3400, -2400, 150, 650); //Mur fond tunnel + spawn.bodyRect(3425, -1515, 75, 75); //Petit en bas spawn + spawn.mapRect(3200, -1275, 300, 175); + } + + // TRAMPOLING // + if (isLevelReversed === false) { /// Normal spawn + spawn.bodyRect(0, -1000, 500, 120, 1, spawn.propsHoist); //hoist + cons[cons.length] = Constraint.create({ + pointA: { + x: 250, + y: -1750, + }, + bodyB: body[body.length - 1], + stiffness: 0.00014, + length: 120 + }); + Composite.add(engine.world, cons[cons.length - 1]); + spawn.bodyRect(0, -1250, 240, 190) //Fat cube ascenseur + } else { /// Reversed spawn + spawn.bodyRect(0, -650, 225, 175); + spawn.mapRect(425, -950, 175, 50); + spawn.mapRect(-25, -1150, 100, 50); + } + // PUIT // + spawn.mapVertex(4200, -1810, "0 0 450 0 600 -2500 0 -2500") + spawn.mapVertex(5000, -1809, "0 0 450 0 450 -2500 -150 -2500") + spawn.mapRect(4800, -3000, 800, 5875); //big right Puit + // BOSS AREA // + spawn.mapRect(4800, -3150, 50, 200); //Premiere barriere + spawn.mapRect(5100, -3530, 50, 380); //2nd barriere + spawn.mapRect(5100, -3200, 150, 50); //Marche en dessous mapVertex 1 + spawn.mapVertex(5450, -3650, "220 0 200 30 -200 30 -220 0 -200 -30 200 -30"); + spawn.mapVertex(6225, -3350, "275 0 250 50 -250 50 -275 0 -250 -50 250 -50"); + spawn.mapRect(5600, -3000, 1600, 725); //ground Boss Area + //Ouverture right boss area + spawn.mapRect(7300, -3325, 50, 50); //petite marche pour accéder à l'ouverture + spawn.mapRect(7350, -4075, 850, 50); //Bouche + spawn.mapRect(7400, -4050, 800, 50); //Bouche + spawn.mapRect(7450, -4025, 750, 50); //Bouche + spawn.mapRect(7500, -4000, 700, 50); //Bouche + spawn.mapRect(7550, -3975, 650, 50); //Bouche + spawn.mapRect(7350, -3600, 850, 50); //Bouche + spawn.mapRect(7400, -3625, 800, 50); //Bouche + spawn.mapRect(7450, -3650, 575, 50); //Bouche + spawn.mapRect(7500, -3675, 525, 50); //Bouche + spawn.mapRect(7550, -3700, 475, 50); //Bouche + //Murs + spawn.mapRect(7350, -5200, 1800, 1125); + spawn.mapRect(8475, -4075, 675, 2825); + spawn.mapRect(7300, -2100, 1175, 850); + spawn.mapRect(7350, -3550, 850, 1275); + //Escaliers + spawn.mapRect(6600, -2100, 200, 75); //escaliers + spawn.mapRect(6750, -2100, 750, 250); //escaliers + spawn.mapRect(6950, -1850, 550, 200); //escaliers + spawn.mapRect(6750, -1400, 750, 150); //escaliers + spawn.mapRect(6550, -1625, 250, 375); //escaliers + spawn.mapRect(6350, -1800, 250, 550); //escaliers + spawn.mapRect(5600, -2275, 800, 1025); //escaliers + // BLOCS + if (isLevelReversed === false) { /// Normal spawn + spawn.bodyRect(1350, -1175, 225, 25); + spawn.bodyRect(1450, -1200, 25, 25); + } else { /// Reversed spawn + spawn.bodyRect(700, -1175, 225, 25); + spawn.bodyRect(800, -1200, 25, 25); + } + spawn.bodyRect(1100, -1375, 225, 225); + spawn.bodyRect(1775, -925, 75, 25); + spawn.bodyRect(2225, -950, 75, 50); + spawn.bodyRect(2000, -1000, 50, 100); + spawn.bodyRect(3100, -1175, 50, 25); + spawn.bodyRect(2200, -375, 50, 50); + spawn.bodyRect(2200, -425, 50, 50); + spawn.bodyRect(2200, -475, 50, 50); + spawn.bodyRect(2200, -525, 50, 50); + spawn.bodyRect(1050, -400, 50, 25); + spawn.mapRect(2200, -650, 50, 125); + spawn.mapRect(2200, -325, 50, 150); + spawn.mapRect(2875, -225, 250, 50); + spawn.mapRect(2050, -1225, 75, 100); //Plateforme over acid + // MOBS + if (isLevelReversed === false) { ///Normal spawn + if (simulation.difficulty > 1) { + if (Math.random() < 0.2) { + spawn.tetherBoss(7000, -3300, { x: 7300, y: -3300 }) // tether ball + } else { + spawn.randomLevelBoss(6100, -3600, ["shooterBoss", "launcherBoss", "laserTargetingBoss", "spiderBoss", "laserBoss", "pulsarBoss"]); + } + } + } else { /// Reversed spawn + if (simulation.difficulty > 1) { + if (Math.random() < 0.2) { + spawn.tetherBoss(2300, -1300, { x: 2300, y: -1750 }) // tether ball + } else { + spawn.randomLevelBoss(2300, -1400, ["shooterBoss", "launcherBoss", "laserTargetingBoss", "spiderBoss", "laserBoss", "dragonFlyBoss", "pulsarBoss"]); + } + } + } + spawn.randomSmallMob(100, -1000, 1); + spawn.randomSmallMob(1340, -675, 1); + spawn.randomSmallMob(7000, -3750, 1); + spawn.randomSmallMob(6050, -3200, 1); + spawn.randomMob(1970 + 10 * Math.random(), -1150 + 20 * Math.random(), 1); + spawn.randomMob(3500, -525, 0.8); + spawn.randomMob(6700, -3700, 0.8); + spawn.randomMob(2600, -1300, 0.7); + spawn.randomMob(600, -1250, 0.7); + spawn.randomMob(2450, -250, 0.6); + spawn.randomMob(6200, -3200, 0.6); + spawn.randomMob(900, -700, 0.5); + spawn.randomMob(1960, -400, 0.5); + spawn.randomMob(5430, -3520, 0.5); + spawn.randomMob(400, -700, 0.5); + spawn.randomMob(6500, -4000, 0.4); + spawn.randomMob(3333, -400, 0.4); + spawn.randomMob(3050, -1220, 0.4); + spawn.randomMob(800, 1200, 0.3); + spawn.randomMob(7200, -4000, 0.3); + spawn.randomMob(250, -1550, 0.3); + spawn.randomGroup(900, -1450, 0.3); + spawn.randomGroup(2980, -400, 0.3); + spawn.randomGroup(5750, -3860, 0.4); + spawn.randomGroup(1130, 1300, 0.1); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + powerUps.spawn(1900, -940, "heal"); + powerUps.spawn(3000, -230, "heal"); + powerUps.spawn(5450, -3675, "ammo"); + + // SECRET BOSS AREA // + //hidden house + spawn.mapRect(-850, -2000, 600, 1150); //Toit hidden house + spawn.mapRect(-2850, -2000, 2150, 4880); //Mur gauche hidden house + spawn.mapRect(-850, -458, 500, 3340); //Bloc sol hidden house + // + spawn.mapRect(-400, 2025, 3450, 850); //Sol secret boss area + spawn.mapRect(625, 1300, 225, 50); //Plateforme horizontale n°1 + spawn.mapRect(850, 1775, 470, 50); //Plateforme horizontale n°2 + spawn.mapRect(1000, 1625, 100, 150); //Plateforme vertiale n°1 + spawn.mapRect(1400, 1275, 100, 100); //Plateforme carrée + spawn.mapRect(1700, 1675, 75, 450); //Plateforme verticale n°2 + spawn.mapRect(2100, 1375, 450, 50); //Plateforme accroche boss + spawn.mapRect(2900, 900, 175, 325); //Débord de toit droite haut + spawn.mapRect(2900, 1675, 150, 350); //Muret en bas à droite + spawn.mapRect(2900, 1225, 75, 100); //Picot haut entrée salle trésor + spawn.mapRect(2900, 1575, 75, 100); //Picot bas entrée salle trésor + spawn.mapRect(2800, 1575, 100, 25); //Plongeoir sortie salle trésor + spawn.mapRect(3050, 1675, 400, 1200); //Sol sallle trésor + spawn.mapRect(3075, 1075, 375, 150); //Plafond salle trésor + spawn.mapRect(3300, 1075, 1500, 1800); //Mur droite salle trésor + // tether ball + spawn.tetherBoss(2330, 1850, { x: 2330, y: 1425 }) + spawn.secondaryBossChance(2330, 1850) + powerUps.chooseRandomPowerUp(3100, 1630); + }, + // detours() { //by Francois from discord + // simulation.inGameConsole(`detours by Francois`); + // level.setPosToSpawn(0, 0); //lower start + // level.exit.y = 150; + // spawn.mapRect(level.enter.x, 45, 100, 20); + // level.exit.x = 10625; + // spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + // level.defaultZoom = 1400; + // simulation.zoomTransition(level.defaultZoom) + // document.body.style.backgroundColor = "#d5d5d5"; + // const BGColor = "rgba(0,0,0,0.1)"; + // // level.fill.push({ + // // x: -150, + // // y: -250, + // // width: 625, + // // height: 325, + // // color: BGColor + // // }); + // // level.fill.push({ + // // x: 475, + // // y: -520, + // // width: 5375, + // // height: 875, + // // color: BGColor + // // }); + // // level.fill.push({ + // // x: 5850, + // // y: -1275, + // // width: 2800, + // // height: 2475, + // // color: BGColor + // // }); + // // level.fill.push({ + // // x: 8650, + // // y: -500, + // // width: 1600, + // // height: 750, + // // color: BGColor + // // }); + // // level.fill.push({ + // // x: 10250, + // // y: -700, + // // width: 900, + // // height: 950, + // // color: BGColor + // // }); + // const balance = level.spinner(5500, -412.5, 25, 660) //entrance + // const rotor = level.rotor(7000, 580, -0.001); + // const doorSortieSalle = level.door(8590, -520, 20, 800, 750) + // // let buttonSortieSalle + // // let portalEnBas + // let portalEnHaut + // // let door3isClosing = false; + + // function drawOnTheMapMapRect(x, y, dx, dy) { + // spawn.mapRect(x, y, dx, dy); + // len = map.length - 1 + // map[len].collisionFilter.category = cat.map; + // map[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + // Matter.Body.setStatic(map[len], true); //make static + // Composite.add(engine.world, map[len]); //add to world + // simulation.draw.setPaths() //update map graphics + // } + + // function drawOnTheMapBodyRect(x, y, dx, dy) { + // spawn.bodyRect(x, y, dx, dy); + // len = body.length - 1 + // body[len].collisionFilter.category = cat.body; + // body[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + // Composite.add(engine.world, body[len]); //add to world + // body[len].classType = "body" + // } + + // function spawnCouloirEnHaut() { + // // level.fill.push({ + // // x: 2575, + // // y: -1150, + // // width: 2550, + // // height: 630, + // // color: BGColor + // // }); + // // level.fill.push({ + // // x: 1900, + // // y: -2300, + // // width: 1650, + // // height: 1150, + // // color: BGColor + // // }); + // // level.fill.push({ + // // x: 3550, + // // y: -1625, + // // width: 1650, + // // height: 475, + // // color: BGColor + // // }); + // // level.fill.push({ + // // x: 1800, + // // y: -1120, + // // width: 775, + // // height: 600, + // // color: BGColor + // // }); + // drawOnTheMapMapRect(3800, -270, 75, 75); + // drawOnTheMapMapRect(3900, -895, 500, 75); + // drawOnTheMapMapRect(3900, -1195, 75, 375); + // drawOnTheMapMapRect(3525, -1195, 450, 75); + // drawOnTheMapMapRect(3525, -1995, 50, 1575); + // drawOnTheMapMapRect(3325, -1995, 50, 1575); + // drawOnTheMapMapRect(3525, -1670, 1675, 75); + // drawOnTheMapMapRect(5100, -1670, 100, 1250); + // drawOnTheMapMapRect(1800, -1195, 1575, 75); + // drawOnTheMapMapRect(1800, -1520, 375, 400); + // drawOnTheMapMapRect(1800, -2370, 100, 1250); + // drawOnTheMapMapRect(2375, -1845, 375, 250); + // drawOnTheMapMapRect(2700, -1745, 650, 75); + // drawOnTheMapMapRect(1800, -2370, 1775, 100); + // drawOnTheMapMapRect(3525, -2370, 50, 775); + // drawOnTheMapMapRect(4650, -1220, 550, 75); + // drawOnTheMapBodyRect(3225, -1845, 100, 100); + // drawOnTheMapBodyRect(3575, 1255, 125, 25); + // drawOnTheMapBodyRect(2450, 2255, 25, 25); + // drawOnTheMapBodyRect(3975, -945, 175, 50); + // drawOnTheMapBodyRect(4825, -1295, 50, 75); + // drawOnTheMapBodyRect(4850, -720, 250, 200); + // drawOnTheMapBodyRect(4050, -970, 25, 25); + // drawOnTheMapBodyRect(3075, -1245, 50, 50); + // portalEnHaut = level.portal({ + // x: 3650, + // y: -1470 + // }, Math.PI / 2, { + // x: 3250, + // y: -1473 + // }, Math.PI / 2) + + // spawn.randomSmallMob(2500, -2070 + Math.random(), 1); + // spawn.randomSmallMob(5000, -1370, 1); + // spawn.randomMob(5000, -645, 0.9); + // spawn.randomMob(4050, -970, 0.9); + // spawn.randomSmallMob(2800, -1620, 0.7); + // spawn.randomMob(2400, -1370, 0.5); + // spawn.randomMob(3725, -1320, 0.3); + // spawn.randomGroup(2115, -2020, 0.1) + + // powerUps.spawn(5000, -1275, "heal"); + + // levelCustom2(); + // } + // ////////////////////////////////////////// + // level.custom = () => { + // level.exit.drawAndCheck(); + // rotor.rotate(); + // // rotor2.rotate() + + // level.enter.draw(); + // }; + // level.customTopLayer = () => { + // doorSortieSalle.draw(); + // ctx.fillStyle = "#233" + // ctx.beginPath(); + // ctx.arc(balance.pointA.x, balance.pointA.y, 9, 0, 2 * Math.PI); + // ctx.fill(); + // }; + // //////////////////////////////////////// + // function levelCustom2() { + // level.custom = () => { + // portalEnHaut[2].query(); + // portalEnHaut[3].query(); + // rotor.rotate(); + // doorSortieSalle.openClose(); + // level.exit.drawAndCheck(); + + // level.enter.draw(); + // }; + // // ////////////////////////////////////// + // level.customTopLayer = () => { + // doorSortieSalle.draw(); + // portalEnHaut[0].draw(); + // portalEnHaut[1].draw(); + // portalEnHaut[2].draw(); + // portalEnHaut[3].draw(); + // ctx.fillStyle = "#233" + // ctx.beginPath(); + // ctx.arc(balance.pointA.x, balance.pointA.y, 9, 0, 2 * Math.PI); + // ctx.fill(); + + // }; + // } + // //spawn box + // spawn.mapRect(-200, -295, 75, 425); + // spawn.mapRect(-200, 55, 700, 75); + // spawn.mapRect(-200, -295, 700, 75); + // spawn.bodyRect(470, -220, 25, 275); //porte spawn box + // //couloir + // spawn.mapRect(450, -520, 50, 300); //muret gauche haut + // spawn.mapRect(450, 55, 50, 300); //muret gauche bas + // spawn.mapRect(1700, -520, 50, 325); //muret 2 haut + // spawn.mapRect(1700, 55, 50, 300); //muret 2 bas + // spawn.mapRect(4375, 55, 50, 300); + // spawn.mapRect(4575, 55, 50, 300); + // spawn.bodyRect(4625, 155, 75, 100); + // spawn.bodyRect(4725, 230, 50, 25); + // if (Math.random() > 0.5) { + // powerUps.chooseRandomPowerUp(4500, 200); + // } else { + // powerUps.chooseRandomPowerUp(8350, -630); + // } + // //blocs + // spawn.bodyRect(7475, 1055, 50, 75); + // spawn.bodyRect(7775, 1105, 25, 25); + // spawn.bodyRect(6925, 1105, 125, 25); + // spawn.bodyRect(6375, 380, 50, 50); + // spawn.bodyRect(6425, -220, 125, 150); + // spawn.bodyRect(6475, -245, 125, 25); + // spawn.bodyRect(7675, -245, 100, 50); + // spawn.bodyRect(7075, -520, 50, 100); + // spawn.bodyRect(8400, -595, 100, 75); + // spawn.bodyRect(1700, 5, 50, 50); + // spawn.bodyRect(1700, -45, 50, 50); + // spawn.bodyRect(1700, -95, 50, 50); + // spawn.bodyRect(1700, -145, 50, 50); + // spawn.bodyRect(1700, -195, 50, 50); + // spawn.mapRect(450, -520, 1600, 100); //plafond 1 + // spawn.mapRect(450, 255, 1600, 100); //sol 1 + // spawn.mapRect(2250, -45, 1450, 75); //entresol + // spawn.mapRect(3900, -520, 2000, 100); //plafond 2 + // spawn.mapRect(3900, 255, 2000, 100); //sol 2 + // //grande salle + // spawn.bodyRect(5900, 830, 325, 300); //bloc en bas à gauche + // spawn.mapRect(5775, -1295, 2900, 100); + // spawn.mapRect(5775, 1130, 2900, 100); //plancher + sol grande salle + // spawn.mapRect(5925, -70, 650, 50); //plateforme middle entrée + // spawn.mapRect(7575, -520, 1100, 100); //sol salle en haut à droite + // spawn.mapRect(6800, -420, 450, 50); //petite plateforme transition vers salle en haut + // spawn.mapRect(7750, -1295, 75, 575); //mur gauche salle en haut à droite + // spawn.mapRect(6100, 430, 375, 50); //plateforme en bas, gauche rotor + // spawn.mapRect(7450, -195, 1225, 75); //longue plateforme + // //murs grande salle + // spawn.mapRect(5775, -1295, 125, 875); + // spawn.mapRect(5775, 255, 125, 975); + // spawn.mapRect(8550, -1295, 125, 875); + // spawn.mapRect(8550, 180, 125, 1050); + // //couloir 2 + // spawn.mapRect(8875, -520, 1425, 325); + // spawn.mapRect(8550, -520, 1750, 100); + // spawn.mapRect(8550, 180, 2625, 100); + // spawn.mapRect(10175, -745, 125, 325); + // spawn.mapRect(10175, -745, 1000, 125); + // spawn.mapRect(11050, -745, 125, 1025); + // spawn.mapRect(8875, 80, 1425, 200); + // //MOBS + // spawn.randomSmallMob(900, -70, 1); + // spawn.randomMob(4300, 95, 1); + // spawn.randomSmallMob(6250, 630, 1); + // spawn.randomMob(6255, -835, 0.9); + // spawn.randomMob(8200, -900, 0.7); + // spawn.randomMob(5700, -270, 0.7); + // spawn.randomMob(8275, -320, 0.7); + // spawn.randomMob(2700, -270, 0.7); + // spawn.randomMob(7575, 950, 0.5); + // spawn.randomMob(7000, -695, 0.4); + // spawn.randomMob(1850, -345, 0.3); + // spawn.randomMob(3600, -270, 0.3); + // spawn.randomMob(1500, -270, 0.2); + // spawn.randomMob(1250, 55, 0.2); + // spawn.randomMob(8800, -45, 0.2); + // spawn.randomGroup(8025, -845, 0.2); + + // if (simulation.difficulty > 2) { + // // if (Math.random() < 0.2) { + // // // tether ball + // // spawn.tetherBoss(8000, 630, { x: 8550, y: 680 }) + // // let me = mob[mob.length - 1]; + // // me.onDeath = function() { //please don't edit the onDeath function this causes serious bugs + // // this.removeCons(); //remove constraint + // // spawnCouloirEnHaut() + // // doorSortieSalle.isClosing = false; + // // }; + // // if (simulation.difficulty > 4) spawn.nodeGroup(8000, 630, "spawns", 8, 20, 105); + // // } else { + // spawn.randomLevelBoss(8000, 630, ["shooterBoss", "launcherBoss", "laserTargetingBoss", "spiderBoss", "laserBoss", "bomberBoss", "orbitalBoss", "pulsarBoss"]); + // spawn.secondaryBossChance(8000, 630) + // //find level boss index + // let me + // for (let i = 0, len = mob.length; i < len; i++) { + // if (mob[i].isBoss) me = mob[i] + // } + // if (me) { + // me.onDeath = function() { //please don't edit the onDeath function this causes serious bugs + // spawnCouloirEnHaut() + // doorSortieSalle.isClosing = false; + // }; + // } else { + // spawnCouloirEnHaut() + // doorSortieSalle.isClosing = false; + // } + // // } + // } else { + // spawn.randomLevelBoss(8000, 630, ["shooterBoss"]); + // let me + // for (let i = 0, len = mob.length; i < len; i++) { + // if (mob[i].isBoss) me = mob[i] + // } + // if (me) { + // me.onDeath = function() { //please don't edit the onDeath function this causes serious bugs + // spawnCouloirEnHaut() + // doorSortieSalle.isClosing = false; + // }; + // } else { + // spawnCouloirEnHaut() + // doorSortieSalle.isClosing = false; + // } + // } + // }, + house() { //by Francois from discord + simulation.inGameConsole(`house by Francois`); + const rotor = level.rotor(4251, -325, 120, 20, 200, 0, 0.01, 0, -0.0001); + const hazard = level.hazard(4350, -1000, 300, 110); + const doorBedroom = level.door(1152, -1150, 25, 250, 250); + const doorGrenier = level.door(1152, -1625, 25, 150, 160); + const buttonBedroom = level.button(1250, -850); + const voletLucarne1 = level.door(1401, -2150, 20, 26, 28); + const voletLucarne2 = level.door(1401, -2125, 20, 26, 53); + const voletLucarne3 = level.door(1401, -2100, 20, 26, 78); + const voletLucarne4 = level.door(1401, -2075, 20, 26, 103); + const voletLucarne5 = level.door(1401, -2050, 20, 26, 128); + const voletLucarne6 = level.door(1401, -2025, 20, 26, 153); + let hasAlreadyBeenActivated = false; + let grd + + level.setPosToSpawn(0, -50); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 3100; + level.exit.y = -2480; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "rgb(170 170 170)" + + level.custom = () => { + ctx.fillStyle = "rgb(221, 221, 221)"; + ctx.fillRect(1175, -1425, 4000, 1200); + ctx.fillStyle = "rgb(170 170 170)"; + ctx.fillRect(1650, -1300, 175, 150); + ctx.fillStyle = "rgb(77, 76, 76)"; + ctx.fillRect(624, -1150, 28, 1075); + ctx.fillStyle = "#ababab"; + ctx.fillRect(3420, -380, 285, 40); + ctx.fillStyle = "#474747"; + ctx.fillRect(3555, -367.5, 15, 15); + ctx.fillRect(3418, -344, 288, 8); + ctx.fillRect(3555, -327.5, 15, 15); + ctx.fillRect(3418, -304, 288, 8); + ctx.fillRect(3555, -285, 15, 15); + ctx.fillStyle = "#ababab"; + ctx.fillRect(3420, -340, 285, 40); + ctx.fillRect(3420, -300, 285, 45); + ctx.fillStyle = "rgba(141, 141, 141,1)"; + ctx.fillRect(3800, -1275, 250, 425); + ctx.fillStyle = "#000"; + ctx.fillRect(3800, -1275, 250, 3); + ctx.fillRect(4048, -1275, 3, 425); + ctx.fillRect(3800, -1275, 3, 425); + ctx.fillRect(3830, -1050, 35, 10); + ctx.fillStyle = "rgba(225, 242, 245,0.6)"; + ctx.fillRect(4050, -1425, 1125, 600); + ctx.fillStyle = "#444"; + ctx.fillRect(1736, -1300, 3, 150); + ctx.fillRect(1650, -1224, 175, 3); + ctx.fillStyle = "#5806ac"; + ctx.fillRect(3375, -625, 375, 175); + ctx.fillStyle = "rgba(166, 166, 166,0.8)"; + ctx.fillRect(4050, -1425, 1, 600); + ctx.fillRect(4090, -1425, 1, 600); + ctx.fillRect(4130, -1425, 1, 600); + ctx.fillRect(4170, -1425, 1, 600); + ctx.fillRect(4210, -1425, 1, 600); + ctx.fillRect(4250, -1425, 1, 600); + ctx.fillRect(4290, -1425, 1, 600); + ctx.fillRect(4330, -1425, 1, 600); + ctx.fillRect(4370, -1425, 1, 600); + ctx.fillRect(4410, -1425, 1, 600); + ctx.fillRect(4450, -1425, 1, 600); + ctx.fillRect(4490, -1425, 1, 600); + ctx.fillRect(4530, -1425, 1, 600); + ctx.fillRect(4570, -1425, 1, 600); + ctx.fillRect(4610, -1425, 1, 600); + ctx.fillRect(4650, -1425, 1, 600); + ctx.fillRect(4690, -1425, 1, 600); + ctx.fillRect(4730, -1425, 1, 600); + ctx.fillRect(4770, -1425, 1, 600); + ctx.fillRect(4810, -1425, 1, 600); + ctx.fillRect(4850, -1425, 1, 600); + ctx.fillRect(4890, -1425, 1, 600); + ctx.fillRect(4930, -1425, 1, 600); + ctx.fillRect(4970, -1425, 1, 600); + ctx.fillRect(5010, -1425, 1, 600); + ctx.fillRect(5050, -1425, 1, 600); + ctx.fillRect(5090, -1425, 1, 600); + ctx.fillRect(5130, -1425, 1, 600); + ctx.fillRect(4050, -1425, 1125, 2); + ctx.fillRect(4050, -1385, 1125, 2); + ctx.fillRect(4050, -1345, 1125, 2); + ctx.fillRect(4050, -1305, 1125, 2); + ctx.fillRect(4050, -1265, 1125, 2); + ctx.fillRect(4050, -1225, 1125, 2); + ctx.fillRect(4050, -1185, 1125, 2); + ctx.fillRect(4050, -1145, 1125, 2); + ctx.fillRect(4050, -1105, 1125, 2); + ctx.fillRect(4050, -1065, 1125, 2); + ctx.fillRect(4050, -1025, 1125, 2); + ctx.fillRect(4050, -985, 1125, 2); + ctx.fillRect(4050, -945, 1125, 2); + ctx.fillRect(4050, -905, 1125, 2); + ctx.fillRect(4050, -865, 1125, 2); + + buttonBedroom.query(); + buttonBedroom.draw(); + if (buttonBedroom.isUp) { + if (hasAlreadyBeenActivated == false) { + doorBedroom.isClosing = true; + doorGrenier.isClosing = true; + voletLucarne1.isClosing = true; + voletLucarne2.isClosing = true; + voletLucarne3.isClosing = true; + voletLucarne4.isClosing = true; + voletLucarne5.isClosing = true; + voletLucarne6.isClosing = true; + } + } else { + doorBedroom.isClosing = false; + doorGrenier.isClosing = false; + voletLucarne1.isClosing = false; + voletLucarne2.isClosing = false; + voletLucarne3.isClosing = false; + voletLucarne4.isClosing = false; + voletLucarne5.isClosing = false; + voletLucarne6.isClosing = false; + if (hasAlreadyBeenActivated == false) { + hasAlreadyBeenActivated = true; + } + } + doorBedroom.openClose(); + doorGrenier.openClose(); + voletLucarne1.openClose(); + voletLucarne2.openClose(); + voletLucarne3.openClose(); + voletLucarne4.openClose(); + voletLucarne5.openClose(); + voletLucarne6.openClose(); + rotor.rotate(); + /// + grd = ctx.createRadialGradient(512.5, -1025, 5, 512.5, -1025, 100); + grd.addColorStop(0, "rgb(255, 199, 43)"); + grd.addColorStop(1, "rgb(170 170 170)"); + ctx.fillStyle = grd; + ctx.fillRect(450, -1025, 125, 100); + /// + grd = ctx.createRadialGradient(762.5, -1025, 5, 762.5, -1025, 100); + grd.addColorStop(0, "rgb(255, 199, 43, 1)"); + grd.addColorStop(1, "rgb(170 170 170)"); + ctx.fillStyle = grd; + ctx.fillRect(700, -1025, 125, 100); + /// + ctx.lineWidth = 7; + ctx.strokeStyle = "#444444" + ctx.strokeRect(1650, -1300, 175, 150); + + chair.force.y += chair.mass * simulation.g; + chair2.force.y += chair2.mass * simulation.g; + person.force.y += person.mass * simulation.g; + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(64,64,64,0.97)"; + ctx.fillRect(2800, -400, 275, 175); + + hazard.query(); + doorBedroom.draw(); + doorGrenier.draw(); + voletLucarne1.draw(); + voletLucarne2.draw(); + voletLucarne3.draw(); + voletLucarne4.draw(); + voletLucarne5.draw(); + voletLucarne6.draw(); + }; + //chairs + const part1 = Matter.Bodies.rectangle(4525, -255, 25, 200, { + density: 0.0005, + isNotHoldable: true, + }); + const part2 = Matter.Bodies.rectangle(4562, -235, 100, 25, { + density: 0.0005, + isNotHoldable: true, + }); + const part3 = Matter.Bodies.rectangle(4600, -202, 25, 91.5, { + density: 0.0005, + isNotHoldable: true, + }); + const part4 = Matter.Bodies.rectangle(5100, -255, 25, 200, { + density: 0.0005, + isNotHoldable: true, + }); + const part5 = Matter.Bodies.rectangle(5063, -235, 100, 25, { + density: 0.0005, + isNotHoldable: true, + }); + const part6 = Matter.Bodies.rectangle(5025, -202, 25, 91.5, { + density: 0.0005, + isNotHoldable: true, + }); + chair = Body.create({ + parts: [part1, part2, part3], + }); + chair2 = Body.create({ + parts: [part4, part5, part6], + }); + Composite.add(engine.world, [chair]); + Composite.add(engine.world, [chair2]); + composite[composite.length] = chair; + composite[composite.length] = chair2; + body[body.length] = part1; + body[body.length] = part2; + body[body.length] = part3; + body[body.length] = part4; + body[body.length] = part5; + body[body.length] = part6; + setTimeout(function () { + chair.collisionFilter.category = cat.body; + chair.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mob | cat.mobBullet | cat.map + }, 1000); + setTimeout(function () { + chair2.collisionFilter.category = cat.body; + chair2.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mob | cat.mobBullet | cat.map + }, 1000); + var head = Matter.Bodies.rectangle(300, -200 - 60, 34, 40, { + isNotHoldable: true, + }); + var chest = Matter.Bodies.rectangle(300, -200, 55, 80, { + isNotHoldable: true, + }); + var rightUpperArm = Matter.Bodies.rectangle(300 + 39, -200 - 15, 20, 40, { + isNotHoldable: true, + }); + var rightLowerArm = Matter.Bodies.rectangle(300 + 39, -200 + 25, 20, 60, { + isNotHoldable: true, + }); + var leftUpperArm = Matter.Bodies.rectangle(300 - 39, -200 - 15, 20, 40, { + isNotHoldable: true, + }); + var leftLowerArm = Matter.Bodies.rectangle(300 - 39, -200 + 25, 20, 60, { + isNotHoldable: true, + }); + var leftUpperLeg = Matter.Bodies.rectangle(300 - 20, -200 + 57, 20, 40, { + isNotHoldable: true, + }); + var leftLowerLeg = Matter.Bodies.rectangle(300 - 20, -200 + 97, 20, 60, { + isNotHoldable: true, + }); + var rightUpperLeg = Matter.Bodies.rectangle(300 + 20, -200 + 57, 20, 40, { + isNotHoldable: true, + }); + var rightLowerLeg = Matter.Bodies.rectangle(300 + 20, -200 + 97, 20, 60, { + isNotHoldable: true, + }); + + //man + var person = Body.create({ + parts: [chest, head, leftLowerArm, leftUpperArm, + rightLowerArm, rightUpperArm, leftLowerLeg, + rightLowerLeg, leftUpperLeg, rightUpperLeg + ], + }); + Composite.add(engine.world, [person]); + composite[composite.length] = person + body[body.length] = chest + body[body.length] = head + body[body.length] = part3 + body[body.length] = leftLowerLeg + body[body.length] = leftUpperLeg + body[body.length] = leftUpperArm + body[body.length] = leftLowerArm + body[body.length] = rightLowerLeg + body[body.length] = rightUpperLeg + body[body.length] = rightLowerArm + body[body.length] = rightUpperArm + setTimeout(function () { + person.collisionFilter.category = cat.body; + person.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mob | cat.mobBullet | cat.map + }, 1000); + + //rez de chaussée + spawn.mapRect(-200, 0, 5400, 100); //ground + spawn.mapRect(1150, -255, 4050, 355); //additionnal ground + spawn.mapRect(800, -255, 400, 90); //1st step + spawn.mapRect(650, -170, 550, 90); //2nd step + spawn.mapRect(500, -85, 700, 90); //3rd step + spawn.mapRect(1150, -850, 50, 175); //porte entrée + spawn.bodyRect(1162.5, -675, 25, 420) //porte entrée + spawn.mapRect(1150, -850, 1500, 50); //plafond 1 + spawn.mapRect(3025, -850, 2175, 50); //plafond 2 + spawn.mapRect(5150, -850, 50, 650); //mur cuisine + //lave-vaisselle + spawn.mapRect(4225, -400, 25, 150); + spawn.mapRect(4225, -400, 175, 25); + spawn.mapRect(4375, -400, 25, 150); + spawn.bodyRect(4350, -350, 20, 40); + spawn.bodyRect(4325, -325, 20, 20); + spawn.bodyRect(4325, -275, 20, 20); + //escalier + spawn.mapRect(3025, -850, 50, 225); + spawn.mapRect(2925, -775, 150, 150); + spawn.mapRect(2800, -700, 275, 75); + spawn.mapRect(2575, -400, 175, 175); + spawn.mapRect(2475, -325, 175, 100); + spawn.mapRect(2675, -475, 400, 100); + spawn.mapRect(2675, -475, 150, 250); + //cuisine + spawn.mapRect(4025, -850, 50, 175); //porte cuisine + spawn.mapRect(4025, -375, 50, 125); //porte cuisine + + map[map.length] = Bodies.polygon(4050, -675, 0, 15); //circle above door + spawn.bodyRect(4040, -650, 20, 260, 1, spawn.propsDoor); // door + body[body.length - 1].isNotHoldable = true; + //makes door swing + consBB[consBB.length] = Constraint.create({ + bodyA: body[body.length - 1], + pointA: { + x: 0, + y: -130 + }, + bodyB: map[map.length - 1], + stiffness: 1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + + //table + chaises + spawn.mapRect(4025, -850, 50, 175); + spawn.mapRect(4650, -375, 325, 25); + spawn.mapRect(4700, -350, 25, 100); + spawn.mapRect(4900, -350, 25, 100); + spawn.bodyRect(4875, -400, 75, 25); + spawn.bodyRect(4700, -400, 75, 25); + + //murs télé + spawn.mapRect(3400, -400, 20, 150); + spawn.mapRect(3705, -400, 20, 150); + spawn.mapRect(3400, -400, 325, 20); + //socle écran + spawn.mapRect(3500, -415, 125, 17); + spawn.mapRect(3550, -450, 25, 50); + // ??? + spawn.bodyRect(3075, -375, 125, 125); + spawn.bodyRect(3075, -400, 50, 25); + spawn.bodyRect(3725, -325, 100, 75); + spawn.bodyRect(3375, -275, 25, 25); + // premier étage + spawn.mapRect(1150, -1450, 4050, 50); + spawn.mapRect(5150, -1450, 50, 650); + spawn.mapRect(1150, -1450, 50, 300); + spawn.mapRect(1150, -900, 50, 100); + spawn.mapVertex(1066, -730, "-200 60 0 -60 100 -60 100 60") + //chambre + spawn.mapRect(2350, -1450, 50, 175); //porte chambre + //lit + spawn.mapRect(1475, -1025, 25, 225); //pied de lit 1 + spawn.mapRect(1850, -925, 25, 125); //pied de lit 2 + spawn.mapRect(1475, -925, 400, 50); //sommier + spawn.bodyRect(1500, -950, 375, 25); //matelat + spawn.bodyRect(1500, -1000, 75, 50); //oreiller + //table + spawn.bodyRect(1950, -1000, 30, 150); //pied table + spawn.bodyRect(2250, -1000, 30, 150); //pied table + spawn.bodyRect(1920, -1025, 390, 25); //table + //salle de bain + spawn.mapRect(4025, -1450, 50, 175); //porte salle de bain + map[map.length] = Bodies.polygon(5050, -925, 0, 35.4); + spawn.mapRect(5015, -960, 125, 40); + spawn.mapRect(5050, -925, 90, 35.4); + spawn.mapVertex(5086.5, -875, "100 60 -30 60 20 0 100 0") + spawn.mapRect(5125, -1070, 15, 120) + spawn.bodyRect(5016, -965, 108, 15) + //baignoire + spawn.mapVertex(4316, -965, "30 100 0 100 -80 -50 30 -50") //bord 1 + spawn.mapVertex(4675, -961.5, "30 100 0 100 0 -50 80 -50") //bord 2 + spawn.mapVertex(4400, -860, "0 -20 -20 20 20 20 0 -20") //pied 1 + spawn.mapVertex(4600, -860, "0 -20 -20 20 20 20 0 -20") //pied 2 + spawn.mapRect(4325, -900, 350, 25); //fond baignoire + spawn.mapRect(4300, -1175, 25, 175); + spawn.mapRect(4300, -1175, 125, 25); + spawn.mapRect(4400, -1175, 25, 50); //pied pommeau de douche + spawn.mapVertex(4412.5, -1105, "-20 -20 -30 40 30 40 20 -20") //pommeau de douche + + //grenier + spawn.mapRect(1150, -1475, 50, 50); + spawn.mapRect(1150, -1800, 50, 175); + spawn.mapRect(5150, -1800, 50, 400); //murs + spawn.mapVertex(1300, -1900, "-150 200 -200 200 50 0 100 0"); + spawn.mapVertex(1800, -2300, "-150 200 -200 200 175 -100 225 -100"); + spawn.mapRect(1390, -2180, 250, 30); //lucarne + spawn.mapVertex(5050, -1900, "150 200 200 200 -50 0 -100 0"); + spawn.mapVertex(4550, -2300, "150 200 200 200 -175 -100 -225 -100"); + spawn.mapRect(4710, -2175, 250, 25); //lucarne 2 + spawn.mapRect(5150, -1450, 200, 50); + //obstacles + spawn.mapRect(3775, -1800, 99, 50); + spawn.mapRect(2425, -2150, 50, 425); + spawn.mapRect(2150, -1775, 325, 50); + spawn.mapRect(3825, -2150, 50, 750); + spawn.mapRect(3826, -2150, 149, 50); + spawn.mapRect(4125, -2150, 149, 50); + spawn.mapRect(4225, -2150, 50, 450); + spawn.mapRect(4225, -1750, 250, 50); + level.chain(2495, -2130, 0, true, 10); + + spawn.bodyRect(2950, -375, 120, 120) //bloc hidden zone + spawn.bodyRect(2350, -1850, 75, 75); + spawn.bodyRect(4275, -1900, 75, 100); + spawn.bodyRect(4825, -1650, 325, 200); + spawn.bodyRect(5025, -1725, 25, 25); + spawn.bodyRect(4900, -1700, 200, 75); + spawn.mapVertex(2950, -2096, "-75 -50 75 -50 75 0 0 100 -75 0") + + /*cheminée + roof*/ + spawn.mapRect(1963, -2450, 2425, 35); + spawn.mapRect(2925, -2900, 125, 480); + spawn.mapRect(2900, -2900, 175, 75); + spawn.mapRect(2900, -2975, 25, 100); + spawn.mapRect(3050, -2975, 25, 100); + spawn.mapRect(2875, -3000, 225, 25); + // lampadaire + jump + spawn.mapRect(1000, -1450, 200, 25); + spawn.mapRect(500, -1150, 275, 25); + spawn.mapRect(750, -1150, 25, 75); + spawn.mapRect(500, -1150, 25, 75); + spawn.mapRect(450, -1075, 125, 50); + spawn.mapRect(700, -1075, 125, 50); + spawn.mapRect(2985, -4600, 0.1, 1700) + + //bodyRects ~= debris + spawn.bodyRect(1740, -475, 80, 220) + spawn.bodyRect(1840, -290, 38, 23) + spawn.bodyRect(1200 + 1475 * Math.random(), -350, 15 + 110 * Math.random(), 15 + 110 * Math.random()); + spawn.bodyRect(1200 + 1475 * Math.random(), -350, 15 + 110 * Math.random(), 15 + 110 * Math.random()); + spawn.bodyRect(3070 + 600 * Math.random(), -1100, 20 + 50 * Math.random(), 150 + 100 * Math.random()) + spawn.bodyRect(3050 + 1000 * Math.random(), -920, 30 + 100 * Math.random(), 15 + 65 * Math.random()); + spawn.bodyRect(1600 + 250 * Math.random(), -1540, 80, 220) //boss room + spawn.debris(3070, -900, 1000, 3); //16 debris per level + spawn.debris(1200, -350, 1475, 4); //16 debris per level + spawn.debris(1250, -1550, 3565, 9); //16 debris per level + + powerUps.chooseRandomPowerUp(2860, -270); + // Mobs + + spawn.randomSmallMob(1385, -600, 1); + spawn.randomSmallMob(5000, -680, 1); + spawn.randomSmallMob(4750, -925, 1); + spawn.randomSmallMob(2300, -1830, 1); + spawn.randomMob(3170, -720, 0.8); + spawn.randomMob(3700, -975, 0.8); + spawn.randomMob(2625, -1150, 0.7); + spawn.randomMob(4175, -750, 0.7); + spawn.randomMob(2100, -370, 0.7); + spawn.randomMob(2000, -1230, 0.7); + spawn.randomMob(4175, -1075, 0.6); + spawn.randomMob(3965, -1650, 0.6) + spawn.randomMob(4650, -1750, 0.6); + spawn.randomMob(830, -1170, 0.5); + spawn.randomGroup(3730, -1100, 0.5); + spawn.randomMob(2650, -2250, 0.3); + spawn.randomMob(1615, -2270, 0.3); + spawn.randomMob(1380, -1280, 0.25); + spawn.randomMob(2280, -650, 0.2); + spawn.randomGroup(2450, -2650, 0.2); + spawn.randomMob(3800, -580, 0.2); + spawn.randomMob(4630, -425, 0.1); + spawn.randomGroup(630, -1300, -0.1); + spawn.randomGroup(3450, -2880, -0.2) + if (simulation.difficulty > 3) { + spawn.secondaryBossChance(3380, -1775) + if (Math.random() < 0.16) { + spawn.tetherBoss(3380, -1775, { x: 3775, y: -1775 }) + } else { + spawn.randomLevelBoss(3100, -1850, ["shooterBoss", "spiderBoss", "launcherBoss", "laserTargetingBoss", "dragonFlyBoss", "laserBoss"]); + } + } + }, + perplex() { //by Oranger from discord + simulation.inGameConsole(`perplex by Oranger`); + document.body.style.backgroundColor = "#dcdcde"; + level.setPosToSpawn(-600, 400); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 550; + level.exit.y = -2730; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + + const portal = level.portal({ //main portals + x: -1000, + y: 50 + }, -Math.PI / 2, { //up + x: 1000, + y: 50 + }, -Math.PI / 2) //up + const portal2 = level.portal({ //portals in upper right corner + x: 1400, + y: -2200 + }, -Math.PI / 2, { //up + x: 1700, + y: -1700 + }, -Math.PI / 2) //up + // rotor(x, y, width, height, density = 0.001, angle = 0, frictionAir = 0.001, angularVelocity = 0, rotationForce = 0.0005) { + const rotor = level.rotor(-600, -1950, 800, 50, 0.001, 0, 0.01, 0, -0.001) + + level.custom = () => { + portal[2].query(true) + portal[3].query(true) + portal2[2].query(true) + portal2[3].query(true) + rotor.rotate(); + + ctx.fillStyle = "#d4f4f4"; + ctx.fillRect(375, -3000, 450, 300); + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + + level.customTopLayer = () => { + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + ctx.fillStyle = "rgba(0,0,0,0.03)"; + ctx.fillRect(-875, -250, 1500, 700); + ctx.fillRect(-925, -505, 930, 255); + ctx.fillStyle = "rgba(0,0,0,0.1)"; + ctx.fillRect(725, -1400, 200, 200); + ctx.fillRect(925, -2150, 150, 2175); + ctx.fillRect(925, -3400, 150, 850); + ctx.fillStyle = "rgba(0,0,0,0.03)"; + ctx.fillRect(1800, -2600, 400, 400); + ctx.fillRect(2200, -2600, 400, 1250); + + }; + + level.defaultZoom = 1700 // 4500 // 1400 + simulation.zoomTransition(level.defaultZoom) + + //section 1: before portals + spawn.mapRect(-925, 450, 1850, 250); //1-1 base + spawn.mapRect(-925, -300, 55, 755); //1 left wall + spawn.mapRect(-875, 50, 1100, 50); //1-1 ceiling + spawn.mapRect(620, -300, 305, 755); //1-1 and 1-2 right wall + spawn.bodyRect(200, 350, 230, 100); + spawn.bodyRect(300, 250, 150, 100); + spawn.mapRect(-875, -300, 580, 50); //1-2 ceiling on left + spawn.mapRect(0, -300, 625, 50); //1-2 ceiling on right + spawn.mapRect(0, -650, 150, 350); //1-3 right wall + spawn.mapRect(-925, -650, 975, 150); //1-3 ceiling + spawn.mapRect(-1280, 100, 205, 150); //1-4 floor + spawn.mapRect(-1280, 245, 360, 455); //bottom left corner + spawn.mapRect(-1600, -200, 200, 50); //1-4 platform 1 + + //section 2: lower central room (gone through main portals 1 time) + spawn.mapRect(920, 245, 160, 455); //below right portal + spawn.mapRect(1075, -300, 500, 1000); //2-1 right floor + spawn.bodyRect(100, -1000, 50, 350); + spawn.bodyRect(100, -1015, 250, 15); + spawn.mapRect(-925, -1600, 100, 1000); //2-2 left wall + spawn.mapRect(725, -2150, 200, 750); //2-2 right wall + spawn.mapRect(725, -1200, 200, 200); //2-2 right wall 2 + spawn.mapRect(300, -1000, 625, 50); //2 central ledge + //shute + spawn.mapRect(1075, -2005, 550, 1055); //shute right wall + spawn.mapRect(875, -1000, 50, 300); //shute left 1 + spawn.mapRect(860, -1030, 50, 300); //shute left 2 + spawn.mapRect(850, -1100, 50, 300); //shute left 3 + spawn.mapRect(830, -980, 50, 50); //shute left 4 + spawn.mapRect(1075, -1000, 50, 300); //shute right 1 + spawn.mapRect(1090, -1030, 50, 300); //shute right 2 + spawn.mapRect(1100, -1100, 50, 300); //shute right 3 + spawn.mapRect(1120, -980, 50, 50); //shute right 4 + spawn.mapRect(1850, -650, 400, 50); //drop from 4-1 + //section 3: upper left room and upper central room (gone through main portals 2 times) + //3-2 is just the upper part of 2-2 + spawn.mapRect(-1775, -1000, 700, 300); //3-1 floor + spawn.mapRect(-1900, -2300, 175, 1600); //3-1 left wall + spawn.mapRect(-1375, -1300, 300, 50); //3-1 platform 1 + spawn.mapRect(-1600, -1650, 300, 50); //3-1 platform 2 + spawn.mapRect(-1775, -2300, 700, 300); //3-1 ceiling + spawn.mapRect(-830, -1600, 300, 50); //3-2 left ledge + spawn.mapRect(250, -2150, 675, 50); //3-2 right ledge + spawn.mapRect(-925, -2300, 100, 300); //3-2 left wall + spawn.mapRect(-600, -2700, 1525, 150); //3-2 ceiling + spawn.mapRect(1075, -2150, 250, 150); //next to upper portal + // level.fill.push({ + // x: -1730, + // y: -2300, + // width: 870, + // height: 1600, + // color: "rgba(0,0,0,0.03)" + // }); + + //section 4: upper right portals + spawn.mapRect(1475, -2700, 150, 700); //4-1 left wall + spawn.mapRect(1775, -1650, 250, 150); //4-1 floor-ish + spawn.mapRect(1575, -1505, 450, 555); //below upper right portal + spawn.mapRect(1800, -2250, 400, 50); //4-1 platform 2 + spawn.bodyRect(2200, -2250, 15, 300); + spawn.mapRect(2200, -1950, 400, 50); //4-1 platform 1 + //spawn.bodyRect(2575, -2600, 25, 650); + spawn.mapRect(2600, -1650, 400, 50); //4-1 platform 0 + spawn.mapRect(2200, -1350, 400, 50); //4-1 platform -1 + spawn.bodyRect(2200, -1900, 15, 550); + spawn.bodyRect(2585, -1650, 15, 300); + + spawn.mapRect(1800, -4200, 800, 1600); //4-2 right wall + spawn.mapRect(800, -4200, 1800, -500); //4-2 ceiling + spawn.mapRect(1075, -3400, 225, 850); //upper shute right wall + spawn.mapRect(800, -3400, 125, 850); //upper shute left wall + + //section 5: after portals (gone through main portals 3 times) + spawn.mapRect(-700, -2700, 100, 450); //5-1 right wall + spawn.mapRect(-1450, -2700, 900, 50); //5-1 ceiling + spawn.mapRect(-925, -2300, 325, 50); //5-1 right floor + spawn.mapRect(-1900, -3000, 450, 50); //stair cover + spawn.bodyRect(-1150, -2950, 150, 250); //5-2 block + + //top left corner stuff + spawn.mapRect(-1900, -2450, 250, 450); // + //exit room + spawn.mapRect(350, -3000, 50, 100); //exit room left wall + spawn.mapRect(350, -3000, 450, -1700); //exit room ceiling + spawn.bodyRect(350, -2900, 50, 50.5); //door + spawn.bodyRect(350, -2850, 50, 50.5); //door + spawn.bodyRect(350, -2800, 50, 50.5); //door + spawn.bodyRect(350, -2750, 50, 50.5); //door + + spawn.debris(-400, 450, 400, 5); //16 debris per level + spawn.debris(-1650, -2300, 250, 4); //16 debris per level + spawn.debris(-750, -650, 750, 3); //16 debris per level + + //mobs + spawn.randomMob(-650, -100, 0.7); //1-2 left + spawn.randomMob(100, -150, 0.3); //1-2 right + spawn.randomMob(-100, -400, 0); //1-3 right + //spawn.randomMob(-1500, -300, 0.3); //1-4 platform + spawn.randomMob(1450, -450, 0); //2-1 right + spawn.randomMob(1700, -800, 1); //2-1 off the edge. chance is 1 because some enemies just fall + spawn.randomGroup(-550, -900, -0.3); //2-2 + spawn.randomMob(-1550, -1800, 0.7); //3-1 upper platform + //spawn.randomMob(-1225, -1400, 0.3); //3-1 lower platform + spawn.randomMob(450, -2350, 0.3); //3-2 right ledge + //spawn.randomMob(1150, -2250, 0); //3-2 far right + spawn.randomGroup(2400, -2300, -0.3); //4-1 floating + spawn.randomMob(2400, -1450, 0); //4-1 platform -1 + spawn.randomMob(2800, -1800, 0.5); //4-1 platform 0 + spawn.randomMob(-1700, -3200, 0.7); //5-2 left platform + spawn.randomMob(-550, -2800, 0.3); //5-2 middle + if (simulation.difficulty > 3) { + if (Math.random() < 0.5) { + spawn.randomLevelBoss(450, -1350, ["shooterBoss", "launcherBoss", "laserTargetingBoss", "streamBoss", "shieldingBoss", "pulsarBoss", "laserBoss"]); + } else { + spawn.randomLevelBoss(-300, -3200, ["shooterBoss", "launcherBoss", "laserTargetingBoss", "streamBoss", "shieldingBoss", "pulsarBoss", "laserBoss"]); + } + } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(7725, 2275) + }, + coliseum() { + simulation.inGameConsole(`coliseum by iNoobBoi`); + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { }; + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#dcdcde"; + //Level + level.setPosToSpawn(200, 50); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + + level.exit.x = 8950; + level.exit.y = 170; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + + //Map + spawn.mapRect(-100, -400, 100, 600); + spawn.mapRect(-100, 100, 700, 100); + spawn.mapRect(500, 100, 100, 1700); + spawn.mapRect(500, 1700, 4000, 100); + spawn.mapRect(4100, 600, 400, 100); + spawn.mapRect(4400, 600, 100, 1600); + spawn.mapRect(4400, 2100, 4300, 100); + spawn.mapRect(8600, 200, 100, 2000); + spawn.mapRect(8600, 200, 700, 100); + spawn.mapRect(9200, -300, 100, 600); + spawn.mapRect(8600, -300, 700, 100); + spawn.mapRect(8600, -700, 100, 500); + spawn.mapRect(4400, -700, 4300, 100); + spawn.mapRect(4400, -700, 100, 900); + spawn.mapRect(-100, -400, 4600, 100); + + //Platforms + spawn.mapRect(1100, 400, 300, 100); + spawn.mapRect(500, 500, 300, 100); + spawn.mapRect(1050, 800, 300, 100); + spawn.mapRect(1770, 1050, 300, 100); + spawn.mapRect(1800, 500, 300, 100); + spawn.mapRect(2550, 900, 300, 100); + spawn.mapRect(2800, 1400, 300, 100); + spawn.mapRect(1250, 1350, 300, 100); + spawn.mapRect(4750, 850, 300, 100); + spawn.mapRect(3200, 1050, 300, 100); + spawn.mapRect(4700, 100, 300, 100); + spawn.mapRect(5350, 0, 300, 100); + spawn.mapRect(3800, 900, 300, 100); + spawn.mapRect(5100, 500, 300, 100); + spawn.mapRect(5900, -300, 300, 100); + spawn.mapRect(6500, -700, 300, 1300); + spawn.mapRect(7900, 0, 300, 100); + spawn.mapRect(8050, 800, 300, 100); + spawn.mapRect(7800, 1900, 300, 100); + spawn.mapRect(8300, 450, 300, 100); + spawn.mapRect(8400, 1200, 300, 100); + spawn.mapRect(7570, 1100, 300, 100); + spawn.mapRect(6700, 1850, 300, 100); + spawn.mapRect(8000, 1500, 300, 100); + spawn.mapRect(7120, -100, 300, 100); + spawn.mapRect(7000, 1500, 300, 100); + spawn.mapRect(6500, 1000, 300, 1200); + spawn.mapRect(5800, 1100, 300, 100); + spawn.mapRect(5900, 1700, 300, 100); + spawn.mapRect(5300, 1400, 300, 100); + spawn.mapRect(5200, 1100, 300, 100); + spawn.mapRect(6700, 1100, 300, 100); + spawn.mapRect(4800, 1650, 300, 100); + + //Room 1 Spawning + spawn.randomMob(1000, 700, 0.7); + spawn.randomGroup(1100, 700, 0.5); + spawn.randomMob(1900, 400, 0.7); + spawn.randomGroup(2000, 400, 0.4); + spawn.randomGroup(1800, 1100, 0.4); + spawn.randomGroup(2700, 700, 0.5); + spawn.randomMob(2900, 1200, 0.7); + spawn.randomSmallMob(3200, 300, 0.9); + spawn.randomSmallMob(3700, 800, 0.9); + spawn.randomMob(1100, 700, 0.6); + spawn.randomGroup(1200, 700, 0.5); + spawn.randomMob(2000, 400, 0.8); + spawn.randomGroup(2100, 400, 0.5); + spawn.randomGroup(1900, 1100, 0.5); + spawn.randomGroup(2800, 700, 0.5); + spawn.randomMob(3000, 1200, 0.7); + spawn.randomSmallMob(3200, 300, 0.9); + spawn.randomSmallMob(3700, 800, 0.9); + spawn.randomMob(800, 1500, 0.9); + spawn.randomMob(1500, 1500, 0.7); + spawn.randomMob(2200, 1500, 0.6); + spawn.randomMob(2500, 1500, 0.7); + spawn.randomMob(2800, 1500, 0.7); + spawn.randomMob(3300, 1500, 0.6); + + //Room 2 Spawning + spawn.randomGroup(4700, 2000, 0.9); + spawn.randomMob(5000, 2000, 0.5); + spawn.randomSmallMob(5700, 1500, 0.9); + spawn.randomMob(8500, 2000, 0.6); + spawn.randomGroup(8000, 1300, 0.9); + spawn.randomMob(8300, -300, 0.4); + spawn.randomSmallMob(7600, -200, 0.9); + spawn.randomMob(5200, -300, 0.5); + spawn.randomSmallMob(4700, -200, 0.5); + spawn.randomGroup(4700, 2000, 0.8); + spawn.randomMob(5000, 2000, 0.5); + spawn.randomSmallMob(5700, 1500, 0.9); + spawn.randomGroup(8500, 2000, 0.3); + spawn.randomSmallMob(8000, 1300, 0.4); + spawn.randomMob(8300, -300, 0.3); + spawn.randomGroup(7600, -200, 0.5); + spawn.randomMob(5200, -300, 0.3); + spawn.randomGroup(4700, -200, 0.4); + spawn.randomGroup(8650, -200, 0.9); //end guards + spawn.randomMob(8650, -200, 0.9); //end guards + + + //Boss Spawning + if (simulation.difficulty > 3) { + spawn.randomLevelBoss(6000, 700, ["pulsarBoss", "laserTargetingBoss", "powerUpBoss", "bomberBoss", "historyBoss", "orbitalBoss"]); + // if (simulation.difficulty > 10) spawn.shieldingBoss(7200, 500); + // if (simulation.difficulty > 20) spawn.randomLevelBoss(2000, 300, ["historyBoss", "shooterBoss"]); + } + + //Blocks + spawn.bodyRect(550, -300, 50, 400); //spawn door + spawn.bodyRect(4400, 200, 100, 400); //boss door + spawn.bodyRect(6600, 600, 50, 400); //boss 2 door + spawn.debris(400, 800, 400, 2); + spawn.debris(3800, 1600, 1200, 6); + spawn.debris(7500, 2000, 800, 4); + spawn.debris(5500, 2000, 800, 4); + + //Powerups + powerUps.spawnStartingPowerUps(1250, 1500); + // powerUps.spawnStartingPowerUps(1500, 1500); + powerUps.spawn(8650, -200, "ammo"); + // powerUps.spawn(8650, -200, "ammo"); + // powerUps.spawn(8650, -200, "ammo"); + // powerUps.spawn(8650, -200, "ammo"); + powerUps.spawn(200, 50, "heal"); + // powerUps.spawn(200, 50, "ammo"); + // powerUps.spawn(200, 50, "ammo"); + // powerUps.spawn(200, 50, "ammo"); + + powerUps.addResearchToLevel() //needs to run after mobs are spawned + spawn.secondaryBossChance(6600, 600) + }, + crossfire() { + simulation.inGameConsole(`crossfire by iNoobBoi`); + + //*1.5 + //Level Setup + const slimePitOne = level.hazard(0, 850, 3800, 120); + const slimePitTwo = level.hazard(4600, 430, 2000, 120); + const slimePitThree = level.hazard(6500, 200, 1000, 170); + + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { + slimePitOne.query(); + slimePitTwo.query(); + slimePitThree.query(); + }; + + level.setPosToSpawn(-500, 550); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + + level.exit.x = 10300; + level.exit.y = -830; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + + level.defaultZoom = 3000 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#dcdcde"; + + //Map Elements + spawn.mapRect(-800, -600, 800, 200); + spawn.mapRect(-200, -600, 200, 800); + spawn.mapRect(-800, -600, 200, 800); + spawn.mapRect(-1000, 0, 1000, 200); + spawn.mapRect(-1000, 0, 200, 800); + spawn.mapRect(-1000, 600, 1400, 200); + spawn.mapRect(0, 600, 200, 400); + spawn.mapRect(0, 950, 4000, 100); + spawn.mapRect(800, 800, 600, 200); + spawn.mapRect(1700, 700, 500, 300); + spawn.mapRect(2500, 600, 400, 400); + spawn.mapRect(3200, 600, 1200, 200); + spawn.mapRect(3800, 600, 200, 800); // + spawn.mapRect(3800, 1200, 800, 200); + spawn.mapRect(4400, 400, 300, 1000); + spawn.mapRect(4400, 500, 2000, 100); + spawn.mapRect(6500, 300, 1000, 100); + spawn.mapRect(5000, 200, 700, 400); + spawn.mapRect(6000, 0, 650, 600); + spawn.mapRect(6900, -300, 700, 100); + spawn.mapRect(7400, -600, 200, 1100); + spawn.mapRect(7400, 300, 2600, 200); + spawn.mapRect(9800, -800, 200, 1300); + spawn.mapRect(9800, -800, 1000, 200); + spawn.mapRect(10600, -1400, 200, 800); + spawn.mapRect(9800, -1400, 200, 400); + spawn.mapRect(7400, -1400, 3400, 200); + spawn.mapRect(7400, -1600, 200, 800); + spawn.mapRect(5400, -1600, 2200, 200); + spawn.mapRect(6000, -1600, 200, 800); + spawn.mapRect(5400, -1600, 200, 800); + spawn.mapRect(4800, -1000, 1400, 200); + spawn.mapRect(4800, -1000, 200, 600); + spawn.mapRect(3800, -600, 1200, 200); + spawn.mapRect(3200, -800, 800, 200); + spawn.mapRect(3200, -800, 200, 800); + spawn.mapRect(3800, -800, 200, 800); + spawn.mapRect(-200, -200, 4200, 200); + + //Boss Room Platforms + spawn.mapRect(7700, 100, 300, 40); + spawn.mapRect(8600, 0, 300, 40); + spawn.mapRect(9200, 100, 300, 40); + spawn.mapRect(9400, -200, 300, 40); + spawn.mapRect(8000, -200, 300, 40); + spawn.mapRect(8500, -400, 300, 40); + spawn.mapRect(9000, -600, 300, 40); + spawn.mapRect(9400, -800, 300, 40); + spawn.mapRect(8600, -1000, 300, 40); + spawn.mapRect(7900, -800, 300, 40); + + //Mob Spawning + spawn.randomMob(200, 400, 0.7); + // spawn.randomMob(1200, 400, 0.7); + spawn.randomMob(2000, 400, 0.7); + // spawn.randomMob(3000, 400, 0.7); + spawn.randomMob(5000, 0, 0.7); + spawn.randomMob(5600, 0, 0.7); + spawn.randomMob(6200, -200, 0.7); + // spawn.randomMob(6600, -200, 0.7); + spawn.randomMob(7200, -800, 0.7); + spawn.randomSmallMob(800, 400, 0.9); + spawn.randomSmallMob(1800, 400, 0.9); + // spawn.randomSmallMob(2600, 400, 0.9); + spawn.randomSmallMob(5200, 0, 0.9); + // spawn.randomSmallMob(5400, 0, 0.9); + spawn.randomSmallMob(6400, -200, 0.9); + spawn.randomGroup(3800, 400, 0.5); + spawn.randomGroup(4200, 400, 0.5); + // spawn.randomGroup(4400, 200, 0.5); + spawn.randomGroup(7000, -800, 0.5); + // spawn.randomGroup(7700, 300, 0.5); + spawn.randomGroup(9800, 300, 0.5); + // spawn.randomGroup(7700, -1100, 0.5); + spawn.randomGroup(9800, -1100, 0.5); + + if (simulation.difficulty > 3) spawn.randomLevelBoss(8600, -600, ["powerUpBoss", "bomberBoss", "dragonFlyBoss", "spiderBoss", "historyBoss"]) + spawn.secondaryBossChance(7900, -400) + + //Boss Spawning + if (simulation.difficulty > 10) { + spawn.pulsarBoss(3600, -400); + powerUps.chooseRandomPowerUp(4006, 400); + powerUps.chooseRandomPowerUp(4407, 400); + powerUps.spawnStartingPowerUps(4400, 400); + if (simulation.difficulty > 30) { + powerUps.chooseRandomPowerUp(4002, 400); + powerUps.chooseRandomPowerUp(4004, 400); + spawn.pulsarBoss(4200, 1000); + if (simulation.difficulty > 60) { + powerUps.chooseRandomPowerUp(4409, 400); + spawn.pulsarBoss(5800, -1200); + if (simulation.difficulty > 80) { + spawn.pulsarBoss(-400, -200); + if (simulation.difficulty > 100) { + spawn.pulsarBoss(3600, -400); + if (simulation.difficulty > 120) { + spawn.pulsarBoss(-400, -200); + } + } + } + } + } + } + + //Powerup Spawning + powerUps.spawnStartingPowerUps(4000, 400); + powerUps.addResearchToLevel(); //needs to run after mobs are spawned + + //Block Spawning + // spawn.bodyRect(-100, 200, 100, 400); //spawn door + spawn.bodyRect(7450, -800, 25, 200); //boss room door + spawn.bodyRect(9850, -1000, 25, 200); //end door + spawn.mapRect(-200, 350, 200, 450); + + // spawn.mapRect(3875, -75, 50, 575); + spawn.mapRect(3800, -75, 200, 525); + spawn.mapRect(3875, 590, 50, 150); + spawn.mapRect(3875, 350, 50, 140); + + const debrisCount = 3 + spawn.debris(1050, 700, 400, debrisCount); + spawn.debris(1900, 600, 400, debrisCount); + spawn.debris(2700, 500, 400, debrisCount); + // spawn.debris(3500, 450, 400, debrisCount); + spawn.debris(4150, 500, 400, debrisCount); + spawn.debris(5300, 0, 400, debrisCount); + spawn.debris(6300, -100, 400, debrisCount); + spawn.debris(7200, -500, 400, debrisCount); + spawn.debris(8000, -600, 400, debrisCount); + spawn.debris(8700, -700, 400, debrisCount); + spawn.debris(9300, -900, 400, debrisCount); + }, + vats() { // Made by Dablux#6610 on Discord + simulation.inGameConsole(`vats by Dablux`); + level.defaultZoom = 1500 + simulation.zoomTransition(level.defaultZoom) + level.setPosToSpawn(4400, -1060) + spawn.mapRect(level.enter.x, level.enter.y + 30, 100, 20) + level.exit.x = 3900; + level.exit.y = 1060; + spawn.mapRect(level.exit.x, level.exit.y + 30, 100, 20) + document.body.style.backgroundColor = "#dcdcde"; + + var nextBlockSpawn = simulation.cycle + Math.floor(Math.random() * 60 + 30) + const door = level.door(475, 900, 50, 200, 201) + const exitDoor = level.door(3375, 900, 50, 200, 201) + const deliveryButton = level.button(3500, -410) + const buttonGreen = level.button(-1600, 1090) + const buttonYellow = level.button(-1600, -1160) + const buttonRed = level.button(5874, -2410) + let g = false; + let y = false; + let r = false; + const deliverySlime = level.hazard(3700, -940, 100, 480) + const deliverySlime2 = level.hazard(3700, -461, 100, 1141) + const slimePit = level.hazard(700, 1200, 2500, 1300, 0.004) + const topSlime = level.hazard(800, -460, 2900, 90, 0.004) + // const rotor = level.rotor(0, -725, 0.001) + const rotor = level.rotor(-400, -725, 800, 50, 0.001, 0, 0.01, 0, 0.001) + + + const portal = level.portal({ + x: -135, + y: 800 + }, Math.PI / 2, { + x: 570, + y: -395 + }, -Math.PI / 2) + const portal2 = level.portal({ + x: -1800, + y: 1900 + }, Math.PI, { + x: 200, + y: 1105 + }, -Math.PI / 2) + const drip1 = level.drip(1875, -660, -400, 70) + const drip2 = level.drip(3525, -940, -400, 150) + const drip3 = level.drip(1975, 100, 1200, 100) + door.isClosing = true; + exitDoor.isClosing = true; + + // UPPER AREA // + spawn.mapRect(4500, -2400, 1700, 2050) + spawn.mapRect(3800, -1000, 700, 650) + spawn.mapRect(4000, -1310, 50, 60) + spawn.mapRect(4450, -1310, 50, 60) + spawn.mapRect(4000, -1320, 500, 20) + level.chain(4025, -1225, 0.5 * Math.PI, false, 5, 25) + spawn.mapRect(3650, -460, 50, 90) + spawn.mapRect(3525, -1000, 325, 20) + spawn.mapRect(3650, -1000, 50, 440) + spawn.mapRect(3300, -1000, 50, 450) + spawn.mapRect(3325, -725, 150, 25) + spawn.mapRect(3500, -980, 175, 35) + spawn.mapRect(3325, -980, 50, 35) + spawn.mapRect(-1800, -1250, 50, 120) + spawn.mapRect(6150, -2500, 50, 120) + spawn.bodyRect(3350, -1000, 175, 20, 1, spawn.propsIsNotHoldable) // Cover + Matter.Body.setMass(body[body.length - 1], 0.7) // Make cover easier to remove + spawn.mapRect(750, -475, 50, 75); + for (let i = 1; i < 5; i++) { + spawn.mapRect(800 + (i * 100) + (500 * (i - 1)), -460 + (i * -120) + (20 * (i - 1)), 500, 20) + } + + // ARENA // + spawn.mapRect(400, -400, 2950, 500) + spawn.mapRect(-1800, -1150, 1800, 1950) + spawn.mapRect(-1800, 1100, 780, 1800) + spawn.mapRect(-300, 1100, 1000, 1800) + //spawn.mapRect(-1800, -1450, 100, 2000) + spawn.blockDoor(-1800, 1070) + level.chain(-1000, 1120, 0, true, 18, 20) + spawn.mapRect(700, 2500, 2500, 900) + spawn.mapRect(400, 100, 200, 599) + spawn.mapRect(400, 650, 75, 250) + spawn.mapRect(525, 650, 75, 250) + spawn.mapRect(3300, 650, 75, 250) + spawn.mapRect(3425, 650, 75, 250) + spawn.mapRect(3200, 1100, 1800, 2200) + spawn.mapRect(3300, -400, 200, 1099) // STOP CHANGING THIS ONE!!!! + spawn.mapRect(3450, -400, 250, 1100) + spawn.mapRect(3650, 680, 200, 20) + spawn.mapRect(3800, -400, 1400, 1100) + spawn.mapRect(4100, 700, 100, 300) + spawn.mapRect(4900, -400, 1300, 2500) + spawn.bodyRect(4100, 1000, 100, 100) + + spawn.bodyRect(-2100, 2050, 290, 30) //Portal platform + let b = body[body.length - 1]; + b.isNotHoldable = true + cons[cons.length] = Constraint.create({ + pointA: { + x: -1820, + y: 2065 + }, + bodyB: b, + pointB: { + x: -135, + y: 0 + }, + stiffness: 1, + length: 1 + }); + cons[cons.length] = Constraint.create({ + pointA: { + x: -1800, + y: 1400 + }, + bodyB: b, + pointB: { + x: 135, + y: 0 + }, + stiffness: 0.005, + length: 700 + }); + Composite.add(engine.world, [cons[cons.length - 2], cons[cons.length - 1]]); + + spawn.bodyRect(5225, -2525, 300, 75); + spawn.bodyRect(4700, -2525, 100, 75, 0.5); + spawn.bodyRect(4900, -2600, 50, 50, 0.4); + spawn.bodyRect(5050, -2475, 500, 100, 0.4); + spawn.bodyRect(2950, -950, 175, 75, 0.5); + spawn.bodyRect(3050, -1000, 75, 50, 0.3); + spawn.bodyRect(2300, -850, 75, 50, 0.7); + spawn.bodyRect(2150, -575, 100, 175, 0.6); + spawn.bodyRect(2500, -550, 400, 150, 0.2); + spawn.bodyRect(1525, -500, 225, 100, 0.2); + spawn.bodyRect(1625, -575, 100, 75); + spawn.bodyRect(1000, -475, 100, 100, 0.8); + spawn.bodyRect(1225, -450, 125, 50, 0.9); + spawn.bodyRect(525, -500, 175, 125, 0.75); + spawn.bodyRect(575, -600, 100, 75, 0.5); + spawn.bodyRect(-925, -1225, 275, 75, 0.4); + spawn.bodyRect(-1125, -1300, 200, 150, 0.7); + spawn.bodyRect(-475, -1250, 200, 100, 0.8); + spawn.bodyRect(-425, -1300, 100, 50, 0.75); + spawn.bodyRect(-1225, -1200, 100, 25, 0.45); + spawn.bodyRect(-1025, -1350, 75, 50, 0.5); + spawn.bodyRect(-450, 1025, 75, 50, 0.5); + spawn.bodyRect(-775, 1050, 50, 50, 0.6); + spawn.bodyRect(-650, 975, 75, 75, 0.2); + spawn.bodyRect(-475, 1025, 100, 50, 0.7); + spawn.bodyRect(-450, 1025, 75, 50, 0.6); + spawn.bodyRect(-800, 1050, 100, 50, 0.5); + spawn.bodyRect(-600, 950, 75, 75, 0.3); + spawn.bodyRect(-500, 1000, 75, 25, 0.2); + spawn.bodyRect(-900, 1025, 150, 50); + spawn.bodyRect(-1350, 1000, 100, 100, 0.4); + spawn.bodyRect(-1225, 1075, 100, 25); + spawn.debris(900, -1000, 2000, 16); + + // MOBS // + spawn.randomSmallMob(2900, -1000) + spawn.randomSmallMob(1750, -700) + spawn.randomMob(4250, -1400) + spawn.randomMob(4800, -2400, 0.3) + spawn.randomMob(1000, 600, 0.3) + spawn.randomMob(1650, 950, 0.2) + spawn.randomMob(1300, -1250, 0) + spawn.randomMob(-600, -1250, 0.1) + spawn.randomMob(1000, -600, 0.4) + spawn.randomMob(1800, -700, 0.4) + spawn.randomMob(2200, 950, 0.2) + spawn.randomMob(-1900, 1400, 0.3) + spawn.randomMob(-750, -1000, 0.3) + spawn.randomMob(3250, 1000, 0.1) + spawn.randomMob(2000, -2800, 0.4) + spawn.randomMob(2200, -500, 0) + spawn.randomMob(1800, -450, 0.3) + spawn.randomGroup(2300, -450, 1) + spawn.randomGroup(3000, -450, 0.3) + spawn.randomGroup(6000, -2700, 0) + spawn.randomGroup(-1200, -1300, -0.3) + powerUps.addResearchToLevel() + + if (simulation.difficulty > 3) { + spawn.randomLevelBoss(1900, 400, ["shieldingBoss", "shooterBoss", "launcherBoss", "streamBoss"]) + } else { + exitDoor.isClosing = false; + } + spawn.secondaryBossChance(800, -800) + + powerUps.spawn(4450, 1050, "heal"); + if (Math.random() > (0.2 + (simulation.difficulty / 60))) { + powerUps.spawn(4500, 1050, "ammo"); + powerUps.spawn(4550, 1050, "ammo"); + } else { + powerUps.spawn(4500, 1050, "tech"); + spawn.randomMob(4550, 1050, Infinity); + } + powerUps.spawnStartingPowerUps(3750, -940) + + const W = 500; + const H = 20; + for (let i = 1; i < 5; i++) { + spawn.bodyRect(700 + (i * 100) + (W * (i - 1)), 1110, W, H, 1, spawn.propsIsNotHoldable) + let b = body[body.length - 1]; + cons[cons.length] = Constraint.create({ + pointA: { + x: b.position.x - (W / 2) + 50, + y: b.position.y - 1025 + }, + bodyB: b, + pointB: { + x: -(W / 2) + 50, + y: 0 + }, + stiffness: 0.002, + length: 1000 + }); + cons[cons.length] = Constraint.create({ + pointA: { + x: b.position.x + (W / 2) - 50, + y: b.position.y - 1025 + }, + bodyB: b, + pointB: { + x: (W / 2) - 50, + y: 0 + }, + stiffness: 0.002, + length: 1000 + }); + Composite.add(engine.world, [cons[cons.length - 1], cons[cons.length - 2]]) + } + const boost1 = level.boost(4400, -1385, 1200) + + level.custom = () => { + boost1.query(); + buttonGreen.query() + buttonYellow.query() + buttonRed.query() + + if (!buttonGreen.isUp) { + if (!g) { + Matter.Composite.remove(engine.world, cons[1]) + cons.splice(1, 2) + } + g = true; + } + if (!buttonYellow.isUp) { + y = true; + } + if (!buttonRed.isUp) { + r = true; + } + + if (g && y && r) { + door.isClosing = false; + } else { + door.isClosing = true; + } + + door.openClose() + exitDoor.openClose() + + if (m.pos.y > 1600 && 700 < m.pos.x && m.pos.x < 3200) { // Saving player from slime pit + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 200, + y: 1000 + }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + m.damage(0.1 * simulation.difficultyMode) + m.energy -= 0.1 * simulation.difficultyMode + } + + if (simulation.cycle >= nextBlockSpawn && body.length < 100) { + var len = body.length; + body[len] = Matter.Bodies.polygon(Math.floor(Math.random() * 1700) + 1050, 100, Math.floor(Math.random() * 11) + 10, Math.floor(Math.random() * 20) + 15) + body[len].collisionFilter.category = cat.body; + body[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet; + Composite.add(engine.world, body[len]) + nextBlockSpawn = simulation.cycle + Math.floor(Math.random() * 60 + 30) + } + + if (exitDoor.isClosing) { + exitDoor.isClosing = false; + for (i = 0; i < mob.length; i++) { + if (mob[i].isBoss && 525 < mob[i].position.x < 3200 && -2500 < mob[i].position.y < 100) { + exitDoor.isClosing = true; + } + } + } + + for (let i = 0, len = body.length; i < len; i++) { + if (body[i].position.x > 700 && body[i].position.x < 3200 && body[i].position.y > 1200 && !body[i].isNotHoldable) { + Matter.Body.scale(body[i], 0.99, 0.99); + if (body[i].velocity.y > 3) body[i].force.y -= 0.96 * body[i].mass * simulation.g + const slowY = (body[i].velocity.y > 0) ? Math.max(0.3, 1 - 0.0015 * body[i].velocity.y * body[i].velocity.y) : Math.max(0.98, 1 - 0.001 * Math.abs(body[i].velocity.y)) //down : up + Matter.Body.setVelocity(body[i], { + x: Math.max(0.6, 1 - 0.07 * Math.abs(body[i].velocity.x)) * body[i].velocity.x, + y: slowY * body[i].velocity.y + }); + if (body[i].mass < 0.05) { + Matter.Composite.remove(engine.world, body[i]) + body.splice(i, 1) + break + } + } + } + + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].position.x > 700 && mob[i].position.x < 3200 && mob[i].alive && !mob[i].isShielded && mob[i].position.y > 1200) { + mobs.statusDoT(mob[i], 0.005, 30) + } + } + + ctx.beginPath() + ctx.fillStyle = "#666"; + ctx.arc(buttonGreen.min.x - 50, buttonGreen.min.y - 70, 20, 0, 2 * Math.PI) + ctx.fillRect(buttonGreen.min.x - 55, buttonGreen.max.y + 25, 10, -95) + ctx.fill() + ctx.beginPath() + ctx.arc(buttonYellow.min.x - 50, buttonYellow.min.y - 70, 20, 0, 2 * Math.PI) + ctx.fillRect(buttonYellow.min.x - 55, buttonYellow.max.y + 25, 10, -95) + ctx.fill() + ctx.beginPath() + ctx.arc(buttonRed.min.x - 50, buttonRed.min.y - 70, 20, 0, 2 * Math.PI) + ctx.fillRect(buttonRed.min.x - 55, buttonRed.max.y + 25, 10, -95) + ctx.fill() + + ctx.beginPath() + ctx.arc(buttonGreen.min.x - 50, buttonGreen.min.y - 70, 10, 0, 2 * Math.PI) + ctx.fillStyle = (g ? `rgba(0, 255, 0, 0.9)` : `rgba(255, 0, 0, 0.9)`); + ctx.fill() + ctx.beginPath() + ctx.arc(buttonYellow.min.x - 50, buttonYellow.min.y - 70, 10, 0, 2 * Math.PI) + ctx.fillStyle = (y ? `rgba(0, 255, 0, 0.9)` : `rgba(255, 0, 0, 0.9)`); + ctx.fill() + ctx.beginPath() + ctx.arc(buttonRed.min.x - 50, buttonRed.min.y - 70, 10, 0, 2 * Math.PI) + ctx.fillStyle = (r ? `rgba(0, 255, 0, 0.9)` : `rgba(255, 0, 0, 0.9)`); + ctx.fill() + + slimePit.query(); + ctx.shadowColor = 'hsla(160, 100%, 50%, 1)' + ctx.shadowBlur = 100; + // slimePit.draw() + ctx.shadowBlur = 0; + ctx.shadowColor = 'rgba(0, 0, 0, 0)' + + deliveryButton.query() + portal[2].query() + //portal[3].query() + portal2[2].query() + //portal2[3].query() + + deliverySlime.level(deliveryButton.isUp) + topSlime.level(!r) + rotor.rotate() + + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(3500, 675, 600, 450) + level.enter.draw() + level.exit.drawAndCheck() + } + + level.customTopLayer = () => { + topSlime.query(); + deliverySlime.query() + deliverySlime2.query() + drip1.draw() + drip2.draw() + drip3.draw() + + ctx.fillStyle = `rgba(68, 68, 68, ${Math.max(0.3, Math.min((4200 - m.pos.x) / 100, 0.99))})` + ctx.fillRect(4100, 650, 850, 500) + + ctx.fillStyle = "rgba(0,20,40,0.1)" + ctx.fillRect(4025, -1300, 475, 300) + ctx.fillRect(3325, -1000, 375, 600) + ctx.fillRect(425, 100, 3050, 2400) + ctx.fillRect(-1775, 800, 1750, 2100) + ctx.fillStyle = "rgba(0,20,40,0.2)" + ctx.fillRect(2725, -860, 450, 460) + ctx.fillRect(2125, -760, 450, 360) + ctx.fillRect(1525, -660, 450, 260) + ctx.fillRect(925, -560, 450, 160) + ctx.fillRect(3700, -980, 100, 1200) + + ctx.fillStyle = `#444`; + ctx.fillRect(465, 690, 70, 209) + ctx.fillRect(3365, 690, 70, 209) + + ctx.beginPath() + ctx.arc(500, 870, 20, 0, 2 * Math.PI) + ctx.arc(500, 820, 20, 0, 2 * Math.PI) + ctx.arc(500, 770, 20, 0, 2 * Math.PI) + ctx.fillStyle = "rgba(0, 0, 0, 0.3"; + ctx.fill() + + ctx.beginPath() + ctx.arc(500, 870, 10, 0, 2 * Math.PI) + ctx.fillStyle = (g ? `rgba(0, 255, 0, 0.9)` : `rgba(255, 0, 0, 0.9)`); + ctx.fill() + ctx.beginPath() + ctx.arc(500, 820, 10, 0, 2 * Math.PI) + ctx.fillStyle = (y ? `rgba(0, 255, 0, 0.9)` : `rgba(255, 0, 0, 0.9)`); + ctx.fill() + ctx.beginPath() + ctx.arc(500, 770, 10, 0, 2 * Math.PI) + ctx.fillStyle = (r ? `rgba(0, 255, 0, 0.9)` : `rgba(255, 0, 0, 0.9)`); + ctx.fill() + + deliveryButton.draw() + // deliverySlime.draw() + // deliverySlime2.draw() + // topSlime.draw() + buttonGreen.draw() + buttonYellow.draw() + buttonRed.draw() + portal[0].draw() + portal[2].draw() + portal2[0].draw() + portal2[2].draw() + } + }, + ngon() { //make by Oranger + simulation.inGameConsole(`"ngon" by Oranger`); + + document.body.style.backgroundColor = "#dcdcde"; + let needGravity = []; + let s = { //mech statue + x: -200, + y: -2350, + angle: 0, + scale: 15, + h: { //hip + x: 12, + y: 24 + }, + k: { //knee + x: -30.96, //-17.38 + y: 58.34, //70.49 + //x2: -33.96, //x - 3 + //y2: 58.34 //same as y + }, + f: { //foot + x: 0, + y: 91 //112 + }, + fillColor: "#ccc", //white + fillColorDark: "#bbb", //25% from white + lineColor: "#999", //#333 + lineColorLight: "#aaa" //#4a4a4a + } + const boost1 = level.boost(2550, 1500, 1700) + const boost2 = level.boost(-3400, -2050, 2100) + + level.custom = () => { + boost1.query(); + boost2.query(); + + level.exit.drawAndCheck(); + + level.enter.draw(); + for (let i = 0; i < needGravity.length; i++) { + needGravity[i].force.y += needGravity[i].mass * simulation.g; + } + ctx.fillStyle = "#444" //light fixtures + ctx.fillRect(2350, 995, 40, 10) + //ctx.fillRect(2280, -6005, 40, 10) + + //statue + ctx.save(); + ctx.translate(s.x, s.y); + //statueLeg is at the bottom, below the enemies but above the NGON function + statueLeg(-3, s.lineColorLight); + statueLeg(0, s.lineColor); + //head + ctx.rotate(s.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30 * s.scale, 0, 2 * Math.PI); + let grd = ctx.createLinearGradient(-30 * s.scale, 0, 30 * s.scale, 0); + grd.addColorStop(0, s.fillColorDark); + grd.addColorStop(1, s.fillColor); + ctx.fillStyle = grd; + ctx.fill(); + ctx.arc(15 * s.scale, 0, 4 * s.scale, 0, 2 * Math.PI); + ctx.strokeStyle = s.lineColor; + ctx.lineWidth = 2 * s.scale; + ctx.stroke(); + ctx.restore(); + }; + + level.customTopLayer = () => { + //boost chute for lack of a better name + ctx.fillStyle = "rgba(60,60,60,0.9)"; + ctx.fillRect(-3451, -4000, 202, 1500); + ctx.fillRect(2499, -170, 202, 1170); + + ctx.fillStyle = "rgba(0,0,0,0.2)"; + ctx.beginPath(); //basement + ctx.moveTo(2360, 1000); + ctx.lineTo(2120, 900); + ctx.lineTo(1500, 900); + ctx.lineTo(1500, 1500); + ctx.lineTo(3000, 1500); + ctx.lineTo(3000, 1000); + ctx.lineTo(2380, 1000); + ctx.lineTo(2870, 1500); + ctx.lineTo(1870, 1500); + ctx.lineTo(2360, 1000); + ctx.fill(); + // ctx.beginPath(); //exit + // ctx.moveTo(1600, -6000); + // ctx.lineTo(1600, -5000); + // ctx.lineTo(3000, -5000); + // ctx.lineTo(3000, -6000); + // ctx.lineTo(2310, -6000); + // ctx.lineTo(2600, -5000); + // ctx.lineTo(2000, -5000); + // ctx.lineTo(2290, -6000); + // ctx.lineTo(1600, -6000); + // ctx.fill(); + + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ctx.fillRect(1600, -1000, 1400, 830); + ctx.fillRect(1600, -170, 520, 170); + ctx.fillRect(-1300, -200, 2200, 200); //statue base + ctx.fillRect(-800, -400, 1200, 200); + ctx.fillRect(-500, -700, 600, 300); + //ctx.fillRect(-4000, -6000, 2000, 1000); //left side + ctx.fillRect(-4000, -2500, 2000, 2500); + }; + + level.setPosToSpawn(1810, 1450); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 2700; + level.exit.y = -4030; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + level.defaultZoom = 3500 + simulation.zoomTransition(level.defaultZoom) + + // powerUps.spawnStartingPowerUps(1475, -1175); + spawn.debris(2750, 1500, 200, 4); //16 debris per level + spawn.debris(1770, -350, 120, 4); //16 debris per level + spawn.debris(-3200, 0, 1000, 6); //16 debris per level + + //boundaries + spawn.mapRect(-4100, 1500, 7200, 100); //base floor + spawn.mapRect(3000, -4000, 100, 5600); //right barrier + spawn.mapRect(-4100, -4000, 100, 5600); //left barrier + //spawn.mapRect(1600, -10000, 1500, 4000); //upper right wall + //spawn.mapRect(-4100, -10000, 2100, 4000); //upper left wall + spawn.mapRect(1600, -4000, 1500, 3000); //right wall + spawn.mapRect(-4100, 0, 5600, 1550); //floor + + //starting room + spawn.mapRect(1500, 0, 700, 900); + spawn.mapRect(2120, -170, 380, 1170); + spawn.mapRect(2700, -170, 400, 1170); + //spawn.mapVertex(2296, 400, "0 0 0 1200 300 1200 400 0"); + //spawn.mapVertex(2904, 400, "0 0 0 1200 -300 1200 -400 0"); + + //left area + spawn.mapRect(-3500, -300, 300, 400); //floor 1 + spawn.mapRect(-3900, -600, 300, 100); + spawn.mapRect(-3500, -900, 300, 100); + spawn.mapRect(-3100, -1150, 1000, 150); //floor 2 + spawn.mapRect(-2200, -2600, 200, 1600); + spawn.mapRect(-2700, -1450, 300, 100); + spawn.mapRect(-3100, -1750, 300, 100); + spawn.mapRect(-3500, -2050, 300, 100); + spawn.mapRect(-4100, -4000, 650, 1500); //floor 3 + spawn.mapRect(-3250, -4000, 1250, 1500); + + //statue base + spawn.mapRect(-700, -900, 1000, 200); //top + //left + spawn.mapRect(-700, -900, 200, 500); + spawn.mapRect(-1000, -600, 500, 200); + spawn.mapRect(-1000, -600, 200, 400); + spawn.mapRect(-1300, -300, 500, 100); + //right + spawn.mapRect(100, -900, 200, 500); + spawn.mapRect(100, -600, 500, 200); + spawn.mapRect(400, -600, 200, 400); + spawn.mapRect(400, -300, 500, 100); + + hangingNGON(-1900, -4000, 1, 1000, 1, false, { + density: 0.001, //default density is 0.001 + friction: 0.0001, + frictionAir: 0.001, + frictionStatic: 0, + restitution: 0, + isNotHoldable: true + }); + hangingNGON(1900, -4600, 0.2, 300, 0.0005, false, { + density: 0.00005, //default density is 0.001 + friction: 0.0001, + frictionAir: 0.003, + frictionStatic: 0, + restitution: 1, + isNotHoldable: true + }); + + // // Never gonna give you up + // spawn.bodyRect(-8000, -10100, 15, 100); + // // Never gonna let you down + // spawn.bodyRect(-7915, -10100, 15, 100); + // // Never gonna run around and desert you + // body[body.length] = Bodies.polygon(-7950, -10025, 0, 25, { //circle + // friction: 0.05, + // frictionAir: 0.001 + // }); + // // Never gonna make you cry + // spawn.bodyRect(6985, -10100, 15, 100); + // // Never gonna say goodbye + // spawn.bodyRect(6900, -10100, 15, 100); + // // Never gonna tell a lie and hurt you + // body[body.length] = Bodies.polygon(6950, -10025, 0, 25, { //circle + // friction: 0.05, + // frictionAir: 0.001 + // }); + + //pile of blocks + spawn.bodyRect(1920, -400, 200, 400) + spawn.bodyRect(1720, -250, 200, 250) + spawn.bodyRect(1770, -300, 150, 50) + spawn.bodyRect(2120, -280, 100, 100) + spawn.bodyRect(1990, -500, 100, 100) + + //doors under statue + spawn.bodyRect(850, -50, 50, 50) + spawn.bodyRect(850, -100, 50, 50) + spawn.bodyRect(850, -150, 50, 50) + spawn.bodyRect(850, -200, 50, 50) + spawn.bodyRect(-1300, -50, 50, 50) + spawn.bodyRect(-1300, -100, 50, 50) + spawn.bodyRect(-1300, -150, 50, 50) + spawn.bodyRect(-1300, -200, 50, 50) + + // on the statue base + spawn.randomMob(700 + Math.random() * 100, -500 + Math.random() * 100, 1); + spawn.randomMob(400 + Math.random() * 100, -800 + Math.random() * 100, 0.4); + spawn.randomMob(100 + Math.random() * 100, -1100 + Math.random() * 100, -0.2); + spawn.randomGroup(-200, -1400, -0.4); + spawn.randomMob(-600 + Math.random() * 100, -1100 + Math.random() * 100, -0.2); + spawn.randomMob(-900 + Math.random() * 100, -800 + Math.random() * 100, 0.4); + spawn.randomMob(-1200 + Math.random() * 100, -500 + Math.random() * 100, 1); + + //in the statue base + spawn.randomSmallMob(400 + Math.random() * 300, -150 + Math.random() * 100, 0.2); + spawn.randomSmallMob(-1100 + Math.random() * 300, -150 + Math.random() * 100, 0.2); + + //bottom left + spawn.randomMob(-2600 + Math.random() * 300, -700 + Math.random() * 300, 0.6); + spawn.randomSmallMob(-3000 + Math.random() * 300, -400 + Math.random() * 300, 0.2); + spawn.randomSmallMob(-3000 + Math.random() * 300, -400 + Math.random() * 300, 0); + spawn.randomMob(-3900 + Math.random() * 100, -200 + Math.random() * 100, 0.6); + spawn.randomMob(-3400 + Math.random() * 100, -400, 0.4); + spawn.randomSmallMob(-3800 + Math.random() * 100, -700, -0.4); + spawn.randomMob(-3400 + Math.random() * 100, -1000, 0.6); + spawn.randomMob(-3000 + Math.random() * 100, -1850, 0); + spawn.randomGroup(-2700, -2000, 0.4); + + //top left + spawn.randomSmallMob(-3800, -5800, -0.2); + spawn.randomSmallMob(-2400, -5200, 0.2); + + //top right + spawn.randomGroup(2000, -5700, 0.6); + + powerUps.addResearchToLevel() //needs to run after mobs are spawned + let bosses = ["shooterBoss", "launcherBoss", "laserTargetingBoss", "streamBoss", "pulsarBoss", "spawnerBossCulture", "laserBoss", "growBossCulture"]; + let abc = Math.random(); + if (simulation.difficulty > 3) { + if (abc < 0.6) { + spawn.randomLevelBoss(-1500 + Math.random() * 250, -1100 + Math.random() * 200, bosses); + } else if (abc < 0.85) { + spawn.laserBoss(-350 + Math.random() * 300, -600 + Math.random() * 200); + } else { + spawn.randomLevelBoss(850 + Math.random() * 250, -1100 + Math.random() * 200, bosses); + } + } + spawn.secondaryBossChance(850 + Math.random() * 250, -1100 + Math.random() * 200) + + //draw leg for statue + function statueLeg(shift, color) { + ctx.save(); + ctx.translate(shift, shift); + //front leg + let stroke = color; + ctx.beginPath(); + ctx.moveTo((s.h.x + shift) * s.scale, (s.h.y + shift) * s.scale); + ctx.lineTo((s.k.x + 2 * shift) * s.scale, (s.k.y + shift) * s.scale); + ctx.lineTo((s.f.x + shift) * s.scale, (s.f.y + shift) * s.scale); + ctx.strokeStyle = stroke; + ctx.lineWidth = 7 * s.scale; + ctx.stroke(); + //toe lines + ctx.beginPath(); + ctx.moveTo((s.f.x + shift) * s.scale, (s.f.y + shift) * s.scale); + ctx.lineTo((s.f.x - 15 + shift) * s.scale, (s.f.y + 5 + shift) * s.scale); + ctx.moveTo((s.f.x + shift) * s.scale, (s.f.y + shift) * s.scale); + ctx.lineTo((s.f.x + 15 + shift) * s.scale, (s.f.y + 5 + shift) * s.scale); + ctx.lineWidth = 4 * s.scale; + ctx.stroke(); + //hip joint + ctx.beginPath(); + ctx.arc((s.h.x + shift) * s.scale, (s.h.y + shift) * s.scale, 11 * s.scale, 0, 2 * Math.PI); + //knee joint + ctx.moveTo((s.k.x + 7 + 2 * shift) * s.scale, (s.k.y + shift) * s.scale); + ctx.arc((s.k.x + 2 * shift) * s.scale, (s.k.y + shift) * s.scale, 7 * s.scale, 0, 2 * Math.PI); + //foot joint + ctx.moveTo((s.f.x + 6 + shift) * s.scale, (s.f.y + shift) * s.scale); + ctx.arc((s.f.x + shift) * s.scale, (s.f.y + shift) * s.scale, 6 * s.scale, 0, 2 * Math.PI); + ctx.fillStyle = s.fillColor; + ctx.fill(); + ctx.lineWidth = 2 * s.scale; + ctx.stroke(); + ctx.restore(); + } + + // | | | | | + // n - g o n + //when s = 1 (scale), it's 3408 long and 800 tall (height of g) + function hangingNGON(x, y, s, height, stiffness, pin, properties) { + //makes a compound part of 3 bodyVertex parts + function compound3Parts(x1, y1, v1, x2, y2, v2, x3, y3, v3, properties) { + const part1 = Matter.Bodies.fromVertices(x1, y1, Vertices.fromPath(v1), properties); + const part2 = Matter.Bodies.fromVertices(x2, y2, Vertices.fromPath(v2), properties); + const part3 = Matter.Bodies.fromVertices(x3, y3, Vertices.fromPath(v3), properties); + const compoundParts = Body.create({ + parts: [part1, part2, part3], + }); + Composite.add(engine.world, [compoundParts]); + needGravity[needGravity.length] = compoundParts; + composite[composite.length] = compoundParts; + body[body.length] = part1; + body[body.length] = part2; + body[body.length] = part3; + setTimeout(function () { + compoundParts.collisionFilter.category = cat.body; + compoundParts.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mob | cat.mobBullet | cat.map + }, 1000); + } + + //for attaching the block to a point + function addConstraint(x, y, px, py, stiff, body, pin = false) { + if (pin) { + map[map.length] = Bodies.polygon(x, y, 0, 15); //circle above + } + cons[cons.length] = Constraint.create({ + pointA: { + x: x, + y: y + }, + bodyB: body, + pointB: { + x: px, + y: py + }, + stiffness: stiff + }); + Composite.add(engine.world, cons[cons.length - 1]); + } + + //I SINCERELY APOLOGIZE FOR THE ILLEGIBLE BLOCKS OF STRING CONCATENATION + //s is scale + + //n + compound3Parts( + x + 100 * s, + y + 310 * s, + ("0 0 " + 200 * s + " 0 " + 200 * s + " " + 620 * s + " 0 " + 620 * s), + x + 300 * s, + y + 160 * s, + (200 * s + " " + 40 * s + " " + 400 * s + " " + 40 * s + " " + 400 * s + " " + 280 * s + " " + 200 * s + " " + 280 * s), + x + 499 * s, + y + 333.3 * s, + (400 * s + " " + 40 * s + " " + 540 * s + " " + 40 * s + " " + 600 * s + " " + 100 * s + " " + 600 * s + " " + 620 * s + " " + 400 * s + " " + 620 * s + " " + 400 * s + " " + 280 * s), + properties + ); + addConstraint(x + 300 * s, y - height, 0, -10 * s, stiffness, composite[composite.length - 1], pin); + + //- + spawn.bodyRect(x + 800 * s, y + 250 * s, 200 * s, 100 * s, 1, properties); + body[body.length - 1].frictionAir = 0.05 //friction to make jump easier + addConstraint(x + 900 * s, y - height, 0, -30 * s, stiffness, body[body.length - 1], pin); + + //g + compound3Parts( + x + 1400 * s, + y + 300 * s, + ("0 0 " + 250 * s + " 0 " + 425 * s + " " + 175 * s + " " + 425 * s + " " + 450 * s + " " + 275 * s + " " + 600 * s + " 0 " + 600 * s + " " + -175 * s + " " + 425 * s + " " + -175 * s + " " + 175 * s), + x + 1636 * s, + y + 633 * s, + (425 * s + " " + 450 * s + " " + 425 * s + " " + 750 * s + " " + 375 * s + " " + 800 * s + " " + 275 * s + " " + 675 * s + " " + 275 * s + " " + 600 * s), + x + 1398 * s, + y + 737 * s, + (375 * s + " " + 800 * s + " " + -75 * s + " " + 800 * s + " " + -75 * s + " " + 675 * s + " " + 275 * s + " " + 675 * s), + properties + ); + addConstraint(x + 1500 * s, y - height, 0, -15 * s, stiffness, composite[composite.length - 1], pin); + + //o + spawn.bodyVertex( + x + 2300 * s, + y + 300 * s, + ("0 0 " + 250 * s + " 0 " + 425 * s + " " + 175 * s + " " + 425 * s + " " + 425 * s + " " + 250 * s + " " + 600 * s + " 0 " + 600 * s + " " + -175 * s + " " + 425 * s + " " + -175 * s + " " + 175 * s), + properties + ); + addConstraint(x + 2300 * s, y - height, 0, -10 * s, stiffness, body[body.length - 1], pin); + + //n + compound3Parts( + x + 2900 * s, + y + 310 * s, + ("0 0 " + 200 * s + " 0 " + 200 * s + " " + 620 * s + " 0 " + 620 * s), + x + 3100 * s, + y + 160 * s, + (200 * s + " " + 40 * s + " " + 400 * s + " " + 40 * s + " " + 400 * s + " " + 280 * s + " " + 200 * s + " " + 280 * s), + x + 3300 * s, + y + 333.3 * s, + (400 * s + " " + 40 * s + " " + 540 * s + " " + 40 * s + " " + 600 * s + " " + 100 * s + " " + 600 * s + " " + 620 * s + " " + 400 * s + " " + 620 * s + " " + 400 * s + " " + 280 * s), + properties + ); + addConstraint(x + 3100 * s, y - height, 0, -10 * s, stiffness, composite[composite.length - 1], pin); + } + }, + tunnel() { // by Scarlettt + simulation.inGameConsole(`tunnel by Scarlettt`); + + level.custom = () => { + level.exit.drawAndCheck(); + + //enter + ctx.beginPath(); + ctx.moveTo(level.enter.x, level.enter.y + 30); + ctx.lineTo(level.enter.x, level.enter.y - 80); + ctx.bezierCurveTo(level.enter.x, level.enter.y - 170, level.enter.x + 100, level.enter.y - 170, level.enter.x + 100, level.enter.y - 80); + ctx.lineTo(level.enter.x + 100, level.enter.y + 30); + ctx.lineTo(level.enter.x, level.enter.y + 30); + ctx.fillStyle = "#013"; + ctx.fill(); + + //exit + ctx.beginPath(); + ctx.moveTo(level.exit.x, level.exit.y + 30); + ctx.lineTo(level.exit.x, level.exit.y - 80); + ctx.bezierCurveTo(level.exit.x, level.exit.y - 170, level.exit.x + 100, level.exit.y - 170, level.exit.x + 100, level.exit.y - 80); + ctx.lineTo(level.exit.x + 100, level.exit.y + 30); + ctx.lineTo(level.exit.x, level.exit.y + 30); + ctx.fillStyle = "#9ff"; + ctx.fill(); + + // hiding rooms in path to second floor + ctx.fillStyle = "#322"; + ctx.fillRect(3750, -1650, 3500, 350); + + // prevent the user from getting into the secreter room without defeating all mobs + if (m.pos.x > 1500 && m.pos.x < 2500 && m.pos.y > -4000 && m.pos.y < -3500 && mob.reduce((a, i) => { + return a || ((Math.sqrt((i.position.x - 3600) * (i.position.x - 3600) + (i.position.y + 3600) * (i.position.y + 3600)) < 20000) && i.isDropPowerUp); + }, false) && !emergencyActivated) { + Matter.Body.setPosition(player, { + x: 2800, + y: m.pos.y + }); + } + + button.query(); + isButtonTapped = isButtonTapped || !button.isUp; + hazard.level(!isButtonTapped); + if (Matter.Query.region([player], hazard).length) m.energy -= 0.001; + + buttonSec.query(); + buttonSec.draw(); + if (!buttonSec.isUp && !hasSecretButton) { + for (var i = 0; i < 5; i++) { + powerUps.spawn(3614, -3700, "ammo"); + } + hasSecretButton = true; + } + buttonThird.query(); + buttonThird.draw(); + if (!buttonThird.isUp && !hasSecretButton2) { + for (var i = 0; i < 1; i++) powerUps.spawn(1614, -3700, "research"); + hasSecretButton2 = true; + } + if (!buttonSec.isUp) { + secretAnimTrans += 2; + secretAnimTime = 1; + secretAnimTrans = Math.max(0, Math.min(secretAnimTrans, 60)); + } else { + secretAnimTrans--; + if (secretAnimTime) secretAnimTrans += 3; + secretAnimTrans = Math.min(60, Math.max(secretAnimTrans, 0)); + } + if (secretAnimTime > 0) { + secretAnimTime++; + if (secretAnimTime > 150) secretAnimTime = 0; + } + + if (emergencyActivated || !buttonThird.isUp) { + secretAnimTrans2 += 2; + secretAnimTime2 = 1; + secretAnimTrans2 = Math.max(0, Math.min(secretAnimTrans2, 60)); + } else { + secretAnimTrans2--; + if (secretAnimTime2) secretAnimTrans2 += 3; + secretAnimTrans2 = Math.min(60, Math.max(secretAnimTrans2, 0)); + } + if (secretAnimTime2 > 0) { + secretAnimTime2++; + if (secretAnimTime2 > 150) secretAnimTime2 = 0; + } + + + + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 200, 0, 2 * Math.PI); + ctx.fillStyle = "#ff25"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 400, 0, 2 * Math.PI); + ctx.fillStyle = "#ff22"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 700, 0, 2 * Math.PI); + ctx.fillStyle = "#ff21"; + ctx.fill(); + elevator.move(); + elevator.drawTrack(); + }; + level.customTopLayer = () => { + hazard.query(); + secretHazard.level(emergencyActivated); + secretHazard.query(); + button.draw(); + + // Fire damage + let isInRange = flames.reduce((a, i) => a || Math.sqrt((m.pos.x - i[0]) * (m.pos.x - i[0]) + (m.pos.y + 90 - i[1]) * (m.pos.y + 90 - i[1])) < 50, false); + + if (isInRange) { + fireDmgLevel++; + fireDmgLevel = Math.min(fireDmgLevel, 100); + } else { + fireDmgLevel--; + fireDmgLevel = Math.max(fireDmgLevel, -8); + } + + if (fireDmgLevel > -8) { + ctx.fillStyle = "#fa0b"; + ctx.fillRect(m.pos.x - 50, m.pos.y - 100, Math.min(fireDmgLevel * 12.5 + 100, 100), 15); + } + + if (fireDmgLevel > 0) { + ctx.fillStyle = "#f00c"; + ctx.fillRect(m.pos.x - 50, m.pos.y - 100, fireDmgLevel, 15); + + m.damage(0.001 * (1.5 * isInRange + 1)); + + drawFlame(m.pos.x, m.pos.y + 90, "#d40", Math.PI / 2 + 1); + drawFlame(m.pos.x, m.pos.y + 90, "#d40", Math.PI / 2 + 1); + drawFlame(m.pos.x, m.pos.y + 90, "#d40", Math.PI / 2 + 1); + drawFlame(m.pos.x, m.pos.y + 90, "#d40", Math.PI / 2 - 1); + drawFlame(m.pos.x, m.pos.y + 90, "#d40", Math.PI / 2 - 1); + drawFlame(m.pos.x, m.pos.y + 90, "#d40", Math.PI / 2 - 1); + drawFlame(m.pos.x, m.pos.y + 90, "#f70", Math.PI / 2); + drawFlame(m.pos.x, m.pos.y + 90, "#f70", Math.PI / 2); + drawFlame(m.pos.x, m.pos.y + 90, "#f70", Math.PI / 2); + } + + for (let j = 0; j < 5; j++) { + drawFlame(1130 + j * 10, -1700) + for (let i = 0; i < 7; i++) drawFlame(2550 + i * 200, -2800); + for (let i = 0; i < 10; i++) drawFlame(2800 + i * 500, -1650); + for (let i = 0; i < 9; i++) drawFlame(1595 + i * 95, -3860); + drawFlame(4850, -1300); + drawFlame(6350, -1300); + } + ctx.fillStyle = "#541"; + for (let i = 0; i < 9; i++) { + ctx.fillRect(1592 + i * 95, -3860, 6, 70); + } + + if (m.pos.x > 1500 && m.pos.x < 3750 && m.pos.y > -5000 && m.pos.y < -3300) { + secretRoomTrans -= 5; + secretRoomTrans = Math.max(secretRoomTrans, 85); + } else { + secretRoomTrans += 5; + secretRoomTrans = Math.min(secretRoomTrans, 250); + } + + + let hasMob = mob.reduce((a, i) => { + return a || ((Math.sqrt((i.position.x - 3600) * (i.position.x - 3600) + (i.position.y + 3600) * (i.position.y + 3600)) < 20000) && i.isDropPowerUp); + }, false) && !emergencyActivated; + + door.isClosing = hasMob; + + door.openClose(); + ctx.fillStyle = "#444444" + secretRoomTrans.toString(16); + ctx.fillRect(1480, -5000, 2270, 1710); + if (hasMob) { + ctx.fillStyle = "#444"; + ctx.fillRect(1480, -5000, 1070, 1710); + } + + if (secretAnimTrans > 0) { + drawProject([3614, -3530], [2900, -3900], [3400, -3600], secretAnimTrans, 60); + if (secretAnimTrans >= 42) { + ctx.font = "27px monospace"; + ctx.textAlign = "start" + ctx.fillStyle = "#00ffff" + Math.floor((secretAnimTrans - 40) * 12.75).toString(16); + ctx.fillText("Waste Discharge Interruption:", 2910, -3870); + ctx.fillText("Owner 'Scarlet' not found", 2910, -3830); + ctx.fillText("Detected user: 'm'", 2910, -3790); + ctx.fillStyle = (hasMob ? "#ff6644" : "#ffff44") + Math.floor((secretAnimTrans - 40) * 12.75).toString(16); + ctx.fillText(hasMob ? "AREA HAS MOBS." : "Area clear.", 2910, -3710); + ctx.fillText(hasMob ? "'openDoor' failed." : "'openDoor' complete.", 2910, -3670); + ctx.strokeStyle = "#00ff00" + Math.floor((secretAnimTrans - 40) * 6).toString(16); + ctx.beginPath(); + ctx.arc(3300, -3730, 60, 0, 2 * Math.PI); + ctx.stroke(); + ctx.arc(3330, -3730, 8, 0, 2 * Math.PI); + ctx.lineWidth = 4; + ctx.stroke(); + ctx.textAlign = "center"; + ctx.fillStyle = "#00ffff" + Math.floor((secretAnimTrans - 40) * 12.75).toString(16); + ctx.font = "30px monospace"; + ctx.fillText("n-gon inc", 3300, -3630); + + ctx.font = "25px Arial"; + } + } + if (secretAnimTrans2 > 0) { + drawProject([1614, -3530], [2050, -3900], [1550, -3600], secretAnimTrans2, 60); + if (secretAnimTrans2 >= 42) { + ctx.font = "27px monospace"; + ctx.textAlign = "start"; + ctx.fillStyle = "#00ffff" + Math.floor((secretAnimTrans2 - 40) * 12.75).toString(16); + ctx.fillText("SECURITY BREACH DETECTED", 1560, -3870); + ctx.fillText("Entity name: m", 1560, -3830); + ctx.fillStyle = (tech.totalCount < 25 ? (tech.totalCount < 10 ? "#ffff44" : "#22ff22") : "#ff6644") + Math.floor((secretAnimTrans2 - 40) * 12.75).toString(16); + ctx.fillText("Threat level: " + (tech.totalCount < 25 ? (tech.totalCount < 10 ? "Low" : "Medium") : "HIGH"), 1560, -3790); + if (tech.totalCount >= 15) ctx.fillText("PROCEDURE ACTIVATED", 1560, -3750); + ctx.strokeStyle = "#00ff00" + Math.floor((secretAnimTrans2 - 40) * 6).toString(16); + ctx.beginPath(); + ctx.arc(1950, -3730, 60, 0, 2 * Math.PI); + ctx.stroke(); + ctx.arc(1980, -3730, 8, 0, 2 * Math.PI); + ctx.lineWidth = 4; + ctx.stroke(); + ctx.textAlign = "center"; + ctx.fillStyle = "#00ffff" + Math.floor((secretAnimTrans2 - 40) * 12.75).toString(16); + ctx.font = "30px monospace"; + ctx.fillText("n-gon inc", 1950, -3630); + + ctx.font = "25px Arial"; + if (secretAnimTrans2 >= 60) { + if (!emergencyActivated && tech.totalCount >= 10) { + for (let i = 0; i < 5; i++) { + spawn.exploder(1614, -3900); + if (tech.totalCount >= 25) spawn.randomMob(1614, -3900, Infinity); + } + emergencyActivated = true; + } + } + } + } + }; + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 8500; + level.exit.y = 680; + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#123"; + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + + // spawn blocks + spawn.mapRect(-100, 0, 1050, 100); + spawn.mapRect(900, -300, 50, 300); + spawn.mapRect(700, -300, 50, 200); + + // first room + spawn.mapRect(-100, -350, 850, 50); + spawn.mapRect(900, -350, 850, 50); + spawn.mapRect(-100, -1550, 50, 1200); + spawn.mapRect(1700, -1550, 50, 1200); + spawn.mapRect(-100, -1550, 850, 50); + spawn.mapRect(900, -1550, 850, 50); + spawn.bodyRect(700, -400, 50, 50); + spawn.bodyRect(900, -400, 50, 50); + + spawn.mapRect(500, -650, 650, 25); + spawn.mapRect(200, -1000, 200, 25); + spawn.mapRect(1250, -1000, 200, 25); + spawn.mapRect(600, -1300, 450, 25); + + spawn.mapRect(700, -1650, 50, 100); + spawn.mapRect(900, -1650, 50, 100); + + + // pathway to second room + spawn.mapRect(950, -1650, 3050, 50); + spawn.mapRect(1100, -1700, 100, 50); + + // second room + spawn.mapRect(0, -5000, 1500, 3000); + spawn.mapRect(1500, -2050, 300, 50); + spawn.mapRect(2000, -3100, 300, 1100); + spawn.mapRect(1500, -5000, 2250, 1000); + spawn.mapRect(1500, -3500, 1050, 225); + spawn.mapRect(4000, -5000, 500, 3000); + spawn.mapRect(3748, -5000, 252, 1550); + + spawn.mapRect(1700, -2400, 300, 50); + spawn.mapRect(1500, -2750, 300, 50); + + spawn.mapRect(2300, -3000, 1700, 50); + spawn.mapRect(2300, -2800, 1700, 800); + spawn.mapRect(2450, -3300, 1300, 100); + + // secret room in second room + spawn.mapRect(2700, -3500, 1050, 50); + spawn.mapRect(2549, -5000, 1201, 1000); + + const buttonSec = level.button(3550, -3500); + const buttonThird = level.button(1550, -3500); + let hasSecretButton = false, + hasSecretButton2 = false, + secretAnimTrans = 0, + secretAnimTime = 0, + secretAnimTrans2 = 0, + secretAnimTime2 = 0; + let emergencyActivated = false; + + const door = level.door(2450, -4000, 100, 500, 490); + const secretHazard = level.hazard(1500, -4000, 1000, 510, 0.01); + + // hazards + const button = level.button(3800, -3000); + const hazard = level.hazard(2300, -3090, 1700, 110, 0.005); + let isButtonTapped = false; + + // if (b.inventory.length < 5) powerUps.spawn(3800, -3200, "gun"); + powerUps.spawn(3900, -3100, "heal", true, 30); + powerUps.spawn(3900, -3100, "heal", true, 30); + + // path to the third room + spawn.mapRect(2000, -1850, 50, 200); + spawn.mapRect(2200, -2000, 50, 200); + spawn.mapRect(2400, -1850, 50, 200); + + spawn.mapRect(4200, -1650, 1300, 50); + spawn.mapRect(5700, -1650, 1300, 50); + spawn.mapRect(7200, -1650, 750, 50); + + spawn.mapRect(3700, -1600, 50, 350); + spawn.mapRect(7250, -1600, 50, 350); + spawn.mapRect(3750, -1300, 3500, 50); + spawn.mapRect(4500, -2150, 3550, 50) + + // third room + spawn.mapRect(7900, -1600, 50, 1000); + spawn.mapRect(8050, -3000, 50, 2400); + spawn.mapRect(7000, -600, 950, 50); + spawn.mapRect(8050, -600, 950, 50); + spawn.mapRect(7000, -600, 50, 1000); + spawn.mapRect(8950, -600, 50, 1000); + spawn.mapRect(7000, 400, 950, 50); + spawn.mapRect(8050, 400, 950, 50); + spawn.mapRect(7900, 400, 50, 300); + spawn.mapRect(7900, 700, 1000, 50); + + const elevator = level.elevator(7962.5, 500, 75, 50, -1800) + + + // fire damage + const flames = []; + flames.push([1150, -1700], [1150, -1770]); + for (let i = 0; i < 10; i++) flames.push([2800 + i * 500, -1650], [2800 + i * 500, -1720]); + flames.push([4850, -1300], [6350, -1300], [4850, -1370], [6350, -1370]); + + let fireDmgLevel = -8; + + let secretRoomTrans = 250; + + // mobs + let mobList1 = [ + [500, -750], + [1150, -750], + [825, -1100], + [300, -1100], + [1350, -1100] + ]; + while (mobList1.length > 5 - Math.sqrt(simulation.difficulty * 2.5) && mobList1.length) { + let rand = Math.floor(Math.random() * mobList1.length); + spawn[["hopper", "sneaker", "striker"][Math.floor(Math.random() * 3)]](mobList1[rand][0], mobList1[rand][1], 60 + Math.random() * 10); + mobList1.splice(rand, 1); + } + + let hasLaser = spawn.pickList.includes("laser"); + if (hasLaser) spawn.pickList.splice(spawn.pickList.indexOf("laser"), 1); + let mobList2 = [ + [50, -1400], + [1600, -450], + [50, -450], + [1600, -1400] + ]; + for (let i = 0; i < 10; i++) mobList2.push([2800 + i * 500, -1800]); + while (mobList2.length && mob.length < -1 + 16 * Math.log10(simulation.difficulty + 1)) { + let rand = Math.floor(Math.random() * mobList2.length); + spawn.randomMob(...mobList2[rand]); + mobList2.splice(rand, 1); + } + + let groupList = ["spawn.randomGroup(8250, 575);", + `spawn.randomGroup(3200, -3700); + if (simulation.difficulty > 15) + spawn.randomGroup(3500, -3700, 0.3);`, + "spawn.randomGroup(7800, -1800, 0.5);" + ]; + while (groupList.length > 0) { + let ind = Math.floor(Math.random() * groupList.length); + Function(groupList[ind])(); + groupList.splice(ind, 1); + } + if (hasLaser) spawn.pickList.push("laser"); + + spawn.shieldingBoss(3900, -3200, 70); + + let randomBoss = Math.floor(Math.random() * 2); + if (simulation.difficulty > 5) spawn[["shooterBoss", "launcherBoss"][randomBoss]](7500, -150, 100, false); + else spawn[["shooter", "launcher"][randomBoss]](7500, -150, 150); + spawn[["shooter", "launcher"][randomBoss]](8500, -150, 150); + + // canvas stuff + function drawFlame(x, y, color = "#f81", angle = Math.PI / 2) { + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.strokeStyle = color; + ctx.lineWidth = 3; + for (let i = 0; i < 3; i++) { + let randAng = (Math.random() - 0.5) * 2 + angle; + randLen = 30 + Math.random() * 10; + + x = x + Math.cos(randAng) * randLen; + y = y - Math.sin(randAng) * randLen; + ctx.lineTo(x, y); + } + ctx.stroke(); + } + + function drawProject(startPos, endPos1, endPos2, tValue, tValueM) { + ctx.strokeStyle = "#003"; + ctx.fillStyle = "#0055aa" + ('0' + (tValue * 60 / tValueM).toString(16)).slice(-2); + + let inter = (tValueM - tValue) / tValueM; + let endpos1i = endPos1.map((i, j) => (startPos[j] - i) * inter), + endpos2i = endPos2.map((i, j) => (startPos[j] - i) * inter); + + ctx.beginPath(); + ctx.moveTo(endPos1[0] + endpos1i[0], endPos1[1] + endpos1i[1]); + ctx.lineTo(...startPos); + ctx.lineTo(endPos2[0] + endpos2i[0], endPos1[1] + endpos1i[1]); + ctx.fill(); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(endPos1[0] + endpos1i[0], endPos1[1] + endpos1i[1]); + ctx.lineTo(...startPos); + ctx.lineTo(endPos1[0] + endpos1i[0], endPos2[1] + endpos2i[1]); + ctx.fill(); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(endPos1[0] + endpos1i[0], endPos2[1] + endpos2i[1]); + ctx.lineTo(...startPos); + ctx.lineTo(endPos2[0] + endpos2i[0], endPos2[1] + endpos2i[1]); + ctx.fill(); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(endPos2[0] + endpos2i[0], endPos2[1] + endpos2i[1]); + ctx.lineTo(...startPos); + ctx.lineTo(endPos2[0] + endpos2i[0], endPos1[1] + endpos1i[1]); + ctx.fill(); + ctx.stroke(); + + if (tValue >= tValueM * 2 / 3) { + ctx.fillStyle = "#0055aa" + ('0' + Math.floor((tValue - tValueM * 2 / 3) * 6.25 * 60 / tValueM).toString(16)).slice(-2); + ctx.strokeStyle = "#000033" + ('0' + Math.floor((tValue - tValueM * 2 / 3) * 12.75 * 60 / tValueM).toString(16)).slice(-2); + ctx.fillRect(endPos1[0], endPos1[1], endPos2[0] - endPos1[0], endPos2[1] - endPos1[1]); + ctx.shadowColor = "#00aaaa" + ('0' + Math.floor((tValue - tValueM * 2 / 3) * 12.75 * 60 / tValueM).toString(16)).slice(-2); + ctx.shadowBlur = 10; + ctx.strokeRect(endPos1[0], endPos1[1], endPos2[0] - endPos1[0], endPos2[1] - endPos1[1]); + ctx.shadowBlur = 0; + ctx.shadowColor = "#0000"; + } + } + }, + run() { + simulation.inGameConsole(`run by iNoobBoi`); + + addPartToMap = (len) => { //adds new map elements to the level while the level is already running //don't forget to run simulation.draw.setPaths() after you all the the elements so they show up visually + map[len].collisionFilter.category = cat.map; + map[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(map[len], true); //make static + Composite.add(engine.world, map[len]); + } + + anotherBoss = (x, y) => { + if (tech.isDuplicateMobs && Math.random() < tech.duplicationChance()) { + spawn.randomLevelBoss(x, y, ["historyBoss"]); + } + } + + const climbPad = level.boost(8200, -200, 500); + var climbTime = false; + var climbGroup = 0; + var initialSpawn = false; + var endTime = false; + + let runMobList = [ + "hopper", + "slasher", + "striker", + "stabber", + "springer", + "pulsar", + "sneaker", + "spinner", + "grower", + "focuser", + "spawner", + ]; + + let removeList = []; + + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + + climbPad.query(); + + if (m.pos.x > 8000 && climbTime === false) { + spawn.mapRect(7800, -900, 200, 900); + addPartToMap(map.length - 1); + simulation.draw.setPaths(); + + simulation.inGameConsole(`UNKNOWN: "Well done. Now climb."`, 600); + simulation.inGameConsole(`UNKNOWN: "I left a gift at the top."`, 600); + + climbTime = true; + } //toggles on a mapRect when player passes a certain area + + if (m.pos.x > 9000 && endTime === false) { + simulation.inGameConsole("UNKNOWN: \"Good luck. I hope you get out of here.\"", 600); + endTime = true; + } + + for (i in mob) { + mob[i].damageReduction = 0; + Matter.Body.setVelocity(mob[i], { + x: mob[i].velocity.x * 0.97, + y: mob[i].velocity.y * 0.97 + }); + } //makes everything slow and immune + }; + + level.customTopLayer = () => { + ctx.fillStyle = "#888"; + + if (climbGroup === 0) { + //toggle on fillRect: 1 + ctx.fillRect(8000, -900, 300, 100); + ctx.fillRect(8500, -1800, 300, 100); + ctx.fillRect(8300, -2700, 300, 100); + ctx.fillRect(8000, -3600, 300, 100); + ctx.fillRect(8200, -4500, 300, 100); + } else if (climbGroup === 1) { + //toggle on fillRect: 2 + ctx.fillRect(8300, -1200, 300, 100); + ctx.fillRect(8500, -2100, 300, 100); + ctx.fillRect(8100, -3000, 300, 100); + ctx.fillRect(8000, -3900, 300, 100); + ctx.fillRect(8200, -4800, 300, 100); + } else if (climbGroup === 2) { + //toggle on fillRect: 0 + ctx.fillRect(8500, -600, 300, 100); + ctx.fillRect(8100, -1500, 300, 100); + ctx.fillRect(8000, -2400, 300, 100); + ctx.fillRect(8500, -3300, 300, 100); + ctx.fillRect(8500, -4200, 300, 100); + } + + if ((simulation.cycle % 120) === 0) { + for (var i = 0; i < map.length; i++) { + if (map[i].isRemove) { + Matter.Composite.remove(engine.world, map[i]); + map.splice(i, 1); + } + } + + if (climbGroup === 0) { + //toggle on platforms: 0 + spawn.mapRect(8000, -900, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8500, -1800, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8300, -2700, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8000, -3600, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8200, -4500, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + + climbGroup = 1; + } else if (climbGroup === 1) { + //toggle on platforms: 1 + spawn.mapRect(8300, -1200, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8500, -2100, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8100, -3000, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8000, -3900, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8200, -4800, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + + climbGroup = 2; + } else if (climbGroup === 2) { + //toggle on platforms: 2 + spawn.mapRect(8500, -600, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8100, -1500, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8000, -2400, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8500, -3300, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + spawn.mapRect(8500, -4200, 300, 100); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + + climbGroup = 0; + } + + simulation.draw.setPaths(); //update map graphics + } //every 120 cycles, first deletes previous group, then cycles through one of 3 toggle groups + }; + + if (!initialSpawn) { + level.defaultZoom = 1300 //was 800 I changed this + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#dcdcde"; + //Level + level.setPosToSpawn(-100, -1450); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + + level.exit.x = 9300; + level.exit.y = -5130; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + + //Map + spawn.mapRect(-1400, -2200, 1700, 200); + spawn.mapRect(100, -2200, 200, 1000); + spawn.mapRect(-600, -1400, 8600, 200); + spawn.mapRect(-1400, -2200, 200, 1000); + spawn.mapRect(-2800, -1400, 1600, 200); + spawn.mapRect(-2800, -1400, 200, 1400); + spawn.mapRect(-2800, -200, 11800, 200); + spawn.mapRect(-900, -600, 600, 600); + spawn.mapRect(200, -800, 500, 100); + spawn.mapRect(1300, -1400, 200, 900); + spawn.mapRect(1300, -600, 500, 100); + spawn.mapRect(2300, -800, 200, 200); + spawn.mapRect(2900, -400, 100, 400); + spawn.mapRect(3200, -600, 100, 600); + spawn.mapRect(3500, -800, 100, 800); + spawn.mapRect(4400, -900, 500, 100); + spawn.mapRect(4400, -600, 500, 100); + spawn.mapRect(4800, -900, 100, 400); + spawn.mapRect(5300, -550, 600, 550); + spawn.mapRect(5600, -900, 300, 800); + spawn.mapRect(6300, -300, 1100, 300); + spawn.mapRect(6600, -400, 500, 200); + spawn.mapRect(6600, -800, 500, 100); + spawn.mapRect(7000, -1400, 100, 700); + spawn.mapRect(7800, -5900, 200, 5100); + spawn.mapRect(7800, -5900, 1900, 200); + spawn.mapRect(9500, -5900, 200, 1000); + spawn.mapRect(8800, -5100, 900, 200); + spawn.mapRect(8800, -5100, 200, 5100); + + //Text + spawn.mapRect(400, -1600, 100, 10); + spawn.mapRect(400, -1600, 10, 100); + spawn.mapRect(490, -1600, 10, 40); + spawn.mapRect(400, -1570, 100, 10); + spawn.mapRect(400, -1540, 100, 10); + spawn.mapRect(490, -1540, 10, 40); + + spawn.mapRect(600, -1600, 10, 100); + spawn.mapRect(600, -1510, 100, 10); + spawn.mapRect(690, -1600, 10, 100); + + spawn.mapRect(800, -1600, 100, 10); + spawn.mapRect(800, -1600, 10, 100); + spawn.mapRect(890, -1600, 10, 100); + + spawn.mapRect(0, 0, 1, 1); //dont ask why i have these + spawn.mapRect(1, 0, 1, 1); //dont ask why i have these + spawn.mapRect(0, 1, 1, 1); //dont ask why i have these + spawn.mapRect(1, 1, 1, 1); //dont ask why i have these + spawn.mapRect(-1, 0, 1, 1); //dont ask why i have these + spawn.mapRect(0, -1, 1, 1); //dont ask why i have these + spawn.mapRect(-1, -1, 1, 1); //dont ask why i have these + spawn.mapRect(1, -1, 1, 1); //dont ask why i have these + spawn.mapRect(-1, 1, 1, 1); //dont ask why i have these + + //Mob Spawning + setTimeout(() => { + simulation.inGameConsole("UNKNOWN: \"You cannot kill them.\"", 600); + }, 2000); + + setTimeout(() => { + simulation.inGameConsole("UNKNOWN: \"But I have slowed them down for you.\"", 600); + }, 6000); + + + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](200, -400); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](1800, -1000); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](3200, -1000); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](6200, -400); + + if (simulation.difficulty > 10) { + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](1000, -400); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](2400, -400); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](4000, -400); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](6600, -1000); + + setTimeout(() => { + simulation.inGameConsole("UNKNOWN: \"Run.\"", 600); + }, 10000); + } //some of the mobs + if (simulation.difficulty > 20) { + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](1000, -1000); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](3100, -300); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](4200, -1000); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](7400, -800); + + setTimeout(() => { + simulation.inGameConsole("UNKNOWN: \"RUN!\"", 600); + }, 11000); + } //most of the mobs + if (simulation.difficulty > 30) { + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](200, -1000); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](3400, -300); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](5200, -800); + spawn[runMobList[Math.floor(Math.random() * runMobList.length)]](7500, -300); + + setTimeout(() => { + simulation.inGameConsole("UNKNOWN: \"GET OUT OF HERE.\"", 600); + }, 12000); + } //all the mobs + + //Boss Spawning + if (simulation.difficulty > 5) { + spawn.randomLevelBoss(-2200, -700, ["powerUpBossBaby", "blockBoss", "revolutionBoss"]); + + setTimeout(() => { + simulation.inGameConsole("UNKNOWN: \"They are coming for you.\"", 600); + }, 14000); + } + anotherBoss(-1800, -700); //custom second boss spawn + + //Blocks + spawn.bodyRect(1300, -500, 200, 100); + spawn.bodyRect(1400, -500, 200, 100); + spawn.bodyRect(1500, -500, 200, 100); + + spawn.bodyRect(5700, -1200, 100, 100); + spawn.bodyRect(5700, -1100, 100, 100); + spawn.bodyRect(5700, -1000, 100, 100); + + spawn.bodyRect(6800, -700, 100, 100); + spawn.bodyRect(6800, -600, 100, 100); + spawn.bodyRect(6800, -500, 100, 100); + + spawn.debris(4400, -300, 500, 16); + spawn.debris(3300, -600, 200, 6); + spawn.debris(3000, -500, 20, 6); + spawn.debris(2300, -300, 200, 6); + spawn.debris(200, -300, 500, 16); + + //Powerups + if (simulation.difficulty > 10) { + powerUps.spawn(1600, -700, "tech"); + } + powerUps.spawnRandomPowerUp(1700, -700); + + // if (simulation.difficulty > 20) { + // powerUps.spawn(4600, -700, "tech"); + // } + powerUps.spawnRandomPowerUp(4700, -700); + + // if (simulation.difficulty > 30) { + // powerUps.spawn(6800, -1000, "tech"); + // } + powerUps.spawnRandomPowerUp(6900, -1000); + + powerUps.spawn(9200, -5400, "tech"); + + if (simulation.difficulty > 10) { + powerUps.spawn(9200, -5500, "tech"); + } + // if (simulation.difficulty > 20) { + // powerUps.spawn(9200, -5600, "tech"); + // } + // if (simulation.difficulty > 30) { + // powerUps.spawn(9200, -5700, "tech"); + // } + powerUps.addResearchToLevel() //needs to run after mobs are spawned + initialSpawn == true; + } + }, + islands() { + simulation.inGameConsole(`islands by Richard0820`); + + const boost1 = level.boost(58500, -18264, 1300); + let portal2, portal3; + // const removeIndex1 = map.length - 1; + const drip1 = level.drip(59300, -18975, -18250, 100); // drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + const drip2 = level.drip(60000, -18953, -18250, 150); + const drip3 = level.drip(60905, -18652, -18250, 70); + const slimePit1 = level.hazard(58850, -18300, 2275, 100, 0.01); //hazard(x, y, width, height, damage = 0.003) spawn.mapRect(58850, -18300, 2275, 100); + const slimePit2 = level.hazard(74400, -18075, 350, 100, 0.01); + let isSpawnedBoss = false; + level.custom = () => { + level.exit.drawAndCheck(); + boost1.query(); + level.enter.draw(); + drip1.draw(); + drip2.draw(); + drip3.draw(); + // portal[2].query(); + // portal[3].query(); + // portal[0].draw(); + // portal[1].draw(); + // portal[2].draw(); + // portal[3].draw(); + portal2[2].query(); + portal2[3].query(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + portal3[2].query(); + portal3[3].query(); + portal3[0].draw(); + portal3[1].draw(); + portal3[2].draw(); + portal3[3].draw(); + }; + level.customTopLayer = () => { + slimePit1.query(); + slimePit2.query(); + ctx.fillStyle = `rgba(68, 68, 68, ${Math.max(0.3, Math.min((-17650 - m.pos.y) / 100, 0.99))})`; + ctx.fillRect(58390, -17655, 1490, 740); + }; + document.body.style.backgroundColor = "hsl(138, 3%, 74%)"; + level.setPosToSpawn(57680, -18330); + level.exit.x = 76343; + level.exit.y = -18020; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 30); + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 30); + level.defaultZoom = 2000; + simulation.zoomTransition(level.defaultZoom); + // spawn.setSpawnList = [ + // "hopper", + // "slasher", + // "striker", + // "stabber", + // "springer", + // "pulsar", + // "sneaker", + // "spinner", + // "grower", + // "focuser", + // "spawner", + // ]; + spawn.mapRect(57800, -18550, 50, 100); + spawn.mapRect(57500, -18550, 50, 275); + spawn.mapRect(66900, -18675, 300, 200); + spawn.mapRect(66925, -19050, 125, 225); + spawn.mapRect(67825, -16975, 125, 100); + spawn.mapRect(74900, -18075, 225, 100); + spawn.mapRect(73925, -18225, 150, 275); + spawn.mapRect(76200, -18325, 50, 125); + spawn.mapRect(76525, -18325, 75, 400); + spawn.mapRect(61325, -18350, 50, 25); + spawn.mapRect(61450, -18425, 50, 25); + spawn.mapRect(61475, -18450, 25, 25); + spawn.mapRect(58725, -18350, 125, 50); + spawn.mapRect(58675, -18275, 50, 75); + spawn.mapRect(58600, -18275, 75, 75); + spawn.mapRect(58675, -18325, 50, 50); + spawn.mapRect(58250, -16925, 1825, 1050); + spawn.mapRect(57500, -18200, 4475, 550); + spawn.mapRect(61500, -18475, 475, 275); + spawn.mapRect(62175, -18575, 325, 400); + spawn.mapRect(62900, -18850, 525, 375); + spawn.mapRect(63900, -18925, 450, 400); + spawn.mapRect(64725, -19000, 625, 500); + spawn.mapRect(65825, -19050, 675, 400); + spawn.mapRect(66800, -18950, 400, 400); + spawn.mapRect(68775, -18850, 525, 400); + spawn.mapRect(67375, -16900, 1800, 1450); + spawn.mapRect(67375, -17475, 325, 575); + spawn.mapRect(68900, -17500, 250, 500); + spawn.mapRect(69425, -17050, 500, 475); + spawn.mapRect(70400, -17150, 425, 175); + spawn.mapRect(71175, -17325, 450, 325); + spawn.mapRect(72000, -17425, 325, 300); + spawn.mapRect(72725, -17450, 350, 275); + spawn.mapRect(70050, -18800, 550, 350); + spawn.mapRect(67750, -19400, 375, 1200); + spawn.mapRect(67750, -18200, 1425, 700); + spawn.mapRect(66800, -18550, 575, 1650); + spawn.mapRect(66800, -16900, 575, 1450); + spawn.mapRect(67350, -18175, 250, 750); + spawn.mapRect(71050, -18450, 725, 275); + spawn.mapRect(72100, -18150, 475, 200); + spawn.mapRect(73325, -17975, 3275, 475); + spawn.mapRect(73175, -17775, 150, 300); + spawn.mapRect(72975, -17675, 225, 250); + spawn.mapRect(76200, -18325, 400, 75); + spawn.mapRect(76525, -18250, 75, 275); + spawn.mapRect(76200, -18250, 50, 50); + spawn.mapRect(57500, -17675, 900, 1800); + spawn.mapRect(59875, -17675, 1975, 1800); + spawn.mapRect(57550, -18275, 225, 75); + spawn.mapRect(61375, -18375, 50, 50); + spawn.mapRect(61100, -18350, 75, 50); + spawn.mapRect(61175, -18325, 50, 25); + spawn.mapRect(61850, -16525, 250, 175); + spawn.mapRect(57500, -18500, 50, 325); + spawn.mapRect(57500, -18550, 350, 50); + spawn.mapRect(57800, -18500, 50, 50); + spawn.mapRect(61275, -18325, 375, 125); + spawn.mapRect(61425, -18400, 200, 75); + spawn.mapRect(62125, -18575, 125, 75); + spawn.mapRect(62250, -18200, 175, 125); + spawn.mapRect(62850, -18725, 100, 75); + spawn.mapRect(63075, -18550, 225, 225); + spawn.mapRect(62800, -18275, 75, 75); + spawn.mapRect(62500, -18475, 75, 50); + spawn.mapRect(63825, -18900, 150, 50); + spawn.mapRect(63950, -18575, 150, 125); + spawn.mapRect(64200, -18550, 100, 250); + spawn.mapRect(64925, -18525, 200, 275); + spawn.mapRect(64625, -18425, 75, 125); + spawn.mapRect(65225, -18675, 150, 175); + spawn.mapRect(65350, -18950, 75, 100); + spawn.mapRect(65950, -18575, 75, 150); + spawn.mapRect(66000, -18725, 225, 175); + spawn.mapRect(66275, -18675, 75, 125); + spawn.mapRect(66275, -18550, 75, 75); + spawn.mapRect(66150, -18550, 100, 50); + spawn.mapRect(66225, -18875, 25, 150); + spawn.mapRect(66200, -18750, 75, 25); + spawn.mapRect(66925, -19100, 125, 150); + spawn.mapRect(66000, -19100, 75, 50); + spawn.mapRect(65000, -19075, 100, 75); + spawn.mapRect(66750, -18625, 100, 100); + spawn.mapRect(68050, -18500, 350, 350); + spawn.mapRect(68125, -18975, 150, 475); + spawn.mapRect(69850, -18675, 150, 200); + spawn.mapRect(70000, -18625, 150, 50); + spawn.mapRect(68850, -18575, 325, 225); + spawn.mapRect(69100, -18400, 75, 100); + spawn.mapRect(70150, -18525, 125, 200); + spawn.mapRect(70425, -18525, 125, 200); + spawn.mapRect(70250, -18350, 175, 225); + spawn.mapRect(70325, -18475, 50, 150); + spawn.mapRect(70275, -18450, 150, 150); + spawn.mapRect(71175, -18250, 525, 250); + spawn.mapRect(71050, -18200, 150, 375); + spawn.mapRect(70925, -18300, 200, 250); + spawn.mapRect(71425, -18525, 175, 150); + spawn.mapRect(70225, -18950, 275, 250); + spawn.mapRect(70475, -17050, 225, 175); + spawn.mapRect(70625, -17250, 100, 150); + spawn.mapRect(71300, -17150, 200, 350); + spawn.mapRect(71100, -17250, 125, 100); + spawn.mapRect(71550, -17400, 150, 150); + spawn.mapRect(67675, -17150, 225, 300); + spawn.mapRect(68225, -17000, 100, 125); + spawn.mapRect(67900, -16975, 375, 100); + spawn.mapRect(68275, -16950, 150, 50); + spawn.bodyRect(76200, -18200, 50, 200); + spawn.mapRect(76200, -18000, 50, 25); + spawn.bodyRect(57800, -18450, 50, 175); + spawn.mapRect(68725, -17600, 300, 250); + spawn.mapRect(68625, -17550, 175, 100); + spawn.mapRect(68850, -17400, 150, 125); + spawn.mapRect(69325, -16900, 200, 225); + spawn.mapRect(69575, -16625, 175, 275); + spawn.mapRect(69850, -16875, 250, 200); + spawn.mapRect(69875, -16650, 150, 300); + spawn.mapRect(69825, -16800, 375, 325); + spawn.mapRect(69650, -16775, 325, 475); + spawn.mapRect(71975, -17325, 100, 125); + spawn.mapRect(72075, -17200, 150, 150); + spawn.mapRect(72275, -17350, 150, 150); + spawn.mapRect(72325, -17275, 150, 225); + spawn.mapRect(72225, -18050, 200, 225); + spawn.mapRect(71925, -18150, 250, 175); + spawn.mapRect(72075, -18275, 125, 175); + spawn.mapRect(72500, -18025, 125, 175); + spawn.mapRect(72400, -17975, 150, 175); + spawn.mapRect(73925, -18225, 350, 275); + spawn.mapRect(74750, -18125, 275, 175); + spawn.mapRect(74250, -18100, 150, 75); + spawn.mapRect(74275, -18050, 200, 75); + spawn.mapRect(73750, -18100, 275, 125); + spawn.mapRect(73075, -17475, 3525, 300); + spawn.mapRect(73275, -17600, 3325, 225); + spawn.mapRect(57775, -18250, 150, 50); + spawn.mapRect(57775, -18275, 75, 25); + spawn.mapRect(57925, -18225, 50, 25); + spawn.debris(68300, -17000, 3700, 16); + spawn.mapRect(62000, -16525, 100, 200); + spawn.mapRect(59125, -19125, 325, 200); + spawn.mapRect(59925, -19175, 350, 225); + spawn.mapRect(60800, -18850, 275, 200); + spawn.mapRect(75025, -18075, 200, 100); + spawn.mapRect(75225, -18025, 100, 50); + spawn.bodyRect(74300, -18150, 50, 25); + spawn.bodyRect(73850, -18150, 75, 75); + spawn.bodyRect(74700, -18000, 75, 50); + spawn.bodyRect(74250, -18325, 25, 25); + spawn.bodyRect(74275, -18325, 25, 25); + spawn.bodyRect(74275, -18325, 25, 25); + spawn.bodyRect(74300, -18325, 100, 25); + // portal = level.portal( + // { + // x: 58625, + // y: -16925, + // }, + // 1.5 * Math.PI, + // { + // //right + // x: 58625, + // y: -17650, + // }, + // 2.5 * Math.PI + // ); //right + portal2 = level.portal({ + x: 61920, + y: -16525, + }, + 1.5 * Math.PI, { + //right + x: 58400, + y: -17325, + }, + 2 * Math.PI + ); + portal3 = level.portal({ + x: 59865, + y: -17300, + }, + 3 * Math.PI, { + //right + x: 60820, + y: -31130, + }, + 2.5 * Math.PI + ); + + spawn.mapRect(60275, -32250, 975, 400); + spawn.mapRect(60375, -31925, 275, 225); + spawn.mapRect(61025, -31950, 175, 300); + spawn.mapRect(60825, -31725, 100, 350); + spawn.mapRect(60675, -31875, 200, 225); + spawn.mapRect(60225, -31950, 100, 725); + spawn.mapRect(60250, -31525, 250, 375); + spawn.mapRect(60675, -31475, 425, 350); + spawn.mapRect(60625, -32500, 225, 300); + spawn.mapRect(61025, -32325, 125, 175); + spawn.mapRect(60375, -32325, 175, 150); + spawn.mapRect(60250, -19075, 100, 100); + spawn.randomMob(59850, -18825, Infinity); + spawn.randomMob(62325, -18800, Infinity); + spawn.randomMob(61725, -18800, Infinity); + spawn.randomMob(63050, -19025, Infinity); + spawn.randomMob(64100, -19200, Infinity); + spawn.randomMob(64225, -19100, Infinity); + spawn.randomMob(64875, -19300, Infinity); + spawn.randomMob(65125, -19325, Infinity); + spawn.randomMob(65850, -19275, Infinity); + spawn.randomMob(66200, -19300, Infinity); + spawn.randomMob(65975, -19425, Infinity); + spawn.randomMob(67925, -19600, Infinity); + spawn.randomMob(66975, -19275, Infinity); + spawn.randomMob(67550, -18750, Infinity); + spawn.randomMob(69625, -17275, Infinity); + spawn.randomMob(70550, -17350, Infinity); + spawn.randomMob(71375, -17475, Infinity); + spawn.randomMob(72200, -17600, Infinity); + spawn.randomMob(73000, -18025, Infinity); + spawn.randomMob(73850, -18350, Infinity); + spawn.randomMob(75725, -18300, Infinity); + spawn.randomMob(75875, -18275, Infinity); + spawn.randomMob(75700, -18200, Infinity); + spawn.randomMob(75550, -18275, Infinity); + spawn.randomMob(75825, -18150, Infinity); + spawn.randomMob(75575, -18150, Infinity); + spawn.randomGroup(75575, -18150, 0); + level.chain(67250, -19325, 0, true, 14, 20); + spawn.mapRect(58725, -18300, 125, 100); + spawn.mapRect(61100, -18300, 175, 100); + spawn.mapRect(67175, -19375, 100, 100); + spawn.mapRect(59125, -19125, 325, 200); + spawn.mapRect(59925, -19175, 350, 225); + spawn.mapRect(60800, -18850, 275, 200); + spawn.mapRect(60850, -18725, 50, 200); + spawn.mapRect(60950, -18675, 50, 200); + spawn.mapRect(59975, -19025, 50, 250); + spawn.mapRect(60125, -19025, 50, 400); + spawn.mapRect(60075, -19025, 50, 450); + spawn.mapRect(59425, -19075, 100, 100); + spawn.mapRect(59175, -19000, 100, 225); + spawn.mapRect(59325, -19000, 75, 450); + spawn.mapRect(59050, -19000, 100, 100); + spawn.mapRect(61050, -18775, 100, 75); + spawn.mapRect(60725, -18850, 125, 125); + spawn.bodyRect(61850, -16525, 250, 175); + if (simulation.difficulty > 1) { + spawn.randomGroup(75575, -18150, 0); + spawn.randomLevelBoss(68450, -17300); + } + if (!isSpawnedBoss) { + isSpawnedBoss = true; + if (Math.random() < 0.33) { + for ( + let i = 0, len = Math.min(simulation.difficulty / 20, 6); i < len; + ++i + ) + spawn.bounceBoss(59025, -17325, 50, false); + } else if (Math.random() < 0.5) { + for ( + let i = 0, len = Math.min(simulation.difficulty / 9, 8); i < len; + ++i + ) + spawn.sprayBoss(59025, -17325, 50, false); + } else { + for ( + let i = 0, len = Math.min(simulation.difficulty / 6, 10); i < len; + ++i + ) + spawn.mineBoss(59025, -17325, 50, false); + } + powerUps.spawn(59352, -17115, "tech"); + // for (let i = 0, len = 3 + simulation.difficulty / 20; i < len; ++i) spawn.mantisBoss(1487 + 300 * i, -1525, 35, false) + } + simulation.fallHeight = -15000; + powerUps.addResearchToLevel(); + powerUps.spawn(3000, -230, "heal"); + }, + temple() { + simulation.inGameConsole(`temple by Scar1337`); + + const V = Vector; + const Equation = (function () { + function Equation(a, b, c) { + this.a = a; + this.b = b; + this.c = c; + } + Equation.prototype.getXfromY = function (y) { + return (-this.b * y - this.c) / this.a; + } + Equation.prototype.getYfromX = function (x) { + return (-this.a * x - this.c) / this.b; + } + Equation.fromPoints = function (v1, v2) { + if (v1.x === v2.x) return new Equation(1, 0, -v1.x); + if (v1.y === v2.y) return new Equation(0, 1, -v1.y); + const d = (v2.y - v1.y) / (v2.x - v1.x); + return new Equation(-d, 1, d * v1.x - v1.y); + }; + return Equation; + })(); + const Rect = (function () { + function Rect(x, y, w, h) { + this.pos = { + x, + y + }; + this.width = w; + this.height = h; + } + Rect.prototype.has = function ({ + x, + y + }) { + return x >= this.pos.x && x <= this.pos.x + this.width && + y >= this.pos.y && y <= this.pos.y + this.height; + } + Rect.prototype.hasLine = function (eq) { + const leftInter = eq.getYfromX(this.pos.x); + const rightInter = eq.getYfromX(this.pos.x + this.width); + const topInter = eq.getXfromY(this.pos.y); + return (leftInter >= this.pos.y && leftInter <= this.pos.y + this.height) || + (rightInter >= this.pos.y && rightInter <= this.pos.y + this.height) || + (topInter >= this.pos.x && topInter <= this.pos.x + this.width); + } + Rect.prototype.addToMap = function () { + spawn.mapRect(this.pos.x, this.pos.y, this.width, this.height); + } + Object.defineProperty(Rect.prototype, "midPos", { + get() { + return V.add(this.pos, { + x: this.width / 2, + y: this.height / 2 + }); + } + }); + Rect.fromBounds = function (min, max) { + return new Rect(min.x, min.y, max.x - min.x, max.y - min.y); + } + Rect.prototype.isCollidingWith = function (other) { + const tc = { + p1: [this.pos.x, this.pos.y], + p2: [this.pos.x + this.width, this.pos.y + this.height] + }; + const oc = { + p1: [other.pos.x, other.pos.y], + p2: [other.pos.x + other.width, other.pos.y + other.height] + }; + + // If one rectangle is on left side of other + if (tc.p1[0] >= oc.p2[0] || oc.p1[0] >= tc.p2[0]) + return false; + + // If one rectangle is above other + if (tc.p1[1] >= oc.p2[1] || oc.p1[1] >= tc.p2[1]) + return false; + + return true; + } + return Rect; + })(); + + function isInBound(bound) { + return bound.has(player.bounds.min) || bound.has(player.bounds.max); + } + + function relocateWIMPs(x, y) { + for (const i of mob) { + if (i.isWIMP) { + setPos(i, { + x: x + 300 * (Math.random() - 0.5), + y: y + 300 * (Math.random() - 0.5) + }); + } + } + } + + function secondRoomSuckerBoss(x, y, isDark = false, radius = 25) { + mobs.spawn(x, y, 12, radius, isDark ? "#000" : "#fff"); + let me = mob[mob.length - 1]; + me.isBoss = true; + me.isDark = isDark; + + me.stroke = "transparent"; + me.eventHorizon = 500; // How family friendly content much do I have to reduce this + me.seeAtDistance2 = 5e6; // Basically just see at all times, in the context it's given + me.accelMag = 0.00003 * simulation.accelScale; + me.collisionFilter.mask = cat.player | cat.bullet; + me.memory = 1600; + me.randomPRNGMult = Math.random() * 500; + + me.attackCycle = 0; + me.lastAttackCycle = 0; + Matter.Body.setDensity(me, 0.012); // extra dense, normal is 0.001 // makes effective life much larger + me.onDeath = function () { + // applying forces to player doesn't seem to work inside this method, not sure why + powerUps.spawn(this.position.x + 20, this.position.y, "ammo"); + if (Math.random() > 0.5) powerUps.spawn(this.position.x, this.position.y, "ammo"); + if (Math.random() > 0.3) powerUps.spawn(this.position.x, this.position.y, "heal", true, 30 * (simulation.healScale ** 0.25) * Math.sqrt(tech.largerHeals) * Math.sqrt(0.1 + Math.random() * 0.5)); + }; + me.damageReduction = 0.25 + me.do = function () { + // keep it slow, to stop issues from explosion knock backs + if (this.speed > 1) { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.95, + y: this.velocity.y * 0.95 + }); + } + if (!(simulation.cycle % this.seePlayerFreq)) { + if (this.distanceToPlayer2() < this.seeAtDistance2) { // ignore cloak for black holes + this.locatePlayer(); + if (!this.seePlayer.yes) this.seePlayer.yes = true; + } else if (this.seePlayer.recall) { + this.lostPlayer(); + } + } + this.checkStatus(); + if (this.seePlayer.recall) { + // accelerate towards the player + const forceMag = this.accelMag * this.mass; + const dx = this.seePlayer.position.x - this.position.x + const dy = this.seePlayer.position.y - this.position.y + const mag = Math.sqrt(dx * dx + dy * dy) + this.force.x += forceMag * dx / mag; + this.force.y += forceMag * dy / mag; + + // eventHorizon waves in and out + const eventHorizon = this.eventHorizon * (1 + 0.2 * Math.sin(simulation.cycle * 0.008)); + + // draw darkness + ctx.fillStyle = this.isDark ? "rgba(0,20,40,0.6)" : "rgba(225,215,255,0.6)"; + DrawTools.arc(this.position.x, this.position.y, eventHorizon * 0.2, 0, 2 * Math.PI); + ctx.fillStyle = this.isDark ? "rgba(0,20,40,0.4)" : "rgba(225,215,255,0.4)"; + DrawTools.arc(this.position.x, this.position.y, eventHorizon * 0.4, 0, 2 * Math.PI); + ctx.fillStyle = this.isDark ? "rgba(0,20,40,0.3)" : "rgba(225,215,255,0.3)"; + DrawTools.arc(this.position.x, this.position.y, eventHorizon * 0.6, 0, 2 * Math.PI); + ctx.fillStyle = this.isDark ? "rgba(0,20,40,0.2)" : "rgba(225,215,255,0.2)"; + DrawTools.arc(this.position.x, this.position.y, eventHorizon * 0.8, 0, 2 * Math.PI); + ctx.fillStyle = this.isDark ? "rgba(0,0,0,0.05)" : "rgba(255,255,255,0.05)"; + DrawTools.arc(this.position.x, this.position.y, eventHorizon, 0, 2 * Math.PI); + // when player is inside event horizon + if (distance(this.position, player.position) < eventHorizon) { + if (this.isDark) { + // Standard black hole stuff + if (m.immuneCycle < m.cycle) { + if (m.energy > 0) m.energy -= 0.003; + if (m.energy < 0.1) m.damage(0.00015 * simulation.dmgScale); + } + const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x); + player.force.x -= 0.0005 * Math.cos(angle) * player.mass * (m.onGround ? 1.7 : 1); + player.force.y -= 0.0005 * Math.sin(angle) * player.mass; + // draw line to player + ctx.lineWidth = Math.min(60, this.radius * 2); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + DrawTools.line([this.position, m.pos]); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + DrawTools.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + } else { + // Lightning attacks + this.attackCycle++; + if (this.attackCycle >= 30) { + this.attackCycle = 0; + this.lastAttackCycle = simulation.cycle; + Matter.Body.setVelocity(player, V.add(player.velocity, { + x: 0, + y: -10 + })); + if (m.immuneCycle < m.cycle) { + if (m.energy > 0) m.energy -= 0.03; + m.damage(0.005 * simulation.dmgScale); + } + } + DrawTools.lightning(this.position, m.pos, this.lastAttackCycle, this.randomPRNGMult); + ctx.fillStyle = `rgba(255,240,127,${0.12 * Math.max(15 - simulation.cycle + this.lastAttackCycle, 0)})`; + DrawTools.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + } + } + } + } + }; + + function secondRoomPlacerBoss(x, y, isDark = false, size = 70) { + mobs.spawn(x, y, isDark ? 3 : 4, size, isDark ? "#0008" : "#fff8"); + let me = mob[mob.length - 1]; + me.isBoss = true; + me.isDark = isDark; + + me.stroke = isDark ? "#000" : "#fff"; + me.seeAtDistance2 = 5e6; // Basically just see at all times, in the context it's given + me.accelMag = 0.0001 * simulation.accelScale; + me.collisionFilter.mask = cat.player | cat.bullet; + me.memory = 1600; + me.randomPRNGMult = Math.random() * 500; + + me.attackCycle = 0; + me.maxAttackCycle = isDark ? 90 : 240; + Matter.Body.setDensity(me, 0.006); // extra dense, normal is 0.001 // makes effective life much larger + me.onDeath = function () { + powerUps.spawn(this.position.x + 20, this.position.y, "ammo"); + if (Math.random() > 0.5) powerUps.spawn(this.position.x, this.position.y, "ammo"); + if (Math.random() > 0.3) powerUps.spawn(this.position.x, this.position.y, "heal", true, 30 * (simulation.healScale ** 0.25) * Math.sqrt(tech.largerHeals) * Math.sqrt(0.1 + Math.random() * 0.5)); + }; + me.damageReduction = 0.25 + me.do = function () { + // keep it slow, to stop issues from explosion knock backs + if (this.speed > 2) { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.95, + y: this.velocity.y * 0.95 + }); + } + if (!(simulation.cycle % this.seePlayerFreq)) { + if (this.distanceToPlayer2() < this.seeAtDistance2) { // ignore cloak + this.locatePlayer(); + if (!this.seePlayer.yes) this.seePlayer.yes = true; + } else if (this.seePlayer.recall) { + this.lostPlayer(); + } + } + this.checkStatus(); + if (this.seePlayer.recall) { + // accelerate towards the player + const forceMag = this.accelMag * this.mass; + const dx = this.seePlayer.position.x - this.position.x + const dy = this.seePlayer.position.y - this.position.y + const mag = Math.sqrt(dx * dx + dy * dy) + this.force.x += forceMag * dx / mag; + this.force.y += forceMag * dy / mag; + this.attackCycle++; + if (this.attackCycle > this.maxAttackCycle) { + this.attackCycle = 0; + secondRoomObstacle(this.position.x, this.position.y, this.isDark, size); + } + } + } + }; + function secondRoomObstacle(x, y, isDark = false, size = 70) { + mobs.spawn(x, y, isDark ? 3 : 4, size, isDark ? "#0004" : "#fff4"); + let me = mob[mob.length - 1]; + + me.stroke = isDark ? "#000b" : "#fffb"; + me.collisionFilter.mask = isDark ? cat.player | cat.bullet : 0; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.leaveBody = false; + me.timeLeft = 1200; + me.isObstacle = true; + me.damageReduction = isDark ? 0.5 : 0 + if (!isDark) { + me.isBadTarget = true; + me.attackCycle = 0; + me.maxAttackCycle = 10; + me.inertia = Infinity; + } + me.do = isDark ? function () { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.95, + y: this.velocity.y * 0.95 + }); + } : function () { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.95, + y: this.velocity.y * 0.95 + }); + if (Rect.fromBounds(this.bounds.min, this.bounds.max).isCollidingWith(Rect.fromBounds(player.bounds.min, player.bounds.max))) { + this.attackCycle++; + this.attackCycle = Math.min(this.attackCycle, 10); + } else { + this.attackCycle--; + this.attackCycle = Math.max(this.attackCycle, 0); + } + if (this.attackCycle > 0) { + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + if (this.attackCycle >= 10) { + ctx.shadowBlur = 10; + ctx.shadowColor = "rgb(255, 210, 64)"; + } + ctx.fillStyle = `rgba(255, 210, 64, ${this.attackCycle / 15})`; + ctx.fill(); + ctx.shadowBlur = 0; + if (this.attackCycle >= 10) { + DrawTools.lightning(this.position, m.pos, simulation.cycle); + m.damage(0.003 * simulation.dmgScale); + } + } + this.timeLimit(); + } + } + + function mobGrenade(...args) { + spawn.grenade(...args); + const pulseRadius = args[3] || Math.min(550, 250 + simulation.difficulty * 3) + let me = mob[mob.length - 1]; + me.fill = "#ace"; + me.damageReduction = 0; + me.onDeath = function () { + //damage player if in range + if (distance(player.position, this.position) < pulseRadius && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage + m.damage(0.02 * simulation.dmgScale); + } + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: pulseRadius, + color: "rgba(170,204,238,0.3)", + time: simulation.drawTime + }); + }; + me.do = function () { + this.timeLimit(); + ctx.beginPath(); //draw explosion outline + ctx.arc(this.position.x, this.position.y, pulseRadius * (1.01 - this.timeLeft / this.lifeSpan), 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = "rgba(170,204,238,0.1)"; + ctx.fill(); + }; + } + // Todo: nerf ThirdRoomBoss a bit? + function thirdRoomBoss(x, y) { + mobs.spawn(x, y, 6, 60, "#000"); + let me = mob[mob.length - 1]; + // Fix in place + me.constraint = Constraint.create({ + pointA: { + x: me.position.x, + y: me.position.y + }, + bodyB: me, + stiffness: 1, + damping: 1 + }); + Composite.add(engine.world, me.constraint); + me.isBoss = true; + + me.stroke = "transparent"; + me.eventHorizon = 900; + me.collisionFilter.mask = cat.player | cat.bullet | cat.body; + + me.memory = Infinity; + me.attackCycle = 0; + me.lastAttackCycle = 0; + me.spawnCycle = 0; + Matter.Body.setDensity(me, 0.08); //extra dense //normal is 0.001 //makes effective life much larger + me.onDeath = function () { + for (let j = 0; j < 8; j++) { //in case some mobs leave things after they die + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i] !== this) { + if (mob[i].isInvulnerable) { //disable invulnerability + mob[i].isInvulnerable = false + mob[i].damageReduction = 1 + } + mob[i].damage(Infinity, true); + } + } + } + // You earned it: One more tech + powerUps.spawn(this.position.x, this.position.y, "tech"); + powerUps.spawnBossPowerUp(this.position.x, this.position.y); + templePlayer.room3ToEndAnim = 1; + }; + me.nextHealthThreshold = 0.75; + me.trapCycle = 0; + me.onDamage = function () { + if (this.health < this.nextHealthThreshold) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 //0.75,0.5,0.25 + this.trapCycle = 1; + this.isInvulnerable = true; + this.damageReduction = 0; + } + }; + me.damageReduction = 0.25 + me.rings = [{ + colour: "#65f", + radius: 300, + id: 0 + }, { + colour: "#0f0", + radius: 400, + id: 1 + }, { + colour: "#f00", + radius: 500, + id: 2 + }]; + me.ring = function () { + if (this.isInvulnerable) return; + ctx.lineWidth = 10; + for (const ring of this.rings) { + const radius = ring.radius * (1 + 0.3 * Math.sin(simulation.cycle / 60 * (ring.id + 2))); + if (Math.abs(distance(player.position, this.position) - radius) < 60 && m.immuneCycle < simulation.cycle) { + m.damage(0.4 / radius); + } + ctx.strokeStyle = ring.colour; + DrawTools.arcOut(this.position.x, this.position.y, radius, 0, Math.PI * 2); + } + } + me.horizon = function () { + if (this.isInvulnerable) return this.fill = "#f00"; + // eventHorizon waves in and out + const eventHorizon = this.eventHorizon * (1 + 0.2 * Math.sin(simulation.cycle * 0.008)); + + const charge = this.attackCycle / 90; + this.fill = `rgb(${charge * 255},${charge * 255},${charge * 255})`; + // draw darkness + ctx.fillStyle = `rgba(${charge * 225},${20 + charge * 195},${40 + charge * 215},0.6)`; + DrawTools.arc(this.position.x, this.position.y, eventHorizon * 0.2, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(${charge * 225},${20 + charge * 195},${40 + charge * 215},0.4)`; + DrawTools.arc(this.position.x, this.position.y, eventHorizon * 0.4, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(${charge * 225},${20 + charge * 195},${40 + charge * 215},0.3)`; + DrawTools.arc(this.position.x, this.position.y, eventHorizon * 0.6, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(${charge * 225},${20 + charge * 195},${40 + charge * 215},0.2)`; + DrawTools.arc(this.position.x, this.position.y, eventHorizon * 0.8, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(${charge * 255},${charge * 255},${charge * 255},0.05)`; + DrawTools.arc(this.position.x, this.position.y, eventHorizon, 0, 2 * Math.PI); + + // when player is inside event horizon + if (V.magnitude(V.sub(this.position, player.position)) < eventHorizon) { + // Standard black hole stuff + if (m.immuneCycle < m.cycle) { + if (m.energy > 0) m.energy -= 0.004; + if (m.energy < 0.1) m.damage(0.0002 * simulation.dmgScale); + } + const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x); + player.force.x -= 0.001 * Math.cos(angle) * player.mass * (m.onGround ? 1.7 : 1); + player.force.y -= 0.001 * Math.sin(angle) * player.mass; + // draw line to player + ctx.lineWidth = Math.min(60, this.radius * 2); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + DrawTools.line([this.position, m.pos]); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + DrawTools.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + // Lightning attacks + this.attackCycle++; + if (this.attackCycle >= 90) { + this.attackCycle = 0; + this.lastAttackCycle = simulation.cycle; + Matter.Body.setVelocity(player, V.add(player.velocity, { + x: 0, + y: -20 + })); + if (m.immuneCycle < m.cycle) { + m.damage(0.012 * simulation.dmgScale); + } + } + const lightningCycle = simulation.cycle * 2 / 3 + this.lastAttackCycle / 3; + DrawTools.lightning(this.position, m.pos, lightningCycle, 1, 12); + DrawTools.lightning(this.position, m.pos, lightningCycle, 2, 12); + ctx.fillStyle = `rgba(255,240,127,${0.12 * Math.max(15 - simulation.cycle + this.lastAttackCycle, 0)})`; + DrawTools.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + } + } + me.periodicSpawns = function () { + if (this.isInvulnerable) return; + this.spawnCycle++; + // Spawn annoying purple thing(s) that chases the player + if (!(this.spawnCycle % 180)) { + spawn.seeker(this.position.x, this.position.y, 15 * (0.7 + 0.5 * Math.random()), 7); + spawn.seeker(this.position.x, this.position.y, 4 * (0.7 + 0.5 * Math.random()), 7); + spawn.seeker(this.position.x, this.position.y, 4 * (0.7 + 0.5 * Math.random()), 7); + } + // Spawn the annoying pink (now blue) exploder that doesn't chase the player + if (!(this.spawnCycle % 300)) { + for (let i = 0; i < 3; i++) { + mobGrenade(1100 + 700 * i, -13030, undefined, Math.min(700, 300 + simulation.difficulty * 4), 10); + setVel(mob[mob.length - 1], { + x: 0, + y: -10 + }); + mobGrenade(1100 + 700 * i, -14370, undefined, Math.min(700, 300 + simulation.difficulty * 4), 10); + setVel(mob[mob.length - 1], { + x: 0, + y: 10 + }); + } + } + // Spawn a bunch of mobs + if (simulation.difficulty > 10 && !(this.spawnCycle % 600)) { + // This is just ripped off of spawn.nodeGroup because I don't want the shield + const nodes = 3; + const radius = Math.ceil(Math.random() * 10) + 18; + const sideLength = Math.ceil(Math.random() * 100) + 70; + const stiffness = Math.random() * 0.03 + 0.005; + spawn.allowShields = false; //don't want shields on individual group mobs + const angle = 2 * Math.PI / nodes + for (let i = 0; i < nodes; ++i) { + spawn.focuser(x + sideLength * Math.sin(i * angle), y + sideLength * Math.cos(i * angle), radius); + } + spawn.constrainAllMobCombos(nodes, stiffness); + spawn.allowShields = true; + } + } + me.invulnerableTrap = function () { + if (this.trapCycle < 1) return; + this.trapCycle++; + // 24 is just an arbitrarily large number + const spawnCycles = Math.min(24, Math.max(6, 4 + Math.floor(simulation.difficulty / 3))); + // I have no idea how to balance at all, please help me + const spawnDelay = Math.floor(5 + 10 / (1 + Math.sqrt(simulation.difficulty) / 5)); + if (this.trapCycle >= 90) { + const cycle = this.trapCycle - 90; + if (!(cycle % spawnDelay)) { + const radius = Math.min(500, 200 + simulation.difficulty * 3); + mobGrenade(600, -13050, 30, radius); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: 35, + y: 0 + }); + mobGrenade(3000, -13050, 30, radius); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: -35, + y: 0 + }); + mobGrenade(600, -14350, 30, radius); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: 35, + y: 0 + }); + mobGrenade(3000, -14350, 30, radius); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: -35, + y: 0 + }); + if (Math.floor(cycle / spawnDelay) >= spawnCycles - 1) { + this.trapCycle = 0; + this.isInvulnerable = false; + this.damageReduction = 0.25 + } + } + } + ctx.font = "100px Arial"; + ctx.fillStyle = "#f00"; + ctx.shadowBlur = 10; + ctx.shadowColor = "#f00"; + ctx.textAlign = "center"; + ctx.textBaseLine = "middle"; + ctx.fillText("!", 900, -13050); + ctx.fillText("!", 900, -14350); + ctx.fillText("!", 1800, -13050); + ctx.fillText("!", 1800, -14350); + ctx.fillText("!", 2700, -13050); + ctx.fillText("!", 2700, -14350); + ctx.shadowBlur = 0; + } + me.do = function () { + this.checkStatus(); + this.horizon(); + this.ring(); + this.periodicSpawns(); + this.invulnerableTrap(); + } + }; + let oldNextLevel = level.nextLevel; + const oldFallHeight = simulation.fallHeight; + level.nextLevel = () => { + color.map = "#444"; + m.death = m.oldDeath; + canvas.style.filter = ""; + level.nextLevel = oldNextLevel; + simulation.fallHeight = oldFallHeight; + oldNextLevel(); + } + let bounds = []; + let mobPositionsQueue = Array.from(Array(10), () => []); + m.oldDeath = m.death; + m.death = function () { + if (!tech.isImmortal) { + requestAnimationFrame(() => color.map = "#444"); + m.death = m.oldDeath; + canvas.style.filter = ""; + level.nextLevel = oldNextLevel; + simulation.fallHeight = oldFallHeight; + m.oldDeath(); + } else { + m.switchWorlds(); + Matter.Body.setPosition(player, { + x: level.enter.x + 50, + y: level.enter.y - 20 + }); + makeLore("How did you not die?"); + setTimeout(() => makeLore("I'll let you off this one time."), 2000); + tech.isImmortal = false; + } + } + let name = "⥟ᘊ5⪊Ыᳪៗⱕ␥ዘᑧ⍗"; + addPartToMap = (len = map.length - 1) => { + map[len].collisionFilter.category = cat.map; + map[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(map[len], true); // make static + Composite.add(engine.world, map[len]); + } + level.setPosToSpawn(50, -50); // normal spawn + // Make the level exit really far away so WIMP powerups don't show up at all + level.exit.x = 1e6; + level.exit.y = -1e6; + Promise.resolve().then(() => { + // Clear all WIMPS and their research + for (let i = 0; i < mob.length; i++) { + if (mob[i] && !mob[i].isDarkMatter) { + mob[i].isWIMP = true; + } + } + relocateWIMPs(0, -10030); + for (let i = 0; i < powerUp.length; i++) { + while (powerUp[i] && powerUp[i].name === "research") { + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + } + } + level.exit.x = 1500; + level.exit.y = -30; + }); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + spawn.mapRect(1500, -10, 100, 20); + level.defaultZoom = 1800 + // simulation.setZoom(1200); + simulation.zoomTransition(1200) + + + document.body.style.backgroundColor = "#daa69f"; + color.map = "#600"; + + function box(x, y, w, h, s) { + spawn.mapRect(x, y, w, s); + spawn.mapRect(x, y, s, h); + spawn.mapRect(x + w - s, y, s, h); + spawn.mapRect(x, y + h - s, w, s); + } + + function diamond(x, y, s) { + spawn.mapVertex(x, y, `0 -${s} -${s} 0 0 ${s} ${s} 0`); + } + + // Fake level + bounds.push(new Rect(-200, -500, 2000, 600)); + box(-200, -500, 2000, 600, 100); + + // Actual level, Room 1 + const firstRoomBounds = new Rect(-200, -4000, 5000, 2100); + bounds.push(firstRoomBounds); + + box(-200, -4000, 5000, 2100, 100); + spawn.mapRect(-200, -2500, 1300, 100); + spawn.mapRect(3500, -2500, 1300, 100); + spawn.mapRect(-200, -4000, 1000, 1600); + spawn.mapRect(3800, -4000, 1000, 1600); + // Enter and Exit platforms + spawn.mapRect(0, -2010, 100, 20); + spawn.mapRect(4500, -2010, 100, 20); + + // Altar of Room 1 + spawn.mapRect(2100, -2200, 100, 300); + spawn.mapRect(2400, -2200, 100, 300); + spawn.mapRect(2070, -2200, 460, 20); + + spawn.debris(1700, -2100, 300, 10); + spawn.debris(2500, -2100, 300, 10); + + // Actual level, Room 2 + const secondRoomBounds = new Rect(-1500, -10500, 3000, 3600); + bounds.push(secondRoomBounds); + + box(-1500, -10500, 3000, 3600, 100); + spawn.mapRect(-2000, -8500, 1600, 1600); + spawn.mapRect(400, -8500, 1600, 1600); + // Enter and Exit platforms + spawn.mapRect(-50, -7010, 100, 20); + spawn.mapRect(-50, -10010, 100, 20); + + // Hazard traversing + spawn.mapRect(-300, -7320, 800, 20); + spawn.mapRect(175, -7600, 325, 20); + spawn.mapRect(200, -7775, 300, 20); + spawn.mapRect(-500, -7600, 325, 20); + spawn.mapRect(-500, -7775, 300, 20); + spawn.mapRect(-500, -7950, 800, 20); + spawn.mapRect(-300, -8100, 800, 20); + spawn.mapRect(-500, -8250, 800, 20); + for (let i = 0; i < 2; i++) spawn.mapRect(-250, -8400 + 150 * i, 500, 60); + const room2SlimePit = level.hazard(-400, -8410, 800, 1090); + room2SlimePit.logic = function () { + if (this.height > 0 && Matter.Query.region([player], this).length) { + if (m.immuneCycle < m.cycle) { + // Trolled + const hasCPT = tech.isRewindAvoidDeath; + tech.isRewindAvoidDeath = false; + const DRAIN = 0.002 * (tech.isRadioactiveResistance ? 0.2 : 1) + 0.001; + if (m.energy > DRAIN && !tech.isEnergyHealth) { + m.energy -= DRAIN; + } + m.damage(0.00015 * (tech.isRadioactiveResistance ? 0.2 : 1)); + if (tech.isEnergyHealth) { + const previousEnergy = m.energy; + m.regenEnergy(); + const energyRegenerated = m.energy - previousEnergy; + if (energyRegenerated > 0) { + m.energy = previousEnergy; + m.damage(energyRegenerated); + } + } + tech.isRewindAvoidDeath = hasCPT; + } + player.force.y -= 0.3 * player.mass * simulation.g; + setVel(player, Vector.sub(player.velocity, { + x: 0, + y: player.velocity.y * 0.02 + })); + } + // Float power ups + powerUpCollide = Matter.Query.region(powerUp, this) + for (let i = 0, len = powerUpCollide.length; i < len; i++) { + const diameter = 2 * powerUpCollide[i].size + const buoyancy = 1 - 0.2 * Math.max(0, Math.min(diameter, this.min.y - powerUpCollide[i].position.y + powerUpCollide[i].size)) / diameter + powerUpCollide[i].force.y -= buoyancy * 1.14 * powerUpCollide[i].mass * simulation.g; + setVel(powerUpCollide[i], { + x: powerUpCollide[i].velocity.x, + y: 0.96 * powerUpCollide[i].velocity.y + }); + } + } + room2SlimePit.draw = function () { + if (this.isOn) { + ctx.fillStyle = "hsla(160, 100%, 35%, 0.75)"; + ctx.fillRect(this.min.x, this.min.y, this.width, this.height); + } + } + // Room 2 spawning bounds + const secondRoomSpawnBounds = new Rect(-1500, -10500, 3000, 2000); + spawn.mapRect(-700, -8700, 150, 20); + spawn.mapRect(550, -8700, 150, 20); + spawn.mapRect(-400, -8900, 800, 20); + diamond(-600, -9800, 30); + diamond(0, -9800, 30); + diamond(600, -9800, 30); + + spawn.mapRect(-1000, -10000, 2000, 30); + + // Actual level, Room 3 (Final Boss?) + const thirdRoomBounds = new Rect(-200, -14500, 4000, 1600); + bounds.push(thirdRoomBounds); + box(-200, -14500, 4000, 1600, 100); + spawn.mapRect(-200, -14500, 800, 1100); + spawn.mapRect(3000, -14500, 800, 1100); + // Enter and Exit platforms + spawn.mapRect(0, -13110, 100, 20); + spawn.mapRect(-200, -13100, 800, 200); + spawn.mapRect(3500, -13110, 100, 20); + spawn.mapRect(3000, -13100, 800, 200); + for (let i = 0; i < 4; i++) spawn.bodyRect(570, -13400 + i * 75, 30, 75); + + for (let i = 0; i < 3; i++) { + diamond(1100 + 700 * i, -13000, 30, 30); + diamond(1100 + 700 * i, -14400, 30, 30); + } + + const Objects = { + altar: { + get isHeal() { + return simulation.cycle % 600 >= 300; + }, + pos: { + x: 2300, + y: -2200 + }, + get isActive() { + const roughPlayerCentre = V.add(m.pos, { + x: 0, + y: 40 + }); + return distance(roughPlayerCentre, this.pos) < 240 && + (Math.abs(angle(roughPlayerCentre, this.pos) - Math.PI / 2) < 1); + }, + logic() { + if (!this.isActive) return; + if (this.isHeal) { + m.energy += 0.005; + } else { + m.energy = Math.max(m.energy - 0.006, 0); + if (m.energy <= 0.01 && m.immuneCycle < m.cycle) m.damage(0.002); + } + }, + drawTop() { + if (!isInBound(firstRoomBounds)) return; + const colour = this.isHeal ? m.fieldMeterColor : "#f00"; + DrawTools.flame([2300, -2200, 26, 4, colour], 7); + ctx.fillStyle = colour; + ctx.fillRect(2200, -2200, 200, 200); + }, + drawBottom() { + ctx.fillStyle = this.isHeal ? "#fff5" : "#0005"; + for (const radius of [230, 180, 130, 80, 30]) { + DrawTools.arc(2300, -2200, radius, 0, Math.PI, true); + } + } + }, + room2Initiator: { + pos: { + x: 0, + y: -9050 + }, + get distance() { + return distance(player.position, this.pos); + }, + range: 120, + rings: [{ + colour: [102, 85, 255], + radius: 200 + }, { + colour: [0, 255, 0], + radius: 300 + }, { + colour: [255, 0, 0], + radius: 400 + }], + get ringNumber() { + return this.rings.length; + }, + get cap() { + return this.ringNumber * 90 + 180; + }, + get capped() { + return templePlayer.room2.spawnInitiatorCycles > this.cap; + }, + logic() { + if (this.distance < this.range) { + templePlayer.room2.spawnInitiatorCycles++; + } + }, + draw() { + Promise.resolve().then(() => { + const cycle = templePlayer.room2.spawnInitiatorCycles; + if (!this.capped && this.distance < 400) { + ctx.fillStyle = `rgba(0, 0, 0, ${Math.min(1, (400 - this.distance) / (400 - this.range)) * 0.9})`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + } + ctx.save(); + simulation.camera(); + if (this.distance < this.range && !this.capped) { + DrawTools.lightning(V.sub(this.pos, { + x: 300, + y: 300 + }), V.add(this.pos, { + x: 300, + y: 300 + }), simulation.cycle - 5); + DrawTools.lightning(V.add(this.pos, { + x: -300, + y: 300 + }), V.add(this.pos, { + x: 300, + y: -300 + }), simulation.cycle - 5); + } + if (!this.capped && cycle >= this.cap - 180) { + const multCoeff = (cycle - this.cap + 180) * 0.4 + ctx.translate((Math.random() - 0.5) * multCoeff, (Math.random() - 0.5) * multCoeff); + } + ctx.shadowBlur = 20; + ctx.lineWidth = 12; + ctx.strokeStyle = (templePlayer.room2.cycles % 60 < 30) ? "#fff" : "#000"; + ctx.shadowColor = (templePlayer.room2.cycles % 60 < 30) ? "#fff" : "#000"; + DrawTools.arcOut(this.pos.x, this.pos.y, 100, 0, Math.PI * 2); + if (templePlayer.room2.cycles <= 100) { + for (let i = 0; i < this.ringNumber; i++) { + if (cycle < i * 90) break; + const ring = this.rings[i]; + ctx.shadowColor = `rgb(${ring.colour.join(",")})`; + const opacity = this.capped ? 1 - 0.01 * templePlayer.room2.cycles : (cycle / 180 - i / 2); + ctx.strokeStyle = `rgba(${ring.colour.join(",")}, ${Math.min(opacity, 1)})`; + const radius = (this.capped ? 1 + 0.07 * templePlayer.room2.cycles : Math.sin(Math.min(cycle - i * 90, 45) / 90 * Math.PI)) * ring.radius; + DrawTools.arcOut(this.pos.x, this.pos.y, radius, 0, Math.PI * 2); + } + } + ctx.restore(); + }); + } + }, + room2Lightning: { + one: [{ + x: -1400, + y: -10400 + }, { + x: 1400, + y: -8500 + }], + two: [{ + x: -1400, + y: -8500 + }, { + x: 1400, + y: -10400 + }], + get isHeal() { + return simulation.cycle % 360 < 180; + }, + get oneEq() { + return Equation.fromPoints(this.one[0], this.one[1]); + }, + get twoEq() { + return Equation.fromPoints(this.two[0], this.two[1]); + }, + logic() { + if (!isInBound(secondRoomSpawnBounds) || !templePlayer.room2.cycles) return; + + const playerbounds = Rect.fromBounds(player.bounds.min, player.bounds.max); + if (playerbounds.hasLine(this.oneEq) || playerbounds.hasLine(this.twoEq)) { + if (this.isHeal) { + m.energy += 0.003; + } else if (m.immuneCycle < m.cycle) { + m.energy -= 0.003; + } + } + }, + draw() { + if (!isInBound(secondRoomBounds) || !templePlayer.room2.cycles) return; + + const colour = this.isHeal ? undefined : [0, 0, 0]; + DrawTools.lightning(...this.one, Math.floor(simulation.cycle / 15) * 15, 1, 9, colour); + DrawTools.lightning(...this.two, Math.floor(simulation.cycle / 15) * 15, 2, 9, colour); + } + }, + room2GeneratedPath: { + rects: (function () { + const rects = []; + for (let i = 0; i < 4; i++) { + rects.push(new Rect(-1405 + (i & 1) * 200, -9700 + i * 300, 205, 30)); + rects.push(new Rect(1200 - (i & 1) * 200, -9700 + i * 300, 205, 30)); + } + return rects; + })(), + logic() { + if (templePlayer.room2.readyPathCycle && simulation.cycle - templePlayer.room2.readyPathCycle === 180) { + for (const r of this.rects) { + r.addToMap(); + addPartToMap(); + simulation.draw.setPaths(); + } + } + }, + draw() { + if (templePlayer.room2.readyPathCycle && simulation.cycle - templePlayer.room2.readyPathCycle < 180) { + ctx.fillStyle = "#fe79"; + for (const r of this.rects) { + ctx.fillRect(r.pos.x, r.pos.y, r.width, r.height); + } + } else if (simulation.cycle - templePlayer.room2.readyPathCycle < 195) { + for (const r of this.rects) { + DrawTools.lightning(Objects.room2Initiator.pos, r.midPos, templePlayer.room2.readyPathCycle + 180); + } + } + } + }, + room3Rotors: { + rotor1: (function () { + const rotor = level.spinner(900, -13700, 200, 30); + rotor.rotate = function () { + Matter.Body.setAngularVelocity(this.bodyB, (this.bodyB.angularVelocity + 0.01) * 0.9) + } + return rotor; + })(), + rotor2: (function () { + const rotor = level.spinner(2700, -13700, 200, 30); + rotor.rotate = function () { + Matter.Body.setAngularVelocity(this.bodyB, (this.bodyB.angularVelocity - 0.01) * 0.9) + } + return rotor; + })(), + logic() { + this.rotor1.rotate(); + this.rotor2.rotate(); + } + }, + room3SlimePits: { + pit1: level.hazard(-100, -13400, 0, 0, 0.004), + pit2: level.hazard(3700, -13400, 0, 0, 0.004), + logic() { + if (templePlayer.room2ToRoom3Anim >= 1320 && templePlayer.room2ToRoom3Anim <= 1570) { + this.pit1.height = this.pit2.height = 300; + this.pit1.max.y = this.pit2.max.y = -13100; + this.pit1.width = this.pit2.width = templePlayer.room2ToRoom3Anim * 2 - 2640; + this.pit1.max.x = this.pit1.min.x + this.pit1.width; + this.pit2.min.x = this.pit2.max.x - this.pit2.width; + } + if (templePlayer.room3ToEndAnim) { + this.pit1.height = this.pit1.width = 0; + this.pit2.height = this.pit2.width = 0; + } + }, + draw() { + this.pit1.query(); + this.pit2.query(); + } + } + }; + let templePlayer = { + room1: { + cycles: 300 + }, + room2: { + spawnInitiatorCycles: 0, + cycles: 0, + readyPathCycle: 0 + }, + stage: 1, + startAnim: 0, + room1ToRoom2Anim: 0, + room2ToRoom3Anim: 0, + room3ToEndAnim: 0, + initialTrapY: 0, + clearedCycle: 0, + drawExit: true + }; + + const RoomTransitionHandler = { + room0() { + if (templePlayer.startAnim <= 0) return; + templePlayer.startAnim++; + if (templePlayer.startAnim == 60) { + makeLore("Not so fast."); + } + if (templePlayer.startAnim < 180) { + trapPlayer(1000, templePlayer.initialTrapY); + } else { + level.exit.x = 4500; + level.exit.y = -2030; + relocateWIMPs(level.exit.x, level.exit.y); + relocateTo(50, -2050); + simulation.fallHeight = -1000; + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + + templePlayer.startAnim = -1; + templePlayer.drawExit = false; + } + }, + room1() { + const frame = templePlayer.room1ToRoom2Anim; + if (frame <= 0) return; + if (frame === 1) { + level.exit.x = -50; + level.exit.y = -10030; + makeLore("Pathetic."); + } + if (frame >= 1 && frame <= 360) { + const factor = 100 - 100 * Math.cos((frame / 90) * Math.PI); + ctx.translate(factor, factor); + Promise.resolve().then(() => { + ctx.save(); + ctx.globalCompositeOperation = "color-burn"; + ctx.fillStyle = DrawTools.randomColours((frame) * (360 - frame) / 32400); + DrawTools.updateRandomColours(5); + ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.restore(); + }); + } + if (frame === 180) { + makeLore("You are trying too hard."); + relocateTo(0, -7050); + simulation.fallHeight = -6000; + templePlayer.stage = 2; + relocateWIMPs(level.exit.x, level.exit.y - 3000); + } + templePlayer.room1ToRoom2Anim++; + }, + room2() { + if (templePlayer.room2ToRoom3Anim <= 0) return; + if (templePlayer.room2ToRoom3Anim === 1) { + level.exit.x = 3500; + level.exit.y = -13130; + makeLore("Do not try me."); + } + if (templePlayer.room2ToRoom3Anim >= 1 && templePlayer.room2ToRoom3Anim <= 180) { + canvas.style.filter = `sepia(${templePlayer.room2ToRoom3Anim / 180}) invert(${templePlayer.room2ToRoom3Anim / 180})`; + } + if (templePlayer.room2ToRoom3Anim === 180) { + templePlayer.stage = 3; + relocateTo(50, -13150); + simulation.fallHeight = -10000; + simulation.zoomTransition(1800); + templePlayer.startAnim = -1; + // Might be a bit harsh to the player if the WIMPs are involved in the third level + for (let i = 0; i < mob.length; i++) { + while (mob[i] && !mob[i].isWIMP) { + mob[i].replace(i); + } + } + templePlayer.drawExit = true; + for (let i = 0; i < 5 * tech.wimpCount; i++) { + powerUps.spawn(level.exit.x + 100 * (Math.random() - 0.5), level.exit.y - 100 + 100 * (Math.random() - 0.5), "research", false); + } + canvas.style.filter = ""; + } + if (templePlayer.room2ToRoom3Anim > 180 && templePlayer.room2ToRoom3Anim <= 360) { + canvas.style.filter = `sepia(${(360 - templePlayer.room2ToRoom3Anim) / 180}) invert(${(360 - templePlayer.room2ToRoom3Anim) / 180})`; + } + templePlayer.room2ToRoom3Anim++; + }, + room3() { + if (templePlayer.room3ToEndAnim <= 0) return; + if (templePlayer.room3ToEndAnim === 1) { + const x = "Nooooooooooo".split(""); + for (let i = 0; i < x.length / 1.6; i++) { + const randomIndex = Math.floor(Math.random() * x.length); + if (x[randomIndex] !== " ") { + x[randomIndex] = String.fromCharCode(Math.floor(Math.random() * 50) + 192); + } + }; + makeLore(x.join("")); + } + templePlayer.room3ToEndAnim++; + }, + end() { + if (!templePlayer.clearedCycle) return; + Promise.resolve().then(() => { + ctx.save(); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.fillStyle = `rgba(0, 0, 0, ${(simulation.cycle - templePlayer.clearedCycle) / 30})`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.restore(); + }); + if (simulation.cycle - templePlayer.clearedCycle > 30) level.nextLevel(); + } + }; + const LogicHandler = { + bounds() { + let isInBounds = false; + for (const b of bounds) { + if (isInBound(b)) { + isInBounds = true; + break; + } + } + if (!isInBounds) { + m.damage(0.1 * simulation.difficultyMode); + trapPlayer(level.enter.x, level.enter.y); + simulation.inGameConsole("" + name + ":   You thought I could let you get away with that?"); + } + }, + room0() { + // Block the player from entering the first seemingly innocuous exit + if ((m.pos.x > 1000) && templePlayer.startAnim === 0) { + spawn.mapRect(1200, -500, 100, 600); + templePlayer.initialTrapY = Math.min(player.position.y, -75); + trapPlayer(1000, templePlayer.initialTrapY); + + addPartToMap(); + simulation.draw.setPaths(); + templePlayer.startAnim = 1; + } + }, + room1() { + WaveHandler.room1(); + Objects.altar.logic(); + }, + room2() { + room2SlimePit.logic(); + Objects.room2Initiator.logic(); + Objects.room2Lightning.logic(); + Objects.room2GeneratedPath.logic(); + WaveHandler.room2(); + }, + room3() { + Objects.room3Rotors.logic(); + Objects.room3SlimePits.logic(); + WaveHandler.room3(); + }, + exit() { + if (!templePlayer.drawExit) return; + if (player.position.x > level.exit.x && + player.position.x < level.exit.x + 100 && + player.position.y > level.exit.y - 150 && + player.position.y < level.exit.y - 40 && + player.velocity.y < 0.1 && + level.exitCount + (input.down ? 8 : 2) > 100) { + if (templePlayer.stage === 1) { + templePlayer.drawExit = false; + level.exitCount = 0; + templePlayer.room1ToRoom2Anim = 1; + } else if (templePlayer.stage === 2) { + templePlayer.drawExit = false; + templePlayer.room2ToRoom3Anim = 1; + level.exitCount = 0; + } else { + level.exitCount = 99 - (input.down ? 8 : 2); + if (!templePlayer.clearedCycle) templePlayer.clearedCycle = simulation.cycle; + } + } + } + }; + const DrawHandler = { + // Bottom layer + base() { + // Draw base red background + ctx.save(); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.fillStyle = color.map; + ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.restore(); + + // Draw the normal bg on the bounds + ctx.fillStyle = "#eab6af"; + for (const b of bounds) { + if (isInBound(b)) ctx.fillRect(b.pos.x + 2, b.pos.y + 2, b.width - 4, b.height - 4); + } + }, + entrance() { + ctx.beginPath(); + ctx.moveTo(level.enter.x, level.enter.y + 30); + ctx.lineTo(level.enter.x, level.enter.y - 80); + ctx.bezierCurveTo(level.enter.x, level.enter.y - 170, level.enter.x + 100, level.enter.y - 170, level.enter.x + 100, level.enter.y - 80); + ctx.lineTo(level.enter.x + 100, level.enter.y + 30); + ctx.lineTo(level.enter.x, level.enter.y + 30); + ctx.fillStyle = "#fca"; + ctx.fill(); + }, + room1() { + if (!isInBound(firstRoomBounds)) return; + + // Draw Cross + ctx.fillStyle = "#fed"; + ctx.fillRect(2200, -3300, 200, 800); + ctx.fillRect(2000, -3100, 600, 200); + + // Final boss-like spawn fire thing. Was it necessary? No! + const spawnFlameAngle = Math.min(Math.min(templePlayer.room1.cycles, 2520) % 600, 120) * Math.PI / 30 + Math.PI / 2; + DrawTools.flame([2300, -3000, 26, 4, "#f60", spawnFlameAngle], 7); + + Objects.altar.drawBottom(); + }, + room2() { + if (!isInBound(secondRoomBounds)) return; + + if (templePlayer.room2.cycles) { + ctx.fillStyle = "#0006"; + ctx.fillRect(secondRoomBounds.pos.x + 2, secondRoomBounds.pos.y + 2, secondRoomBounds.width - 4, secondRoomBounds.height - 4); + } + room2SlimePit.draw(); + }, + room3() { + if (!isInBound(thirdRoomBounds)) return; + ctx.fillStyle = "#0006"; + ctx.fillRect(thirdRoomBounds.pos.x + 2, thirdRoomBounds.pos.y + 2, thirdRoomBounds.width - 4, thirdRoomBounds.height - 4); + Objects.room3SlimePits.draw(); + }, + // Top layer + mobTrails() { + if (simulation.cycle % 4 === 0) { + let newMobPositions = []; + for (const i of mob) { + if (!(i.isDarkMatter || i.isWIMP || i.isObstacle)) newMobPositions.push({ + x: i.position.x, + y: i.position.y + }); + } + mobPositionsQueue.shift(); + mobPositionsQueue.push(newMobPositions); + } + // Draw "holy" trails for mobs for no particular reason at all + ctx.strokeStyle = "#bae"; + ctx.lineWidth = 3; + for (let i = 0; i < 10; i++) { + const p = mobPositionsQueue[i]; + for (const m of p) { + DrawTools.holy(m.x, m.y, i / 2 + 10); + } + } + ctx.shadowBlur = 0; + }, + waveTimer() { + const roomConditions = [ + isInBound(firstRoomBounds) && templePlayer.room1.cycles < 2400, + isInBound(secondRoomBounds) && templePlayer.room2.cycles > 0 && templePlayer.room2.cycles < 2160, + isInBound(thirdRoomBounds) && templePlayer.room2ToRoom3Anim < 540 + ]; + Promise.resolve(roomConditions).then(roomConditions => { + // First Room + if (roomConditions[0]) { + ctx.save(); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.fillStyle = "#0004"; + ctx.fillRect(canvas.width2 - 288, 50, 576, 20); + ctx.fillStyle = "#0cf"; + ctx.fillRect(canvas.width2 - 288, 50, 0.96 * (600 - templePlayer.room1.cycles % 600), 20); + ctx.restore(); + } + // Second Room + if (roomConditions[1]) { + ctx.save(); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.fillStyle = "#0004"; + ctx.fillRect(canvas.width2 - 288, 50, 576, 20); + ctx.fillStyle = (Math.ceil(templePlayer.room2.cycles / 720) & 1) ? "#000" : "#e1d7ff"; + ctx.fillRect(canvas.width2 - 288, 50, 0.8 * (720 - templePlayer.room2.cycles % 720), 20); + ctx.restore(); + } + // Third Room + if (roomConditions[2]) { + ctx.save(); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.fillStyle = "#0004"; + ctx.fillRect(canvas.width2 - 288, 50, 576, 20); + ctx.fillStyle = "#000"; + ctx.fillRect(canvas.width2 - 288, 50, 1.6 * (540 - templePlayer.room2ToRoom3Anim), 20); + ctx.restore(); + } + }); + }, + room2Top() { + if (!isInBound(secondRoomBounds)) return; + Objects.room2Lightning.draw(); + Objects.room2GeneratedPath.draw(); + Objects.room2Initiator.draw(); + } + }; + const WaveHandler = { + room1() { + if (!isInBound(firstRoomBounds)) return; + if (templePlayer.room1.cycles === 0) powerUps.spawnStartingPowerUps(0, -2050); + templePlayer.room1.cycles++; + if (templePlayer.room1.cycles === 2400) { + spawn.secondaryBossChance(2300, -2800); + powerUps.addResearchToLevel(); + } + if (templePlayer.room1.cycles % 600 === 0 && templePlayer.room1.cycles <= 2400) { + const spawnAmt = Math.min(3 + Math.pow(simulation.difficulty / 1.7, 0.6), 10) + Math.floor(templePlayer.room1.cycles / 720); + for (let i = 0; i < spawnAmt; i++) { + if (Math.random() < 0.5 + 0.07 * simulation.difficulty) { + spawn.randomMob(800 + Math.random() * 3e3, -2400 - Math.random() * 600, Infinity); + } + } + spawn.randomMob(800 + Math.random() * 3e3, -2400 - Math.random() * 600, Infinity); + } + if (templePlayer.room1.cycles === 2520) { + templePlayer.drawExit = true; + } + }, + room2() { + if (!isInBound(secondRoomBounds)) return; + if (templePlayer.room2.spawnInitiatorCycles > Objects.room2Initiator.cap) { + const randomSecondRoomBoss = [secondRoomSuckerBoss, secondRoomPlacerBoss]; + if (templePlayer.room2.cycles % 720 === 0 && templePlayer.room2.cycles <= 2160) { + const isOdd = Math.floor(templePlayer.room2.cycles / 720) & 1; + randomSecondRoomBoss[Math.floor(randomSecondRoomBoss.length * Math.random())](-600, -9800, isOdd); + randomSecondRoomBoss[Math.floor(randomSecondRoomBoss.length * Math.random())](600, -9800, isOdd); + randomSecondRoomBoss[Math.floor(randomSecondRoomBoss.length * Math.random())](0, -9800, !isOdd); + } + templePlayer.room2.cycles++; + if (templePlayer.room2.cycles === 2400) { + templePlayer.drawExit = true; + templePlayer.room2.readyPathCycle = simulation.cycle; + } + } + }, + room3() { + if (templePlayer.room2ToRoom3Anim === 540) { + thirdRoomBoss(1800, -13700); + for (let i = 0; i < 3; i++) { + powerUps.spawn(m.spawnPos.x, m.spawnPos.y, "heal"); + } + } + } + }; + const DrawTools = { + randomColours(alpha = 1) { + return `rgba(${this._randomColours.join(",")},${alpha})` + }, + _randomColours: [Math.random() * 255, Math.random() * 255, Math.random() * 255], + updateRandomColours(x = 0.8) { + for (let i = 0; i < this._randomColours.length; i++) { + this._randomColours[i] = Math.max(Math.min(this._randomColours[i] + (this.randFact() * x * 2) - x, 255), 0); + } + }, + randFact() { + return Math.random() * 0.8 + Math.sin(Date.now() / 300) * 0.2; + }, + + line(vecs) { + ctx.beginPath(); + ctx.moveTo(vecs[0].x, vecs[0].y); + for (const v of vecs.slice(1)) ctx.lineTo(v.x, v.y); + ctx.stroke(); + }, + arc(...x) { + ctx.beginPath(); + ctx.arc(...x); + ctx.fill(); + }, + arcOut(...x) { + ctx.beginPath(); + ctx.arc(...x); + ctx.stroke(); + }, + flame(props, repeat) { + for (let i = 0; i < repeat; i++) this.singleFlame(...props); + }, + singleFlame(x, y, size = 10, repeat = 3, color = "#f00", angle = Math.PI / 2) { + ctx.strokeStyle = color; + ctx.lineWidth = 3; + const path = [{ + x, + y + }]; + for (let i = 0; i < repeat; i++) { + const randAng = (Math.random() - 0.5) * 2 + angle; + const randLen = 2 * size + Math.random() * size; + + x += Math.cos(randAng) * randLen; + y -= Math.sin(randAng) * randLen; + path.push({ + x, + y + }) + } + DrawTools.line(path); + }, + lightning(from, to, cycle, randomPRNGMult = 1, width = 8, color = [255, 240, 127]) { + const diff = simulation.cycle - cycle; + if (diff >= 15) return; + ctx.strokeStyle = `rgba(${color.join(",")},${(1 - diff / 15) * 255})`; + ctx.lineWidth = width * (1 - diff / 15); + ctx.shadowColor = `rgb(${color.join(",")})`; + ctx.shadowBlur = 20; + const path = [{ + x: from.x, + y: from.y + }]; + let vector = { + x: from.x, + y: from.y + }; + let distanceLeft = V.magnitude(V.sub(from, to)); + const d = distanceLeft > 800 ? distanceLeft / 40 : 20; + const normalised = V.normalise(V.sub(to, from)); + while (1) { + const randOffset = rotateVector({ + y: RNG(Math.floor(cycle * randomPRNGMult + distanceLeft)) * 2 * d - d, + x: 0 + }, normalised); + const randLen = RNG(Math.floor(cycle * (randomPRNGMult + 1) + distanceLeft)) * d + d; + distanceLeft -= randLen; + if (distanceLeft <= 0) { + path.push({ + x: to.x, + y: to.y + }); + break; + } + vector = V.add(vector, V.mult(normalised, randLen)); + path.push({ + x: vector.x + randOffset.x, + y: vector.y + randOffset.y + }); + } + DrawTools.line(path); + ctx.shadowBlur = 0; + }, + holy(x, y, size = 12) { + this.line([{ + x, + y: y - size + }, { + x: x - size, + y + }, + { + x, + y: y + size + }, { + x: x + size, + y + }, { + x, + y: y - size + } + ]); + } + }; + + function RNG(x) { + x += Math.seed; + let start = Math.pow(x % 97, 4.3) * 232344573; + const a = 15485863; + const b = 521791; + start = (start * a) % b; + for (let i = 0; i < (x * x) % 90 + 90; i++) { + start = (start * a) % b; + } + return start / b; + } + + function rotateVector(v, ang) { + const c = typeof ang === "number" ? { + x: Math.cos(ang), + y: Math.sin(ang) + } : V.normalise(ang); + return { + x: v.x * c.x - v.y * c.y, + y: v.y * c.x + v.x * c.y + }; + } + + function trapPlayer(x, y) { + setPosAndFreeze(player, { + x, + y + }); + const bLen = bullet.length; + for (let i = 0; i < bLen; i++) { + if (bullet[i].botType) setPosAndFreeze(bullet[i], V.add(player.position, { + x: 100 * (RNG(i) - 0.5), + y: 100 * (RNG(i + bLen) - 0.5) + })); + } + } + + function relocateTo(x, y) { + level.setPosToSpawn(x, y); + trapPlayer(x, y); + for (let i = 0; i < mob.length; i++) { + if (mob[i].isDarkMatter) { + setPos(mob[i], { + x, + y + }); + break; + } + } + m.resetHistory(); + } + const distance = (a, b) => V.magnitude(V.sub(a, b)); + const angle = (a, b) => Math.atan2(b.y - a.y, a.x - b.x); + const setPos = (a, b) => Matter.Body.setPosition(a, b); + const setVel = (a, b) => Matter.Body.setVelocity(a, b); + const freeze = a => setVel(a, { + x: 0, + y: 0 + }); + const setPosAndFreeze = (a, b) => { + setPos(a, b); + freeze(a); + }; + const makeLore = (x, t) => simulation.inGameConsole(`

${name}:

 

${x}

`, t); + level.custom = () => { + // All the logic gets handled here. How nice! + for (const i in LogicHandler) { + LogicHandler[i](); + } + + // Animations and lore for things that seem like exits + for (const i in RoomTransitionHandler) { + RoomTransitionHandler[i](); + } + + // Bottom layer graphics + DrawHandler.base(); + DrawHandler.room1(); + DrawHandler.room2(); + DrawHandler.room3(); + DrawHandler.entrance(); + if (templePlayer.drawExit) level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + // Top layer graphics + DrawHandler.mobTrails(); + Objects.altar.drawTop(); + DrawHandler.waveTimer(); + DrawHandler.room2Top(); + }; + }, + dripp() { + simulation.inGameConsole(`dripp by M. B.`); + + const door = level.door(780, -350, 15, 400, 265); + const buttonDoor = level.button(420, -10); + const boost = level.boost(130, -445); + const hazard = level.hazard(690, -1050, 10, 700, 0.4) + const hazard2 = level.hazard(2470, -1515, 162, 14, 0.4) + const hazard3 = level.hazard(740, -1050, 10, 700, 0.4) + const hazard4 = level.hazard(3400, -380, 350, 6, 0.2) + const hazard5 = level.hazard(3425, -1420, 400, 8, 0.2) + const slimePit = level.hazard(2250, -100, 2700, 200, 0.004) + const door2 = level.door(3131, -898, 40, 520, 522) + const buttonDoor2 = level.button(2495, -270) + const toggle = level.toggle(1463, -708, true) + const elevator = level.elevator(4310, -150, 200, 50, -1443, 0.0025, { + up: 0.1, + down: 0.2 + }) + const portal = level.portal({ //main portals + x: 2117, + y: -1560 + }, -2 * Math.PI, { //up + x: -80, + y: -475 + }, -Math.PI / 100) //up + + const drip1 = level.drip(4100 + 1000 * Math.random(), -1900, 50, 100) // drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + const drip2 = level.drip(4100 + 1000 * Math.random(), -1900, 50, 207) // drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + const drip3 = level.drip(4100 + 1000 * Math.random(), -1900, 50, 133) // drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + const drip4 = level.drip(4100 + 1000 * Math.random(), -1900, 50, 157) // drip(x, yMin, yMax, period = 100, color = "hsla(160, 100%, 35%, 0.5)") { + + level.custom = () => { + level.exit.drawAndCheck(); + + drip1.draw() + drip2.draw() + drip3.draw() + drip4.draw() + buttonDoor.query(); + buttonDoor.draw(); + if (buttonDoor.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + + buttonDoor2.query(); + buttonDoor2.draw(); + if (buttonDoor2.isUp) { + door2.isClosing = true + } else { + door2.isClosing = false + } + door2.openClose(); + + // shadow/shades builds + ctx.fillStyle = "rgba(0, 0, 0, 0.05)" + ctx.fillRect(3169, -900, 891, 580) + ctx.fillRect(417, -1057, 380, 730) + ctx.fillRect(930, -515, 207, 520) + ctx.fillRect(930, -1280, 207, 760) + ctx.fillRect(1220, -1280, 54, 800) + ctx.fillRect(1221, -1394, 451, 1398) + ctx.fillRect(1924, -800, 219, 674) + ctx.fillRect(2264, -1488, 214, 1550) + ctx.fillRect(2631, -1488, 201, 1550) + ctx.fillRect(2889, -930, 237, 1090) + ctx.fillRect(3124, -311, 957, 360) + ctx.fillRect(1919, -1480, 220, 700) + // ctx.fillRect(1768, -1200, 71, 500) + level.enter.draw(); + elevator.move(); + toggle.query(); + }; + level.customTopLayer = () => { + boost.query(); + hazard.opticalQuery(); + hazard2.opticalQuery(); + hazard3.opticalQuery(); + hazard4.opticalQuery(); + hazard5.opticalQuery(); + slimePit.query(); + // slimePit.draw(); + hazard.isOn = toggle.isOn + hazard3.isOn = toggle.isOn + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[2].query() + portal[3].query() + }; + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 1400; + level.exit.y = -1500; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + + //builds + spawn.mapRect(-100, 0, 1485, 100); + spawn.mapRect(-279, -750, 200, 850); + spawn.mapRect(1781, -125, 375, 75); + spawn.mapRect(1670, -100, 590, 200); + spawn.mapRect(2261, 50, 3100, 50); + spawn.mapRect(2420, -260, 300, 50); + spawn.bodyRect(235, -240, 50, 50, 1, spawn.propSLide) + spawn.mapRect(410, -1100, 400, 50); + spawn.mapRect(1220, -1470, 420, 80) + spawn.mapRect(927, -1325, 220, 50); + spawn.mapRect(4950, -200, 425, 375); + spawn.bodyRect(5200, -300, 100, 100); + + //random builds + spawn.mapRect(2150, 50, 225, 50); + + //large border walls + spawn.mapRect(-300, -2375, 6075, 475); + spawn.mapRect(-951, -2374, 675, 2476); + spawn.mapRect(-950, 100, 6950, 500); + spawn.mapRect(5300, -2374, 700, 2700); + + // create enemies + spawn.randomMob(3000, -300, 0.5); + spawn.randomMob(1900, -1000, 0.5); + spawn.randomMob(2960, -800, 0.6) + spawn.randomMob(3500, -1700, 0.4) + spawn.randomMob(800, -1700, 0.6) + spawn.randomMob(100, -1150, 0.6) + spawn.randomMob(1095, -700, 0.6) + + //powerUps + powerUps.spawn(590, -200, "ammo") + powerUps.spawn(600, -200, "heal") + // powerUps.spawn(590, -200, "gun") + powerUps.spawnStartingPowerUps(590, -200); + + // more builds + spawn.blockDoor(1230, -1490) + // spawn.blockDoor(728, -1130); + spawn.mapRect(-100, -380, 900, 50); + spawn.mapRect(-279, -1400, 200, 650); + spawn.mapRect(-279, -1900, 200, 650); + // spawn.mapRect(-100, -1900, 2300, 75); + // spawn.mapRect(2200, -1900, 1025, 75); + // spawn.mapRect(2700, -1900, 2000, 75); + spawn.mapRect(2270, -1530, 199, 50); + spawn.mapRect(2633, -1530, 199, 50) + // spawn.mapRect(4570, -1825, 125, 1925); + spawn.mapRect(3106, -400, 300, 50) + spawn.mapRect(3750, -400, 330, 50) + spawn.mapRect(3130, -1030, 930, 130); + spawn.mapRect(4015, -900, 46, 275); + spawn.blockDoor(4016, -400) + spawn.mapRect(3168, -1440, 290, 50); + spawn.mapRect(3771, -1440, 294, 50); + spawn.mapRect(3106, -355, 974, 42); + spawn.mapRect(3228, -1395, 834, 380); + spawn.mapRect(3129, -1350, 100, 325); + spawn.mapRect(3129, -1400, 175, 100); + spawn.mapRect(3129, -1437, 125, 75); + spawn.mapRect(1382, 0, 295, 100); + spawn.mapRect(1600, -50, 560, 85); + spawn.mapRect(2264, -945, 220, 50); + spawn.mapRect(1925, -800, 220, 50); + spawn.mapRect(1390, -700, 260, 50); + spawn.mapRect(927, -520, 220, 50); + spawn.mapRect(2894, -948, 300, 50) + spawn.mapRect(1230, -1825, 440, 81); + spawn.mapRect(1616, -1750, 54, 360); + spawn.mapRect(3128, -1440, 50, 50); + spawn.mapRect(1705, -120, 125, 75); + spawn.mapRect(1550, -25, 150, 50); + spawn.mapRect(1628, -75, 100, 50); + spawn.mapRect(1729, -130, 650, 75); + //ground for blue portal + spawn.mapRect(1917, -1484, 300, 50); + spawn.mapRect(1917, -1950, 200, 325); + spawn.mapRect(1917, -1825, 50, 375); + + //split + spawn.mapRect(1221, -1420, 57, 465); + spawn.mapRect(1221, -634, 57, 450); + spawn.bodyRect(1227, -105, 42, 189, 1, spawn.propSlide) + // spawn.mapRect(1770, -1900, 70, 750); + spawn.mapRect(1770, -780, 70, 400) + spawn.bodyRect(1783, -289, 38, 250, 1, spawn.propSlide) + if (simulation.difficulty > 1) spawn.randomLevelBoss(4800, -750); + spawn.secondaryBossChance(4700, -1500) + + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + biohazard() { + // MAP BY INOOBBOI AND THESHWARMA + simulation.inGameConsole(`biohazard by INOOBBOI and THESHWARMA`); + + // set here for the cutscene later + level.setPosToSpawn(-2800, -150) + + // set up cutscenes + simulation.cutscene = (locations, speed, stay, xPos = m.pos.x, yPos = m.pos.y) => { + // locations: an array of location vectors, reversed for the pop ahead + locations.reverse() + // speed: the speed of the cutscene transition (0 to 1) + // stay: how much to stay in the destination (ticks) + // xPos & yPos: the initial location, also used as the current location + + // start by disabling the default camera draw. Don't worry, it's backed up + const camera = simulation.camera + // create a new camera function + simulation.camera = () => { + ctx.save() + ctx.translate(canvas.width2, canvas.height2) //center + ctx.scale(simulation.zoom, simulation.zoom) + const xScaled = canvas.width2 - xPos + const yScaled = canvas.height2 - yPos + ctx.translate(-canvas.width2 + xScaled, -canvas.height2 + yScaled) //translate + } + + // and set a restoring function + const restore = () => (simulation.camera = camera) + + // then choose the next destination. There should be always at least one destination, + // if there isn't there's no point checking, the game should and will crash + let dest = locations.pop() + // animate the camera + const lerp = (first, second, percent) => first * (1 - percent) + second * percent + const speedDelta = speed / 5 + // wait timer + let wait = 0 + // polls the animation, should be called every tick + const poll = () => { + // update position + xPos = lerp(xPos, dest.x, speedDelta) + yPos = lerp(yPos, dest.y, speedDelta) + // if position is close enough, wait and go to the next position + const TOO_CLOSE = 100 + if (Math.abs(dest.x - xPos) < TOO_CLOSE && Math.abs(dest.y - yPos) < TOO_CLOSE) { + // wait for a bit + if (++wait > stay) { + // if there is another target, reset the wait timer and go there + // otherwise end the cutscene + wait = 0 + if (!(dest = locations.pop())) { + // no more locations! End + restore() + return true + } + } + } + // early return if the player skips by fielding + if (input.field) { + restore() + return true + } + return false + } + return poll + } + + const boost1 = level.boost(-1400, -100, 900) + const boost2 = level.boost(500, -900, 2500) + const boost3 = level.boost(4200, -100, 900) + const boost4 = level.boost(2200, -900, 2500) + + const toggle = level.toggle(1340, -600, false, true) + + let bossInit = false + + const cutscenePoll = simulation.cutscene([{ + x: 230, + y: -2700 + }, { + x: 3500, + y: -1400 + }, { + x: 1450, + y: -1150 + }, m.pos], 0.1, 10) + let hasEnded = false + + // ** PROPS ** + // create some drips + const rndInRange = (min, max) => Math.random() * (max - min) + min + + const amount = Math.round(5 + 20 * Math.random()) + const drips = [] + for (let i = 0; i < amount; i++) { + const locX = rndInRange(-2000, 4800) + drips.push(level.drip(locX, -3100, 1500, 200 + Math.random() * 500)) + } + + // a barrel of radioactive waste, which can drop ammo and heals + const barrelMob = (x, y, dirVector) => { + const MAX_WIDTH = 150 + const personalWidth = MAX_WIDTH / 2 + mobs.spawn(x, y, 4, personalWidth, 'rgb(232, 191, 40)') + const me = mob[mob.length - 1] + // steal some vertices + const betterVertices = Matter.Bodies.rectangle(x, y, personalWidth, personalWidth * 1.7).vertices + me.vertices = betterVertices + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.mob | cat.bullet + me.g = simulation.g + me.leaveBody = me.isDropPowerUp = false + me.do = function () { + this.gravity() + // apply shock damage when touching the map, if it's fast + if (this.speed > 5) { + const collision = Matter.Query.collides(this, map) + if (collision.length > 0) { + // on collision reduce health + this.health = this.health - this.speed / 250 + // die when it's too low, doesn't register for some reason + } + } + // becomes more radioactive as it gets damaged! + this.fill = `rgb(${232 * this.health}, 191, 40)` + } + + me.onDeath = function () { + const END = Math.floor(input.down ? 10 : 7) + const totalBullets = 10 + const angleStep = (input.down ? 0.4 : 1.3) / totalBullets + let dir = m.angle - (angleStep * totalBullets) / 2 + for (let i = 0; i < totalBullets; i++) { + //5 -> 7 + dir += angleStep + const me = bullet.length + bullet[me] = Bodies.rectangle( + this.position.x + 50 * Math.cos(this.angle), + this.position.y + 50 * Math.sin(this.angle), + 17, + 4, + b.fireAttributes(dir) + ) + const end = END + Math.random() * 4 + bullet[me].endCycle = 2 * end + simulation.cycle + const speed = (25 * end) / END + const dirOff = dir + (Math.random() - 0.5) * 3 + Matter.Body.setVelocity(bullet[me], { + x: speed * Math.cos(dirOff), + y: speed * Math.sin(dirOff) + }) + bullet[me].onEnd = function () { + b.explosion( + this.position, + 150 + (Math.random() - 0.5) * 40 + ) //makes bullet do explosive damage at end + } + bullet[me].beforeDmg = function () { + this.endCycle = 0 //bullet ends cycle after hitting a mob and triggers explosion + } + bullet[me].do = function () { } + Composite.add(engine.world, bullet[me]) //add bullet to world + } + // barrels drop a ton of ammo and some heals, scales up with difficulty because I have mercy + const amount = ~~(5 * Math.random() * simulation.difficulty / 10) + for (let i = 0; i < amount; i++) { + powerUps.spawn(this.position.x, this.position.y, 'ammo', true) + if (Math.random() > 0.7) { + powerUps.spawn(this.position.x, this.position.y, 'heal', true) + } + } + } + Matter.Body.rotate(me, Math.random() * Math.PI) + Matter.Body.setVelocity(me, dirVector) + } + + // creates a platform with shadow + const platformShadow = (x, y, width, height, shadowList) => { + // faster than making manual shadows... Why not just calculate them semi-realsitically? + // the shadows are calculated on the object creation, so if you add map blocks it won't update. + // shadowList is an array of shadows that'll be rendered. When the platform shadow is ready, + // it is added to the list. + // some helper functions first + const perpCollision = point => { + // takes a point, and finds a collision with the map downwards + // the end of the ray, 3000 units down + const lowerPoint = Vector.add(point, { + x: 0, + y: 3000 + }) + // the destination point. If a collision was not found, then it defaults to some + // arbiterary point 3000 units down. + let dest = lowerPoint + for (const mapBody of map) { + const check = simulation.checkLineIntersection(point, lowerPoint, mapBody.vertices[0], mapBody.vertices[1]) + // a collision was found + if (check.onLine1 && check.onLine2) { + dest = { + x: check.x, + y: check.y + } + break + } + } + return dest + } + const boundsToRectangle = (firstBound, secondBound) => { + // takes two bounds and returns an (x, y, width, height) rectangle. The first one + // must be the top left, and the second one must be the bottom right + // sub to find the width and height + const width = Math.abs(firstBound.x - secondBound.x) + const height = Math.abs(firstBound.y - secondBound.y) + // compile to an object + return { + x: firstBound.x, + y: firstBound.y, + width, + height + } + } + // create the actual platform + spawn.mapRect(x, y, width, height) + const me = map[map.length - 1] + // the bottom vertices are the third and fourth ones + const first = me.vertices[3] + const second = me.vertices[2] + // cast shadows to find the last shadow location. + // iterate over all map objects, and check for collisions between a perpendicular ray + // cast from the vertex down to the map object's top panel + // const firstDown = perpCollision(first) // not needed in a rectangle settings + const secondDown = perpCollision(second) + // possible TODO: make it multirect for efficiency + // create a single rectangle and return + shadowList.push(boundsToRectangle(first, secondDown)) + } + + // cages with mobs, One of them holds the boss pre mutation + const cage = (x, y, maxChainLength, drawList, mobType = null, isTheBoss = false) => { + // the drawList is an array that the drawing function is added to + // if the cage containing the boss it has a 50% chance to just not spawn. Spices things a bit + if (!isTheBoss && Math.random() > 0.5) { + return + } + if (!mobType) { + // if mob type is null, then it picks a random mob + mobType = spawn.fullPickList[~~(Math.random() * spawn.fullPickList.length)] + } + // create the chain length, must take into account the radius of the mob. + // therefore, it'll create a pseudo mob of that type, take it radius and instantly kill it + const chainLength = maxChainLength / 5 + maxChainLength * Math.random() + + // spawn and insantly kill a mob of the same type to get the radius. + // this is used to prevent spawning the mob too short, it's a horrible + // solution but it works + spawn[mobType](0, 0) + mob[mob.length - 1].leaveBody = mob[mob.length - 1].isDropPowerUp = false + const radius = mob[mob.length - 1].radius + mob[mob.length - 1].alive = false + // spawn the mob. Disable shields first + spawn.allowShields = false + spawn[mobType](x, y + chainLength + radius * 2) + const trappedMob = mob[mob.length - 1] + // destroy its mind so it won't attack + trappedMob.do = () => { } + // spawn the cage + mobs.spawn(x, y + chainLength + radius * 2, 4, trappedMob.radius + 50, 'rgba(150, 255, 150, 0.3)') + const cage = mob[mob.length - 1] + cage.g = simulation.g + cage.do = function () { + this.gravity() + } + // label it + cage.label = 'Cage' + // a special orb when hit + let damageTick = 0 + cage.onDamage = (dmg) => { + // add some damage ticks, if the trapped mob is still alive. + // activating the boss by this method is almost impossible, since you need 10x damage + if (trappedMob.alive) damageTick += ~~(isTheBoss ? 5 * dmg : 50 * dmg) + } + // collision filter + trappedMob.collisionFilter.mask = cage.collisionFilter.mask = cat.player | cat.map | cat.bullet + // constrain together + spawn.constrain2AdjacentMobs(2, 0.05, false) + // move them to be together + trappedMob.position = Vector.clone(cage.position) // make sure you clone... Otherwise........ + // invincibility, make homing bullets not hit these, remove health bar + trappedMob.health = cage.health = Infinity + trappedMob.isBadTarget = cage.isBadTarget = true + trappedMob.showHealthBar = cage.showHealthBar = false + trappedMob.leaveBody = trappedMob.isDropPowerUp = cage.leaveBody = cage.isDropPowerUp = false + // cross all edges of the cage with the rope, and see where it collides. Attach the rope there + const verts = cage.vertices + // the crossing location, doesn't stay null + let cross = null + for (let i = 0; i < verts.length; i++) { + // iterate over all vertices to form lines + const v1 = verts[i] + const v2 = verts[(i + 1) % verts.length] + const result = simulation.checkLineIntersection(cage.position, { + x, + y + }, v1, v2) + if (result.onLine1 && result.onLine2) { + // both lines cross! + cross = result + break + } + } + + if (!cross) { + // for some odd reason, sometimes it never finds a collision. I have no idea why + // just default to the center then + console.error("Couldn't find a cross... Origin: ", { + x, + y + }, " center: ", cage.position, ' vertices: ', cage.vertices) + cross = cage.position + } + // create the rope + const rope = Constraint.create({ + pointA: { + x, + y + }, + // offset the point be in the attachment point + pointB: Vector.sub(cross, cage.position), + bodyB: cage, + // the longer the rope, the looser it is + stiffness: Math.max(0.0005 - chainLength / 10000000, 0.00000001), + length: chainLength + }) + Matter.Composite.add(engine.world, rope) + // create and return a function for drawing the rope + const draw = () => { + // draw a little recantagle at the base + ctx.fillStyle = color.map + ctx.fillRect(x - 20, y - 5, 40, 25) + // if the cage was destroyed... Do nothing beyond + if (!cage.alive) { + return + } + // draw the rope + ctx.beginPath() + ctx.moveTo(x, y) + // line to the crossing point + // ctx.lineTo(cons[i].bodyB.position.x, cons[i].bodyB.position.y); + ctx.lineTo(cage.position.x + rope.pointB.x, cage.position.y + rope.pointB.y); + ctx.lineWidth = 7 + ctx.strokeStyle = 'rgba(0, 0, 0, 0.5)' + ctx.stroke() + // now draw a mystic hit orb if touched + if (damageTick) damageTick-- // reduce the ticks + ctx.beginPath() + ctx.arc(cage.position.x, cage.position.y, cage.radius + 30, 0, Math.PI * 2) + ctx.lineWidth = 10 + ctx.fillStyle = `rgba(255, 0, 0, ${Math.min(1, damageTick / 2000)})` + ctx.strokeStyle = `rgba(255, 100, 0, ${Math.min(1, damageTick / 1000)})` + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]) + ctx.stroke() + ctx.setLineDash([]) + ctx.fill() + // if it's the boss, draw sucking arcs + if (isTheBoss && bossInit) { + for (const entity of mob) { + // suck the health of all mobs + // I hate string manipulation in control flow but heh + if (entity.alive) { + ctx.beginPath() + ctx.moveTo(entity.position.x, entity.position.y) + ctx.lineTo(trappedMob.position.x, trappedMob.position.y) + ctx.lineWidth = 10 + ctx.strokeStyle = 'rgba(38, 0, 255, 0.67)' + ctx.stroke() + // damage the mob + entity.damage(1) + // damage itself bonus + cage.damage(1) + } + } + cage.damage(5) + } + + // ok if it's too much, explode + if (damageTick > 2000) { + b.explosion(cage.position, cage.radius * 10) + // die a silent death + trappedMob.alive = cage.alive = false + damageTick = 0 + if (isTheBoss) { + // become the real boss + geneticBoss(trappedMob.position.x, trappedMob.position.y) + } + } + } + // restore the shields + spawn.allowShields = true + // add the drawing function + drawList.push(draw) + } + + // platform shadows + const shadows = [] + // cages + const cages = [] + + level.custom = () => { + level.exit.drawAndCheck() //draws the exit + level.enter.draw() //draws the entrance + + player.force.y -= player.mass * simulation.g * 0.25 //this gets rid of some gravity on player + + // if the cutscene is yet to end, continue polling + if (!hasEnded) { + hasEnded = cutscenePoll() + } + + for (const drip of drips) drip.draw() + // throw some barrels after the boss spawns + if (Math.random() > 0.999 && bossInit && !hasEnded) { + const spawnLocs = [-1415, -30, 1345, 2815, 4285] + // const randVec = Vector.mult({ x: Math.cos(randAngle), y: Math.sin(randAngle) }, Math.random() * 15) + barrelMob(spawnLocs[~~(spawnLocs.length * Math.random())], -4200, { + x: 0, + y: 0 + }) + } + + // platform shadow + ctx.beginPath() + for (const shadow of shadows) { + ctx.rect(shadow.x, shadow.y, shadow.width, shadow.height) + } + ctx.fillStyle = 'rgba(0,10,30,0.1)' + ctx.fill() + + // player pressed lever + if (toggle.isOn && !bossInit) { + bossInit = true + } + // draw the cage + } //for dynamic stuff that updates while playing that is one Z layer below the player + + level.customTopLayer = () => { + boost1.query() + boost2.query() + boost3.query() + boost4.query() + toggle.query() + + // shadow holes + ctx.fillStyle = 'rgba(68, 68, 68,0.95)' + ctx.fillRect(-1450 - 10, -4350, 150 + 20, 1250) + ctx.fillRect(-50 - 10, -4350, 150 + 20, 1250) + ctx.fillRect(1325 - 10, -4350, 150 + 20, 1250) + ctx.fillRect(2800 - 10, -4350, 150 + 20, 1250) + ctx.fillRect(4275 - 10, -4350, 150 + 20, 1250) + + for (const drawCage of cages) { + drawCage() + } + } //for dynamic stuff that updates while playing that is one Z layer above the player + + const anotherBoss = (x, y) => { + if (tech.isDuplicateMobs && Math.random() < tech.duplicationChance()) { + spawn.historyBoss(x, y) + } + } + + //GENETICBOSS + function drawEnergyBar(mob) { + if (mob.seePlayer.recall && mob.energy > 0) { + const h = mob.radius * 0.3 + const w = mob.radius * 2 + const x = mob.position.x - w / 2 + const y = mob.position.y - w * 0.9 + ctx.fillStyle = 'rgba(100, 100, 100, 0.3)' + ctx.fillRect(x, y, w, h) + ctx.fillStyle = '#0cf' + ctx.fillRect(x, y, w * mob.energy, h) + } + } + + function generateGenome() { + // creates a random genome and returns it + const genome = { + density: Math.random() * 0.001, + size: 15 + Math.random() * 15, + speed: Math.random() * 0.1, + // color and vertex properties are "trash" genes as they don't really contribute to the orb + color: [Math.random() * 255, Math.random() * 255, Math.random() * 255, 50 + Math.random() * 205], + vertexCount: Math.floor(Math.random() * 5) + 3, + // TODO fix possible concaving + vertexOffset: null // placeholder + } + // initialized here as it depends on vertexCount. I could use `new function()` but nah. + genome.vertexOffset = Array(genome.vertexCount) + .fill() + .map(() => ({ + x: Math.random() - 0.5, + y: Math.random() - 0.5 + })) + return genome + } + + function mutateGenome(genome) { + // takes an existing genome and applies tiny changes + const randomInRange = (min, max) => Math.random() * (max - min) + min + const tinyChange = x => randomInRange(-x, x) + + const vertexMutator = x => ({ + x: x.x + tinyChange(0.5), + y: x.y + tinyChange(0.5) + }) + // mutates a genome and returns the mutated version. + const newGenome = { + density: genome.density + tinyChange(0.0005), + size: genome.size + tinyChange(5), + speed: genome.speed + tinyChange(0.05), + color: genome.color.map(x => (x + tinyChange(10)) % 255), // wrap around + vertexCount: Math.max(genome.vertexCount + Math.round(tinyChange(1)), 3), + vertexOffset: genome.vertexOffset.map(vertexMutator) + } + if (genome.vertexOffset.length < newGenome.vertexCount) { + const vo = newGenome.vertexOffset + vo.push(vertexMutator(vo[~~(vo.length * Math.random())])) + } else if (genome.vertexOffset.length > newGenome.vertexCount) { + newGenome.vertexOffset.pop() + } + + return newGenome + } + + function calculateGenomeCost(genome) { + // calculates the cost of a genome and returns it. The cost is used to + // determine how "costly" the genome is to make, and after the orb's life ends it + // is used together with the orb success score to determine the fittest orb. + const score = (1 / (genome.density * genome.size * genome.speed)) * 0.000001 + return score + } + // distance functions + const dist2 = (a, b) => (a.x - b.x) ** 2 + (a.y - b.y) ** 2 + const dist = (a, b) => Math.sqrt(dist2(a, b)) + + // ** MAP SPECIFIC MOBS ** + function energyTransferBall(origin, target, boss, charge) { + // transports energy to the boss + // when the boss is hit by it, how much of the energy stored the boss actually recives + const ENERGY_TRANSFER_RATE = 80 /*%*/ + // add 1 to the active ball list + boss.activeBalls++ + const color = `rgba(${150 + 105 * charge}, 81, 50, 0.6)` + mobs.spawn(origin.x, origin.y, 12, 20 + 20 * charge, color) + const me = mob[mob.length - 1] + me.end = function () { + simulation.drawList.push({ + // some nice graphics + x: this.position.x, + y: this.position.y, + radius: this.radius, + color: '#f3571d', + time: ~~(Math.random() * 20 + 10) + }) + // on death spawn and explode a bomb + if (Math.random() > 0.95) { + spawn.bomb(this.position.x, this.position.y, this.radius, this.vertices.length) + mob[mob.length - 1].death() + } + // remove 1 from the active ball list + boss.activeBalls-- + this.death() + } + me.collisionFilter.mask = cat.player | cat.map + // me.onHit = this.end + me.life = 0 + me.isDropPowerUp = false + me.leaveBody = false + me.do = function () { + // die on collision with the map + if (Matter.Query.collides(this, map).length > 0) { + this.end() + } + // die if too much time passes. Stronger bullets explode earlier + if (++this.life > 200 - charge * 100) { + this.end() + } + // if the orb collides with the boss, die but give energy to the boss + if (Matter.Query.collides(this, [boss]).length > 0) { + boss.energy = Math.min(charge * (ENERGY_TRANSFER_RATE / 100) + boss.energy, 1) + // also make the boss fire once regardless of energy + boss.spawnOrbs() + this.end() + } + const movement = Vector.normalise(Vector.sub(target, origin)) + Matter.Body.setVelocity(this, { + x: this.velocity.x + movement.x, + y: this.velocity.y + movement.y + }) + // nice graphics + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: this.radius, + color: '#e81e1e', + time: 3 + }) + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: this.radius, + color: '#e87f1e', + time: 6 + }) + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: this.radius, + color: '#e8e41e', + time: 9 + }) + } + me.onDamage = me.end + } + + function energyBeacon(x, y, parentBoss) { + // an unmoving beacon that charges the genetic boss with energy either stolen + // from the player or generated. That energy is used to create stronger mobs. + mobs.spawn(x, y, 3, 50, '') // default color, changed an instant later + const me = mob[mob.length - 1] + me.laserRange = 500 + me.leaveBody = false + me.isDropPowerUp = false + // custom variables + // max energy is 1 + me.energy = 0 + me.seed = simulation.cycle // seed to make sure this mob is unique render wise + me.chargeTicks = 0 // used to time charging the boss + me.bossPos = null // the position that the mob remembers when charging + me.density = me.density * 2 + Matter.Body.setDensity(me, 0.0022 * 3 + 0.0002 * Math.sqrt(simulation.difficulty)) //extra dense + me.do = function () { + // if the boss is dead, die + if (!parentBoss.alive) { + this.death() + } + // slowly rotate + Matter.Body.setAngularVelocity(this, 0.01) + this.fill = `rgba(${this.energy * 255}, 29, 136, 0.80)` + this.seePlayerCheck() + // steal energy from player + // this.harmZone() // regular harmZone + // custom effects on top of that + if (this.distanceToPlayer() < this.laserRange) { + if (m.immuneCycle < m.cycle) { + // suck extra energy from the player if it's in range + if (m.energy > 0.1 && this.energy < 1 - 0.012) { + m.energy -= 0.012 + this.energy += 0.012 + } + // special "sucking" graphics + ctx.beginPath() + ctx.moveTo(this.position.x, this.position.y) + ctx.lineTo(m.pos.x, m.pos.y) + ctx.lineWidth = 3 + Math.abs(Math.sin((simulation.cycle + this.seed) / 100)) * 2 + ctx.strokeStyle = `rgb(${( + Math.abs(Math.sin((simulation.cycle + this.seed + 100) / 100)) * 255 + ).toFixed(3)}, 204, 255)` + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]) + ctx.stroke() + ctx.setLineDash([]) + } + } + // if the mob's energy is at least 50% full, try to send that energy to the boss. + // don't send that energy yet if more than 5 other transfer balls are active + if (this.energy > 0.5 && parentBoss.energy < 1 && parentBoss.activeBalls <= 5 && this.chargeTicks === 0) { + const seesBoss = Matter.Query.ray(map, this.position, parentBoss.position).length === 0 + if (seesBoss) { + this.chargeTicks = 100 + this.bossPos = Vector.clone(parentBoss.position) + } + } + if (this.chargeTicks > 0) { + if (--this.chargeTicks === 0) { + // spawn the orb + const location = Vector.add( + Vector.mult(Vector.normalise(Vector.sub(this.bossPos, this.position)), this.radius * 3), + this.position + ) + energyTransferBall(location, this.bossPos, parentBoss, this.energy) + this.energy = 0 + } + // create a beam and aim it at the bossPos + ctx.beginPath() + ctx.moveTo(this.position.x, this.position.y) + ctx.lineTo(this.bossPos.x, this.bossPos.y) + ctx.lineWidth = 10 + Math.abs(Math.sin((simulation.cycle + this.seed) / 100)) * 5 + ctx.strokeStyle = `rgb(${( + Math.abs(Math.sin((simulation.cycle + this.seed + 100) / 100)) * 255 + ).toFixed(3)}, 204, 255)` + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]) + ctx.stroke() + ctx.setLineDash([]) + } + // generate (0.15 * difficulty / 4)% energy per tick + if (this.energy < 1) this.energy += 0.0015 * (simulation.difficulty / 4) + // draw energy bar + drawEnergyBar(this) + } + me.onDeath = function () { + // remove itself from the list + const beacons = parentBoss.energyBeacons + beacons.splice(beacons.indexOf(this), 1) + // explode with the strength of its energy! + this.alive = false // to prevent retriggering infinitly + b.explosion(this.position, this.energy * this.radius * 15) + // when it dies, it reduces some of the boss' energy + parentBoss.energy -= 0.025 + // and stuns it + mobs.statusStun(parentBoss, 70 + ~~(100 / simulation.difficulty)) + } + } + + function geneticSeeker(x, y, genome, parentBoss) { + // special bullets that get score based on their performance. + mobs.spawn(x, y, genome.vertexCount, genome.size, '#' + genome.color.map(it => (~~it).toString(16)).join('')) + const me = mob[mob.length - 1] + // apply genome + Matter.Body.setDensity(me, genome.density) + me.accelMag = genome.speed + // apply vertex offset + for (let i = 0; i < me.vertices.length; i++) { + const vertex = me.vertices[i] + const offset = genome.vertexOffset[i] + if (!offset) console.log(genome, me) + vertex.x += offset.x + vertex.y += offset.y + } + + me.stroke = 'transparent' + Matter.Body.setDensity(me, 0.00001) //normal is 0.001 + // increased if the orb done things that are deemed successful + me.score = 30 + me.timeLeft = 9001 / 9 + me.accelMag = 0.00017 * simulation.accelScale //* (0.8 + 0.4 * Math.random()) + me.frictionAir = 0.01 + me.restitution = 0.5 + me.leaveBody = false + me.isDropPowerUp = false + me.isBadTarget = true + me.isMobBullet = true + me.showHealthBar = false + me.collisionFilter.category = cat.mobBullet + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet + me.do = function () { + this.alwaysSeePlayer() + this.attraction() + this.timeLimit() + + if (Matter.Query.collides(this, map).length > 0) { + // colliding with the map gives a score reduction, 0.5 per tick + this.score -= 0.5 + } + // default score is slowly reduced every tick to give mobs that reached the player faster a benefit + this.score -= 0.05 + if (this.score < 0) { + this.alive = false // no point continuing if this orb is that bad! Silent death + } + // give a bonus if some projectile is nearby or the mouse position is close (like laser pointing) + // if a mob survives this for long, then it gets a score benefit. + const bulletCloseToOrb = bullet.some(it => dist2(this.position, it.position) < 10000 /* 100 ^ 2 */) + // player shoots and aims close + const mouseCloseToOrb = dist2(this.position, simulation.mouseInGame) < 10000 && input.fire + if (bulletCloseToOrb || mouseCloseToOrb) { + this.score += 1 + } + // die if too far from the boss... It would be incredibly difficult to dodge otherwise + if (dist2(this.position, parentBoss.position) > 2000 * 2000) { + this.alive = false + } + // DEBUG score printer + // ctx.font = '48px sans-serif' + // ctx.fillStyle = 'rgba(252, 0, 143, 1)' + // ctx.fillText(~~this.score, this.position.x - this.radius, this.position.y - this.radius) + } + me.onHit = function () { + // hitting the player gives a 50 points score bonus + this.score += 50 + this.score += this.mass * 2 // bigger mass = bigger damage, add that too + // a marker for later + this.hitPlayer = true + this.explode(this.mass) + } + me.onDeath = function () { + if (!this.hitPlayer) { + // if it didn't hit the player, give it a score based on its distance + this.score += 10000 / this.distanceToPlayer() + } + // 3% chance to drop ammo + if (Math.random() > 0.97) { + powerUps.spawn(this.position.x, this.position.y, 'ammo', true) + } + parentBoss.deadOrbs.push({ + genome: genome, + score: this.score + }) + } + } + + function geneticBoss(x, y, radius = 130, spawnBossPowerUp = true) { + // a modified orb shooting boss that evolves its orbs. + // the way this boss works is different from the regular orb shooting boss, + // because the orbs have evolving properties via a "machine learning" scoring algorithm. + const MAX_BEACONS = Math.round(3 + Math.random() * simulation.difficulty / 3) + mobs.spawn(x, y, 8, radius, 'rgb(83, 32, 58)') + let me = mob[mob.length - 1] + me.isBoss = true + + me.accelMag = 0.0001 * simulation.accelScale + me.fireFreq = Math.floor((330 * simulation.CDScale) / simulation.difficulty) + me.frictionStatic = 0 + me.friction = 0 + me.frictionAir = 0.02 + me.memory = (420 / 69) * 42 // 🧌 + me.repulsionRange = 1000000 + me.energyBeacons = [] + me.activeBalls = 0 + // starts by random, or by the stored genomes if they exist + const init = () => ({ + genome: generateGenome(), + score: 0 + }) + me.fittestOrbs = (localStorage && localStorage.genome) ? JSON.parse(localStorage.genome) : [init(), init(), init()] // best genomes so far. Size of three + // when an orb died it's moved here. When a new spawn cycle starts, their scores get calculated + // and they get put in the fittest orbs array, if they are better than the old ones. + me.deadOrbs = [] + me.energy = 1 + // this boss has no orbitals, because it's not meant to ever attack on its own + me.damageReduction = 0.25 + // has a shield and sustains that shield + spawn.shield(me, x, y, Infinity) + me.fireFreq = 30 + me.ionizeFreq = 20 + me.ionized = [] + me.laserRange = radius * 4 + + Matter.Body.setDensity(me, 0.0022 * 4 + 0.0002 * Math.sqrt(simulation.difficulty)) //extra dense //normal is 0.001 //makes effective life much larger + me.onDeath = function () { + if (spawnBossPowerUp) { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + const amount = ~~(5 * Math.random() * simulation.difficulty / 10) * 2 + for (let i = 0; i < amount; i++) { + powerUps.spawn(this.position.x, this.position.y, 'ammo', true) + if (Math.random() > 0.7) { + powerUps.spawn(this.position.x, this.position.y, 'heal', true) + } + } + } + // keep the best genome and use it next fight... + if (localStorage) { + localStorage.setItem("genome", JSON.stringify(this.fittestOrbs)) + } + + // stop spawning barrels + bossInit = false + } + me.onDamage = function () { } + me.spawnBeacon = function () { + // the vertex to spawn the beacon from + const vert = this.vertices[~~(Math.random() * this.vertices.length)] + // the position should be a little to the side to prevent crashing into the boss + // TODO check for collisions with the wall + const spawnPos = Vector.add(vert, Vector.mult(Vector.normalise(Vector.sub(this.position, vert)), -60)) + // some velocity + const velocity = Vector.mult(Vector.normalise(Vector.sub(this.position, vert)), -5) + energyBeacon(spawnPos.x, spawnPos.y, this) // spawn the beacon, a bit ahead + const beacon = mob[mob.length - 1] + this.energyBeacons.push(beacon) + Matter.Body.setVelocity(beacon, { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }) + } + me.spawnOrbs = function () { + Matter.Body.setAngularVelocity(this, 0.11) + // sort the vertices by the distance to the player + const sorted = [...this.vertices].sort(dist2) + // spawn the bullets based on how close they are to the player. + // the way it works is it picks the fittest three orbs and clones them. + // but start by taking old mobs and checking if they are better than the new ones + let next + while ((next = this.deadOrbs.pop())) { + // material costs are calculated as a contra to the score + const cost = calculateGenomeCost(next.genome) * 500 // normalize via multiplication + const totalScore = next.score - cost + // try to insert itself into the best orbs, if it can + for (let i = 0; i < this.fittestOrbs.length; i++) { + const fitEntry = this.fittestOrbs[i] + if (fitEntry.score < totalScore) { + this.fittestOrbs[i] = next + break + } + } + } + // finally sort them using their score + this.fittestOrbs.sort((a, b) => a.score - b.score) + // only take the genome, the score doesn't matter here + const bestOrbs = this.fittestOrbs.map(it => it.genome) + for (let vertex of sorted) { + // pick a random fit orb and try to spawn it. If the cost is too high, it'll attempt + // to generate a new random orb instead. If that orb is too expensive too, just ignore this vertex. + // the evolution part comes here, as the genome is mutated first. + let randGenome = mutateGenome(bestOrbs[~~(Math.random() * bestOrbs.length)]) + const cost = calculateGenomeCost(randGenome) * 2 + if (this.energy - cost < 0) { + // okay this orb is too expensive for the boss to spawn, + // make a new orb from scratch + randGenome = generateGenome() + const secondCost = calculateGenomeCost(randGenome) + if (this.energy - secondCost < 0) { + // that was too expensive too, heh + continue + } + } else { + // alright the boss can afford that + this.energy -= Math.abs(cost) // TODO: Fix this, why the heck can it even be negative?? + } + + geneticSeeker(vertex.x, vertex.y, randGenome, this) + // give the bullet a rotational velocity as if they were attached to a vertex + const velocity = Vector.mult( + Vector.perp(Vector.normalise(Vector.sub(this.position, vertex))), + -10 + ) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }) + } + } + me.do = function () { + this.seePlayerCheck() + this.checkStatus() + this.attraction() + this.repulsion() + // draw laser arcs if it sees the player + this.harmZone() + // + const regularChance = Math.random() > 0.99 + const biggerChance = Math.random() > 0.95 && this.energy > 0.25 + // start by making sure there is always at least one beacon + if (this.energyBeacons.length === 0) { + this.spawnBeacon() + } + // then, spawn some energy beacons if there are less than the maximum. + // small chance if there's no energy, bigger chance if there is at least 10% (which is drained) + if ((this.energyBeacons.length < MAX_BEACONS && biggerChance) || regularChance) { + if (biggerChance) { + // if the spawn was a selection of bigger chance, reduce 10% energy + this.energy -= 0.10 + } + this.spawnBeacon() + } + // then, spawn genetic seekers + if (this.seePlayer.recall && !(simulation.cycle % this.fireFreq)) { + // fire a bullet from each vertex if there's enough energy + if (this.energy > 0.15) { + this.spawnOrbs() + } + } + + if (this.energy > 1) { + // clean excess energy + this.energy -= 0.003 + } else { + // or slowly generate energy + this.energy += 0.001 + } + // the boss will ionize every bullet in its radius, but that will cause its energy to deplete + if (!(simulation.cycle % this.ionizeFreq)) { + for (let i = 0; i < bullet.length; i++) { + const it = bullet[i] + // if it's not a bot and it's close + if (!it.botType && dist(this.position, it.position) < this.laserRange) { + // add it to the ionized list + this.ionized.push({ + target: it, + ticks: 0 + }) + } + } + } + + for (let i = 0; i < this.ionized.length; i++) { + const entry = this.ionized[i] + + // skip if there's not enough energy + if (this.energy <= 0) break + + // terminate if it's no longer in the radius + if (dist(this.position, entry.target.position) > this.laserRange) { + this.ionized.splice(i, 1) + continue + } + // terminate after some ticks + if (++entry.ticks === 10) { + entry.target.endCycle = 0 + // draw nice popping graphics + simulation.drawList.push({ + x: entry.target.position.x, + y: entry.target.position.y, + radius: 5, + color: '#f24', + time: ~~(Math.random() * 20 + 10) + }) + // and remove + this.ionized.splice(i, 1) + continue + } + // draw line + ctx.beginPath() + ctx.moveTo(this.position.x, this.position.y) + ctx.lineTo(entry.target.position.x, entry.target.position.y) + ctx.lineWidth = 7 + ctx.strokeStyle = `rgb(${60 - entry.ticks * 2}, 50, 50)` + ctx.stroke() + // reduce energy, as it's hard to ionize + this.energy -= entry.target.mass / 25 + } + + // if it has energy, shield itself and drain energy + if (!this.isShielded && this.energy > 0.5) { + spawn.shield(this, this.position.x, this.position.y, Infinity) + this.energy -= 0.25 + } + drawEnergyBar(this) + // change fill color + this.fill = `rgb(${((Math.sin(simulation.cycle / 100) + 1) / 2) * 100}, 32, 58)` + } + // start by spawning several beacons to gain initial energy + const amount = Math.ceil(2 + Math.random() * simulation.difficulty / 5) + for (let i = 0; i < amount; i++) + me.spawnBeacon() + } + + // LEVEL SETUP + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20) //don't change this + + level.exit.x = 5700 //you exit at x + level.exit.y = -130 //you exit at y + spawn.mapRect(5800, -110, -100, 10) + + level.defaultZoom = 2000 //how far out you want the image to be zoomed at (lower = zoom in, higher = zoom out) + simulation.zoomTransition(level.defaultZoom) //makes the level transition to have the zoom at the start of a level + document.body.style.backgroundColor = 'hsl(138, 3%, 74%)' //sets background color + + //LEVEL STRUCTURE + spawn.mapRect(-3100, -100, 9200, 100) + spawn.mapRect(-3100, -600, 100, 500) + spawn.mapRect(-3100, -600, 1100, 100) + spawn.mapRect(-2100, -3100, 100, 2700) + spawn.mapRect(4800, -3100, 100, 2600) + spawn.mapRect(4800, -600, 1300, 100) + spawn.mapRect(6000, -600, 100, 600) + + spawn.mapRect(400, -200, 2000, 100) + spawn.mapRect(600, -300, 1600, 100) + spawn.mapRect(800, -400, 1200, 100) + spawn.mapRect(1000, -500, 800, 100) + spawn.mapRect(1200, -600, 400, 100) + // roof + spawn.mapRect(-2100, -4350, 650, 1250) + spawn.mapRect(-1300, -4350, 1250, 1250) + spawn.mapRect(100, -4350, 1225, 1250) + spawn.mapRect(1475, -4350, 1325, 1250) + spawn.mapRect(2950, -4350, 1325, 1250) + spawn.mapRect(4425, -4350, 475, 1250) + + // arc + // spawn.mapVertex(1400, -892, '700, -800, 700, -900, 1000, -1000, 1800, -1000, 2100, -900, 2100, -800') + + + //PLATFORMS + platformShadow(-1200, -500, 300, 100, shadows) + platformShadow(-400, -700, 300, 100, shadows) + platformShadow(400, -900, 300, 100, shadows) + platformShadow(-2000, -800, 300, 100, shadows) + platformShadow(-1000, -1000, 300, 100, shadows) + platformShadow(-400, -1300, 300, 100, shadows) + platformShadow(-1600, -1300, 300, 100, shadows) + platformShadow(-1300, -1600, 300, 100, shadows) + platformShadow(-2000, -1700, 300, 100, shadows) + platformShadow(-700, -1800, 300, 100, shadows) + platformShadow(-1500, -2100, 300, 100, shadows) + platformShadow(-600, -2200, 300, 100, shadows) + platformShadow(-2000, -2500, 300, 100, shadows) + platformShadow(-1100, -2400, 300, 100, shadows) + platformShadow(-500, -2700, 300, 100, shadows) + platformShadow(100, -2400, 300, 100, shadows) + platformShadow(700, -2700, 300, 100, shadows) + + platformShadow(3700, -500, 300, 100, shadows) + platformShadow(2900, -700, 300, 100, shadows) + platformShadow(2100, -900, 300, 100, shadows) + platformShadow(4500, -800, 300, 100, shadows) + platformShadow(3500, -1000, 300, 100, shadows) + platformShadow(4100, -1300, 300, 100, shadows) + platformShadow(2900, -1300, 300, 100, shadows) + platformShadow(3800, -1600, 300, 100, shadows) + platformShadow(4500, -1700, 300, 100, shadows) + platformShadow(3200, -1800, 300, 100, shadows) + platformShadow(4000, -2100, 300, 100, shadows) + platformShadow(3100, -2200, 300, 100, shadows) + platformShadow(4500, -2500, 300, 100, shadows) + platformShadow(3600, -2400, 300, 100, shadows) + platformShadow(3000, -2700, 300, 100, shadows) + platformShadow(2400, -2400, 300, 100, shadows) + platformShadow(1800, -2700, 300, 100, shadows) + + // cages + cage(-1492, -1200, 100, cages) + cage(-875, -2300, 300, cages) + cage(-1600, -3100, 1000, cages) + cage(225, -2300, 1000, cages) + cage(-750, -3100, 700, cages) + cage(-625, -1700, 1200, cages) + cage(2200, -3100, 500, cages) + cage(3275, -1700, 500, cages) + cage(3650, -900, 300, cages) + cage(2500, -2300, 300, cages) + cage(3625, -2300, 300, cages) + cage(3875, -1500, 300, cages) + cage(4025, -3100, 300, cages) + + // boss cage + platformShadow(1275, -2150, 250, 100, shadows) + cage(1400, -2050, 500, cages, 'starter', true) + map[map.length] = Bodies.trapezoid(1400, -2193, 250, 100, 0.5) + //DEBRIS + //idk just put the debris wherever you want + spawn.debris(-550, -225, 100) + spawn.debris(-1150, -1725, 75) + spawn.debris(-275, -1400, 50) + spawn.debris(2850, -2075, 150) + spawn.debris(4250, -2250, 150) + //BOSS + // geneticBoss(1400, -3800) + anotherBoss(0, 0) //will only spawn historyBoss if there is an additional boss + }, + stereoMadness() { + simulation.inGameConsole(`stereoMadness by Richard0820`); + let totalCoin = 0; + const hunter = function (x, y, radius = 30) { //doesn't stop chasing until past 105000 + mobs.spawn(x, y, 6, radius, "black"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.collisionFilter.mask = cat.player | cat.bullet; + me.accelMag = 0.0006 * Math.min(simulation.difficulty + 1, 4); + me.showHealthBar = false; + me.isUnblockable = true; + me.isShielded = true; + me.memory = Infinity; + me.seeAtDistance2 = Infinity; + Matter.Body.setDensity(me, 1) + simulation.inGameConsole(`Ω: Intruder Detected`); + me.boost = 10; + me.do = function () { + if (me.boost == 1 && m.fieldMode == 3 || m.fieldMode == 9 && me.boost == 1) { + me.accelMag *= 1.5; + me.boost--; + } + this.attraction(); + this.checkStatus(); + this.repelBullets(); + this.locatePlayer(); + this.alwaysSeePlayer() + if (player.position.x > 105000) { + this.death() + } + }; + me.onHit = function () { + for (let i = 0; i < 10; i++) { + spawn.spawns(this.position.x + Math.random() * 1000 - Math.random() * 1000, this.position.y - Math.random() * 1000) + } + } + } + const coin = function (x, y, radius = 50) { + mobs.spawn(x, y, 40, radius, "yellow"); + let me = mob[mob.length - 1]; + me.stroke = "#00000055" + me.isShielded = true; + me.leaveBody = false; + me.isBadTarget = true; + me.isUnblockable = true; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.collisionFilter.category = 0; + Matter.Body.setDensity(me, 0.0045); + me.onDeath = function () { + totalCoin++; + }; + me.damageReduction = 0.35 + me.do = function () { + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.PI / 2 + 0.5) + ctx.strokeStyle = "#000000"; + ctx.beginPath() + ctx.arc(0, 0, 30, -1, Math.PI, false) + ctx.moveTo(20, -5) + ctx.arc(0, 0, 20, -1, Math.PI, false) + ctx.lineWidth = 5; + ctx.stroke() + ctx.restore() + if (!simulation.isTimeSkipping) { + const sine = Math.sin(simulation.cycle * 0.015) + this.radius = 50 * (1 + 0.1 * sine) + const sub = Vector.sub(player.position, this.position) + const mag = Vector.magnitude(sub) + const force = Vector.mult(Vector.normalise(sub), 0.000000003) + if (mag < this.radius) { //heal player when inside radius + if (m.health < 0.7) { + m.damage(-0.001); + } else if (m.health == 0.7 || m.health > 0.7) { + this.death() + } + ctx.strokeStyle = "#00FFDD55"; + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 34, 0, 2 * Math.PI); + ctx.lineWidth = 6; + ctx.stroke(); + } + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.radius + 15, 0, 2 * Math.PI); + ctx.strokeStyle = "#000" + ctx.lineWidth = 1; + ctx.stroke(); + }; + } + } + const spike = function (x, y, angle = Math.PI * 0.5, radius = 50) { + mobs.spawn(x, y, 3, radius, "#454545"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.isDropPowerUp = false; + me.showHealthBar = false; + Matter.Body.setDensity(me, 50) + me.collisionFilter.mask = cat.player | cat.mob | cat.bullet; + me.constraint = Constraint.create({ + pointA: { + x: me.position.x, + y: me.position.y + }, + bodyB: me, + stiffness: 0, + damping: 0 + }); + me.do = function () { + if (this.health < 1) { + this.health += 0.001; //regen + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: this.radius / 1.5, + color: `rgba(0, 255, 20, ${Math.random() * 0.1})`, + time: simulation.drawTime + }); + } + this.checkStatus(); + Matter.Body.setAngle(me, angle); + }; + me.onHit = function () { + m.damage(0.01) //extra damage + me.collisionFilter.mask = 0; + setTimeout(() => { + me.collisionFilter.mask = cat.player | cat.mob | cat.bullet; + }, 1000); + } + Composite.add(engine.world, me.constraint); + } + + function drawStar(cx, cy, spikes, outerRadius, innerRadius) { + outerRadius *= (1 + 0.1 * Math.sin(simulation.cycle * 0.15)); + innerRadius *= (1 + 0.1 * Math.sin(simulation.cycle * 0.15)); + var rot = Math.PI / 2 * 3; + var xs = cx; + var y = cy; + var step = Math.PI / spikes; + + ctx.strokeSyle = "#000"; + ctx.beginPath(); + ctx.moveTo(cx, cy - outerRadius) + for (i = 0; i < spikes; i++) { + xs = cx + Math.cos(rot) * outerRadius; + y = cy + Math.sin(rot) * outerRadius; + ctx.lineTo(xs, y) + rot += step + + xs = cx + Math.cos(rot) * innerRadius; + y = cy + Math.sin(rot) * innerRadius; + ctx.lineTo(xs, y) + rot += step + } + ctx.lineTo(cx, cy - outerRadius) + ctx.closePath(); + ctx.lineWidth = 5; + ctx.strokeStyle = 'red'; + ctx.stroke(); + ctx.fillStyle = 'darkred'; + ctx.fill(); + + } + const slimePit1 = level.hazard(7475, -75, 475, 100, 0.01) + const slimePit2 = level.hazard(11275, -75, 1450, 100, 0.01) + const slimePit3 = level.hazard(13400, -150, 3500, 200, 0.1) + const slimePit4 = level.hazard(20275, -400, 3475, 450, 0.01) + const slimePit5 = level.hazard(25300, -800, 20000, 650, 0.003) + const slimePit6 = level.hazard(47725, -425, 2500, 475, 0.01) + const slimePit7 = level.hazard(50975, -575, 4050, 650, 0.01) + const slimePit8 = level.hazard(54950, -950, 6650, 1050, 0.01) + const slimePit9 = level.hazard(63550, -75, 2150, 100, 0.01) + const slimePit10 = level.hazard(70875, -75, 1200, 100, 0.01) + const slimePit11 = level.hazard(72075, -50, 900, 75, 1) + const slimePit12 = level.hazard(75900, -75, 2575, 100, 0.01) + const slimePit13 = level.hazard(78475, -35, 2300, 70, 0.01) + const slimePit14 = level.hazard(82875, -75, 5100, 100, 0.1) + + const drip1 = level.drip(32474, -2165, -800, 100); + const drip2 = level.drip(37750, -2165, -800, 100); + const drip3 = level.drip(43525, -2165, -800, 100); + const drip4 = level.drip(20475, -830, -375, 100); + const drip5 = level.drip(49960, -2315, -423, 200) + let textlogOne = 0; + let textlogTwo = 0; + let barThere = true; + let bar = document.createElement("div"); + bar.style.cssText = `position: absolute; top: 80px; background-color: black; width: 80vw; z-index: 1; border-radius: 10px; height: 20px; left: 5em; right: 5em;`; + bar.innerHTML += `
` + document.body.appendChild(bar); + let innerBar = document.getElementById("innerBar"); + level.custom = () => { + level.exit.drawAndCheck(); + if (barThere == true) { + innerBar.style.width = "calc(" + `${Math.max(0, Math.min(player.position.x / 1310, 80))}` + "vw - 10px)"; + innerBar.style.backgroundColor = m.eyeFillColor; + } + if (m.pos.x > 25360 && textlogOne == 0) { + simulation.inGameConsole(`
A stong force pushes you forward...
`) + textlogOne++; + } + if (m.pos.x < -3000) { + Matter.Body.setVelocity(player, { + x: 99, + y: 19 + }); + + if (textlogTwo == 0) + simulation.inGameConsole(`
A strong force pushes you away...
`); + textlogTwo++; + } + if (m.pos.y > 1055) { + Matter.Body.setPosition(player, { x: 0, y: -150 }); + simulation.inGameConsole(`
There is nowhere to run...
`); + m.damage(0.1 * simulation.difficultyMode); + } + if (m.alive == false && barThere == true) { + document.body.removeChild(bar); + barThere = false; + } + ctx.beginPath() + ctx.lineWidth = 5; + ctx.strokeStyle = "#000000"; + ctx.moveTo(40, -1000) + ctx.arc(0, -1000, 40, 0, 2 * Math.PI) + ctx.stroke() + ctx.fillStyle = "#FF00FF55" + ctx.fillRect(89750, -1300, 800, 200) + ctx.fillRect(89750, -200, 800, 200) + ctx.fillRect(92050, -200, 800, 200) + ctx.fillRect(92050, -1675, 800, 575) + ctx.fillRect(93950, -350, 200, 350); + ctx.fillRect(95100, -1350, 150, 375); + ctx.fillRect(100900, -1325, 1175, 250); + ctx.fillRect(100900, -225, 1200, 250); + ctx.fillRect(98725, -1325, 450, 150); + ctx.fillRect(98725, -125, 450, 150); + ctx.beginPath() + //lines! + ctx.lineWidth = 10; + ctx.strokeStyle = "#000000"; + ctx.moveTo(7462.5, -250) + ctx.lineTo(7462.5, -170) + ctx.moveTo(7710, -330) + ctx.lineTo(7710, -250) + ctx.moveTo(7960, -420) + ctx.lineTo(7960, -320) + ctx.moveTo(13725, -250) + ctx.lineTo(13725, -180) + ctx.moveTo(14025, -350) + ctx.lineTo(14025, -280) + ctx.moveTo(14325, -450) + ctx.lineTo(14325, -380) + ctx.moveTo(14625, -550) + ctx.lineTo(14625, -480) + ctx.moveTo(14925, -650) + ctx.lineTo(14925, -580) + ctx.moveTo(15225, -750) + ctx.lineTo(15225, -680) + ctx.moveTo(15525, -850) + ctx.lineTo(15525, -780) + ctx.moveTo(15825, -950) + ctx.lineTo(15825, -880) + ctx.moveTo(16125, -1050) + ctx.lineTo(16125, -980) + ctx.moveTo(16425, -1150) + ctx.lineTo(16425, -1080) + ctx.moveTo(22600, -650) + ctx.lineTo(22600, -580) + ctx.moveTo(22800, -750) + ctx.lineTo(22800, -680) + ctx.moveTo(23000, -850) + ctx.lineTo(23000, -780) + ctx.moveTo(23200, -950) + ctx.lineTo(23200, -880) + ctx.moveTo(23400, -1050) + ctx.lineTo(23400, -980) + ctx.moveTo(23600, -1150) + ctx.lineTo(23600, -1080) + ctx.moveTo(29550, -1625) + ctx.lineTo(29550, -1425) + ctx.moveTo(32275, -2125) + ctx.lineTo(32275, -1925) + ctx.moveTo(33775, -2125) + ctx.lineTo(33775, -1925) + ctx.moveTo(32275, -350) + ctx.lineTo(32275, -550) + ctx.moveTo(33775, -350) + ctx.lineTo(33775, -550) + ctx.moveTo(35475, -650) + ctx.lineTo(35475, -450) + ctx.moveTo(37650, -2000) + ctx.lineTo(37650, -1800) + ctx.moveTo(39675, -400) + ctx.lineTo(39675, -600) + ctx.moveTo(40375, -500) + ctx.lineTo(40375, -700) + ctx.moveTo(41075, -600) + ctx.lineTo(41075, -800) + ctx.moveTo(43625, -1925) + ctx.lineTo(43625, -1725) + ctx.moveTo(50975, -1125) + ctx.lineTo(50975, -925) + ctx.moveTo(51387.5, -1325) + ctx.lineTo(51387.5, -1125) + ctx.moveTo(51787.5, -1525) + ctx.lineTo(51787.5, -1325) + ctx.moveTo(52187.5, -1725) + ctx.lineTo(52187.5, -1525) + ctx.moveTo(52587.5, -1725) + ctx.lineTo(52587.5, -1925) + ctx.moveTo(52987.5, -2125) + ctx.lineTo(52987.5, -1925) + ctx.moveTo(53387.5, -2325) + ctx.lineTo(53387.5, -2125) + ctx.moveTo(53787.5, -2525) + ctx.lineTo(53787.5, -2325) + ctx.moveTo(54187.5, -2725) + ctx.lineTo(54187.5, -2525) + ctx.moveTo(54587.5, -2925) + ctx.lineTo(54587.5, -2725) + ctx.moveTo(54987.5, -3125) + ctx.lineTo(54987.5, -2925) + ctx.moveTo(57500, -1925) + ctx.lineTo(57650, -1925) + ctx.moveTo(57520, -1845) + ctx.lineTo(57650, -1845) + ctx.moveTo(57500, -1925) + ctx.lineTo(57895 + 300, -1925) + ctx.moveTo(57520, -1845) + ctx.lineTo(57895 + 300, -1845) + ctx.moveTo(58525, -1725) + ctx.lineTo(58525 + 125, -1725) + ctx.moveTo(58525, -1625) + ctx.lineTo(58525 + 125, -1625) + ctx.moveTo(59000, -1725) + ctx.lineTo(59150, -1725) + ctx.moveTo(59150, -1625) + ctx.lineTo(59000, -1625) + ctx.moveTo(70875, -200) + ctx.lineTo(70875, -100) + ctx.moveTo(63700, -200) + ctx.lineTo(63800, -200) + ctx.moveTo(64000, -200) + ctx.lineTo(64100, -200) + ctx.moveTo(64675, -200) + ctx.lineTo(64575, -200) + ctx.moveTo(64875, -200) + ctx.lineTo(64975, -200) + ctx.moveTo(65025, -300) + ctx.lineTo(64925, -300) + ctx.moveTo(65225, -300) + ctx.lineTo(65325, -300) + ctx.moveTo(71275, -200) + ctx.lineTo(71275, -300) + ctx.moveTo(71675, -300) + ctx.lineTo(71675, -400) + ctx.moveTo(72075, -400) + ctx.lineTo(72075, -500) + ctx.moveTo(72425, -325) + ctx.lineTo(72425, -425) + ctx.moveTo(72675, -200) + ctx.lineTo(72675, -300) + ctx.moveTo(72925, -75) + ctx.lineTo(72925, -175) + ctx.moveTo(75225, -100) + ctx.lineTo(75225, -200) + ctx.moveTo(76600, -125) + ctx.lineTo(76600, -225) + ctx.moveTo(76900, -200) + ctx.lineTo(76900, -300) + ctx.moveTo(77175, -275) + ctx.lineTo(77175, -375) + ctx.moveTo(77475, -350) + ctx.lineTo(77475, -450) + ctx.moveTo(85575, -275) + ctx.lineTo(85575, -375) + ctx.moveTo(86000, -275) + ctx.lineTo(86000, -375) + ctx.moveTo(86275, -275) + ctx.lineTo(86275, -375) + ctx.moveTo(86950, -425) + ctx.lineTo(86950, -525) + ctx.moveTo(89700, -175) + ctx.lineTo(89700, -75) + ctx.moveTo(89700, -1125) + ctx.lineTo(89700, -1225) + ctx.moveTo(90600, -1225) + ctx.lineTo(90600, -1125) + ctx.moveTo(90600, -100) + ctx.lineTo(90600, -175) + ctx.moveTo(92000, -100) + ctx.lineTo(92000, -175) + ctx.moveTo(92900, -100) + ctx.lineTo(92900, -175) + ctx.moveTo(92900, -1225) + ctx.lineTo(92900, -1125) + ctx.moveTo(94500, -1475) + ctx.lineTo(94500, -1575) + ctx.moveTo(94700, -1475) + ctx.lineTo(94700, -1575) + ctx.moveTo(94900, -1475) + ctx.lineTo(94900, -1575) + ctx.moveTo(96125, -1500) + ctx.lineTo(96125, -1575) + ctx.moveTo(96550, -1575) + ctx.lineTo(96550, -1500) + ctx.moveTo(97000, -1475) + ctx.lineTo(97000, -1575) + + ctx.stroke() + ctx.beginPath() + ctx.strokeStyle = "#FFFFFF"; + ctx.fillStyle = document.body.style.backgroundColor; + let cycles = Math.sin(simulation.cycle * 0.15) + ctx.moveTo(7482.5, -270) + ctx.arc(7462.5, -270, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI); + ctx.moveTo(7730, -350) + ctx.arc(7710, -350, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI); + ctx.moveTo(7980, -420) + ctx.arc(7960, -420, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(13745, -180) + ctx.arc(13725, -180, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(14045, -280) + ctx.arc(14025, -280, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(14345, -380) + ctx.arc(14325, -380, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(14645, -480) + ctx.arc(14625, -480, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(14945, -580) + ctx.arc(14925, -580, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(15245, -680) + ctx.arc(15225, -680, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(15545, -780) + ctx.arc(15525, -780, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(15845, -880) + ctx.arc(15825, -880, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(16145, -980) + ctx.arc(16125, -980, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(16445, -1080) + ctx.arc(16425, -1080, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(22620, -580); + ctx.arc(22600, -580, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(22820, -680); + ctx.arc(22800, -680, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(23020, -780); + ctx.arc(23000, -780, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(23220, -880); + ctx.arc(23200, -880, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(23420, -980); + ctx.arc(23400, -980, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(23620, -1080); + ctx.arc(23600, -1080, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(29570, -1425) + ctx.arc(29550, -1425, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(32295, -1925) + ctx.arc(32275, -1925, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(33795, -1925) + ctx.arc(33775, -1925, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(32295, -550) + ctx.arc(32275, -550, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(33795, -550) + ctx.arc(33775, -550, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(35495, -650) + ctx.arc(35475, -650, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(37670, -1800) + ctx.arc(37650, -1800, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(39695, -600) + ctx.arc(39675, -600, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(40395, -700) + ctx.arc(40375, -700, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(41095, -800) + ctx.arc(41075, -800, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(43645, -1725) + ctx.arc(43625, -1725, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(50995, -1125) + ctx.arc(50975, -1125, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(51407.5, -1325) + ctx.arc(51387.5, -1325, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(51807.5, -1525) + ctx.arc(51787.5, -1525, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(52207.5, -1725) + ctx.arc(52187.5, -1725, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(52607.5, -1925) + ctx.arc(52587.5, -1925, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(53007.5, -2125) + ctx.arc(52987.5, -2125, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(53407.5, -2325) + ctx.arc(53387.5, -2325, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(53807.5, -2525) + ctx.arc(53787.5, -2525, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(54207.5, -2725) + ctx.arc(54187.5, -2725, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(54607.5, -2925) + ctx.arc(54587.5, -2925, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(55007.5, -3125) + ctx.arc(54987.5, -3125, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(57520, -1925) + ctx.arc(57500, -1925, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(57520, -1845) + ctx.arc(57500, -1845, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(58525, -1725) + ctx.arc(58505, -1725, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(57895 + 300, -1925) + ctx.arc(57875 + 300, -1925, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(57895 + 300, -1845) + ctx.arc(57875 + 300, -1845, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(58525, -1625) + ctx.arc(58505, -1625, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(58690 + 375 + 125, -1625) + ctx.arc(58670 + 375 + 125, -1625, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(59190, -1725) + ctx.arc(59170, -1725, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(70895, -200) + ctx.arc(70875, -200, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(63720, -200) + ctx.arc(63700, -200, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(64120, -200) + ctx.arc(64100, -200, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(64595, -200) + ctx.arc(64575, -200, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(64995, -200) + ctx.arc(64975, -200, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(64945, -300) + ctx.arc(64925, -300, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(65345, -300) + ctx.arc(65325, -300, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(71295, -300) + ctx.arc(71275, -300, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(71695, -400) + ctx.arc(71675, -400, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(72095, -500) + ctx.arc(72075, -500, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(72445, -425) + ctx.arc(72425, -425, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(72695, -300) + ctx.arc(72675, -300, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(72945, -175) + ctx.arc(72925, -175, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(75245, -200) + ctx.arc(75225, -200, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(76620, -125) + ctx.arc(76600, -125, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(76920, -200) + ctx.arc(76900, -200, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(77195, -275) + ctx.arc(77175, -275, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(77495, -350) + ctx.arc(77475, -350, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(85595, -375) + ctx.arc(85575, -375, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(86020, -375) + ctx.arc(86000, -375, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(86295, -375) + ctx.arc(86275, -375, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(86970, -525) + ctx.arc(86950, -525, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(89720, -175) + ctx.arc(89700, -175, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(89720, -1125) + ctx.arc(89700, -1125, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(90620, -1125) + ctx.arc(90600, -1125, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(90620, -175) + ctx.arc(90600, -175, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(92020, -175) + ctx.arc(92000, -175, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(92920, -175) + ctx.arc(92900, -175, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(92920, -1125) + ctx.arc(92900, -1125, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(94520, -1575) + ctx.arc(94500, -1575, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(94720, -1575) + ctx.arc(94700, -1575, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(94920, -1575) + ctx.arc(94900, -1575, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(96145, -1575) + ctx.arc(96125, -1575, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(96570, -1500) + ctx.arc(96550, -1500, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.moveTo(97020, -1575) + ctx.arc(97000, -1575, 20 * (1 + 0.1 * cycles), 0, 2 * Math.PI) + ctx.fill() + ctx.stroke() + slimePit1.query() + slimePit2.query() + slimePit3.query() + slimePit4.query() + slimePit5.query() + slimePit5.query() + slimePit6.query() + slimePit7.query() + slimePit8.query() + slimePit9.query() + slimePit10.query() + slimePit11.query() + slimePit12.query() + slimePit13.query() + slimePit14.query() + drip1.draw() + drip2.draw() + drip3.draw() + drip4.draw() + drip5.draw() + + ctx.fillStyle = "rgba(0,255,255,0.9)" + ctx.fillRect(25325, -1375, 75, 400) + ctx.fillRect(46425, -1350, 100, 500) + ctx.fillRect(87925, -725, 75, 450) + + /* + if (player.position.x < 46470) { + document.body.style.backgroundColor = "#DD00DD"; + } + */ + if (player.position.x > 25360 && player.position.x < 46470) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, //+ 0.2, + y: player.velocity.y, + }); + if (input.up) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y, //- 1, + }); + } + document.body.style.backgroundColor = "#fb3310" + } else if (player.position.x > 46470 && player.position.x < 61675) { + document.body.style.backgroundColor = "#7704FF" + } else if (player.position.x > 9700 && player.position.x < 46470) { + document.body.style.backgroundColor = "#7704FF" + } else if (player.position.x > 61675 && player.position.x < 87950) { + document.body.style.backgroundColor = "#DD1111" + } else if (player.position.x > 87950) { + document.body.style.backgroundColor = "#7704FF" + } + + if (m.pos.y > -200 && 20350 < m.pos.x && m.pos.x < 23635) { + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 20250, + y: -1000 + }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + m.damage(0.1 * simulation.difficultyMode) + m.energy -= 0.1 * simulation.difficultyMode + } + if (m.pos.y > -150 && m.pos.x > 47770 && m.pos.x < 50130) { + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 47640, + y: -900 + }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + m.damage(0.1 * simulation.difficultyMode) + m.energy -= 0.1 * simulation.difficultyMode + } + if (m.pos.y > -150 && 50975 < m.pos.x && m.pos.x < 54925) { + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 50965, + y: -1100 + }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + m.damage(0.1 * simulation.difficultyMode) + m.energy -= 0.1 * simulation.difficultyMode + } + if (m.pos.y > -150 && 55025 < m.pos.x && m.pos.x < 57675) { + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 55148, + y: -3072 + }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + m.damage(0.1 * simulation.difficultyMode) + m.energy -= 0.1 * simulation.difficultyMode + } + if (m.pos.y > -150 && 57875 < m.pos.x && m.pos.x < 58700) { + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 57800, + y: -2200 + + }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + m.damage(0.1 * simulation.difficultyMode) + m.energy -= 0.1 * simulation.difficultyMode + } + if (m.pos.y > -150 && 58875 < m.pos.x && m.pos.x < 61650) { + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 58850, + y: -2025 + + }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + m.damage(0.1 * simulation.difficultyMode) + m.energy -= 0.1 * simulation.difficultyMode + } + if (m.pos.y > -1677 && 104650 < m.pos.x && m.pos.x < 105000 && barThere == true) { + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 132577, + y: -300 + + }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + document.body.style.transitionDuration = "0ms"; + document.body.style.backgroundColor = "#696969"; + simulation.inGameConsole(`
You have earned: ` + Math.min(3, totalCoin) + ` tech
`) + if (barThere == true) { //only runs once + document.body.removeChild(bar); + for (let i = 0, len = Math.min(3, totalCoin); i < len; i++) powerUps.directSpawn(player.position.x, player.position.y, "tech"); + barThere = false; + + + } + } + ctx.fillStyle = "#FFFFFF53" + ctx.fillRect(57645, -2055, 385, 85) + ctx.fillRect(58645, -1880, 385, 85) + //chains + ctx.strokeStyle = "#FF0000" + ctx.strokeRect(66975, -725, 25, 50) + ctx.strokeRect(67050, -725, 25, 50) + ctx.strokeRect(66975 + 1150, -725, 25, 50) + ctx.strokeRect(67050 + 1250, -725, 25, 50) + ctx.strokeRect(69162, -725, 25, 50) + ctx.strokeRect(69862, -725, 25, 50) + ctx.strokeRect(74412.5, -412.5, 25, 50) + ctx.strokeRect(74612.5, -412.5, 25, 50) + ctx.strokeRect(77962.5, -900, 25, 50) + ctx.strokeRect(78212.5, -775, 25, 50) + ctx.strokeRect(78462.5, -650, 25, 50) + ctx.strokeRect(81587.5, -725, 25, 50) + ctx.strokeRect(81687.5, -725, 25, 50) + ctx.strokeRect(81787.5, -725, 25, 50) + ctx.strokeRect(83037.5, -215, 25, 50) + ctx.strokeRect(83362.5, -215, 25, 50) + ctx.strokeRect(83687.5, -215, 25, 50) + ctx.strokeRect(84187.5, -315, 25, 50) + ctx.strokeStyle = "#FF000088" + ctx.strokeRect(66975, -850, 25, 50) + ctx.strokeRect(67050, -850, 25, 50) + ctx.strokeRect(66975 + 1150, -850, 25, 50) + ctx.strokeRect(67050 + 1250, -850, 25, 50) + ctx.strokeRect(69162, -850, 25, 50) + ctx.strokeRect(69862, -850, 25, 50) + ctx.strokeRect(74412.5, -525, 25, 50) + ctx.strokeRect(74612.5, -525, 25, 50) + ctx.strokeRect(77962.5, -985, 25, 50) + ctx.strokeRect(78212.5, -860, 25, 50) + ctx.strokeRect(78462.5, -735, 25, 50) + ctx.strokeRect(81587.5, -850, 25, 50) + ctx.strokeRect(81687.5, -850, 25, 50) + ctx.strokeRect(81787.5, -850, 25, 50) + ctx.strokeRect(83037.5, -315, 25, 50) + ctx.strokeRect(83362.5, -315, 25, 50) + ctx.strokeRect(83687.5, -315, 25, 50) + ctx.strokeRect(84187.5, -415, 25, 50) + ctx.strokeStyle = "#FF000044" + ctx.strokeRect(66975, -975, 25, 50) + ctx.strokeRect(67050, -975, 25, 50) + ctx.strokeRect(66975 + 1150, -975, 25, 50) + ctx.strokeRect(67050 + 1250, -975, 25, 50) + ctx.strokeRect(69162, -975, 25, 50) + ctx.strokeRect(69862, -975, 25, 50) + ctx.strokeRect(74412.5, -633, 25, 50) + ctx.strokeRect(74612.5, -633, 25, 50) + ctx.strokeRect(77962.5, -1075, 25, 50) + ctx.strokeRect(78212.5, -950, 25, 50) + ctx.strokeRect(78462.5, -825, 25, 50) + ctx.strokeRect(81587.5, -975, 25, 50) + ctx.strokeRect(81687.5, -975, 25, 50) + ctx.strokeRect(81787.5, -975, 25, 50) + ctx.strokeRect(83037.5, -415, 25, 50) + ctx.strokeRect(83362.5, -415, 25, 50) + ctx.strokeRect(83687.5, -415, 25, 50) + ctx.strokeRect(84187.5, -515, 25, 50) + ctx.strokeStyle = "#FF000011" + ctx.strokeRect(66975, -1100, 25, 50) + ctx.strokeRect(67050, -1100, 25, 50) + ctx.strokeRect(66975 + 1150, -1100, 25, 50) + ctx.strokeRect(67050 + 1250, -1100, 25, 50) + ctx.strokeRect(69162, -1100, 25, 50) + ctx.strokeRect(69862, -1100, 25, 50) + ctx.strokeRect(74412.5, -741, 25, 50) + ctx.strokeRect(74612.5, -741, 25, 50) + ctx.strokeRect(77962.5, -1165, 25, 50) + ctx.strokeRect(78212.5, -1040, 25, 50) + ctx.strokeRect(78462.5, -915, 25, 50) + ctx.strokeRect(81587.5, -1100, 25, 50) + ctx.strokeRect(81687.5, -1100, 25, 50) + ctx.strokeRect(81787.5, -1100, 25, 50) + ctx.strokeRect(83037.5, -515, 25, 50) + ctx.strokeRect(83362.5, -515, 25, 50) + ctx.strokeRect(83687.5, -515, 25, 50) + ctx.strokeRect(84187.5, -615, 25, 50) + ctx.stroke() + ctx.beginPath() + ctx.strokeStyle = "#FF0000" + ctx.moveTo(66987.5, -680) + ctx.lineTo(66987.5, -625) + ctx.moveTo(67062.5, -680) + ctx.lineTo(67062.5, -625) + ctx.moveTo(66987.5 + 1150, -680) + ctx.lineTo(66987.5 + 1150, -625) + ctx.moveTo(67062.5 + 1250, -680) + ctx.lineTo(67062.5 + 1250, -625) + ctx.moveTo(69175, -680) + ctx.lineTo(69175, -625) + ctx.moveTo(69875, -680) + ctx.lineTo(69875, -625) + ctx.moveTo(74425, -290) + ctx.lineTo(74425, -370) + ctx.moveTo(74625, -290) + ctx.lineTo(74625, -370) + ctx.moveTo(77975, -790) + ctx.lineTo(77975, -855) + ctx.moveTo(78225, -665) + ctx.lineTo(78225, -730) + ctx.moveTo(78475, -540) + ctx.lineTo(78475, -605) + ctx.moveTo(81600, -680) + ctx.lineTo(81600, -625) + ctx.moveTo(81700, -680) + ctx.lineTo(81700, -625) + ctx.moveTo(81800, -680) + ctx.lineTo(81800, -625) + ctx.moveTo(83050, -100) + ctx.lineTo(83050, -170) + ctx.moveTo(83375, -100) + ctx.lineTo(83375, -170) + ctx.moveTo(83700, -100) + ctx.lineTo(83700, -170) + ctx.moveTo(84200, -200) + ctx.lineTo(84200, -270) + ctx.stroke() + ctx.strokeStyle = "#FF000099" + ctx.moveTo(66987.5, -810) + ctx.lineTo(66987.5, -715) + ctx.moveTo(67062.5, -810) + ctx.lineTo(67062.5, -715) + ctx.moveTo(66987.5 + 1150, -810) + ctx.lineTo(66987.5 + 1150, -715) + ctx.moveTo(67062.5 + 1250, -810) + ctx.lineTo(67062.5 + 1250, -715) + ctx.moveTo(69175, -810) + ctx.lineTo(69175, -715) + ctx.moveTo(69875, -810) + ctx.lineTo(69875, -715) + ctx.moveTo(74425, -405) + ctx.lineTo(74425, -480) + ctx.moveTo(74625, -405) + ctx.lineTo(74625, -480) + ctx.moveTo(77975, -890) + ctx.lineTo(77975, -940) + ctx.moveTo(78225, -765) + ctx.lineTo(78225, -815) + ctx.moveTo(78475, -640) + ctx.lineTo(78475, -690) + ctx.moveTo(81600, -810) + ctx.lineTo(81600, -715) + ctx.moveTo(81700, -810) + ctx.lineTo(81700, -715) + ctx.moveTo(81800, -810) + ctx.lineTo(81800, -715) + ctx.moveTo(83050, -210) + ctx.lineTo(83050, -270) + ctx.moveTo(83375, -210) + ctx.lineTo(83375, -270) + ctx.moveTo(83700, -210) + ctx.lineTo(83700, -270) + ctx.moveTo(84200, -310) + ctx.lineTo(84200, -370) + ctx.stroke() + ctx.strokeStyle = "#FF000044" + ctx.moveTo(66987.5, -930) + ctx.lineTo(66987.5, -845) + ctx.moveTo(67062.5, -930) + ctx.lineTo(67062.5, -845) + ctx.moveTo(66987.5 + 1150, -930) + ctx.lineTo(66987.5 + 1150, -845) + ctx.moveTo(67062.5 + 1250, -930) + ctx.lineTo(67062.5 + 1250, -845) + ctx.moveTo(69175, -930) + ctx.lineTo(69175, -845) + ctx.moveTo(69875, -930) + ctx.lineTo(69875, -845) + ctx.moveTo(74425, -515) + ctx.lineTo(74425, -590) + ctx.moveTo(74625, -515) + ctx.lineTo(74625, -590) + ctx.moveTo(77975, -975) + ctx.lineTo(77975, -1040) + ctx.moveTo(78225, -850) + ctx.lineTo(78225, -915) + ctx.moveTo(78475, -725) + ctx.lineTo(78475, -790) + ctx.moveTo(81600, -930) + ctx.lineTo(81600, -845) + ctx.moveTo(81700, -930) + ctx.lineTo(81700, -845) + ctx.moveTo(81800, -930) + ctx.lineTo(81800, -845) + ctx.moveTo(83050, -305) + ctx.lineTo(83050, -370) + ctx.moveTo(83375, -305) + ctx.lineTo(83375, -370) + ctx.moveTo(83700, -305) + ctx.lineTo(83700, -370) + ctx.moveTo(84200, -405) + ctx.lineTo(84200, -470) + ctx.stroke() + ctx.strokeStyle = "#FF000022" + ctx.moveTo(66987.5, -1060) + ctx.lineTo(66987.5, -965) + ctx.moveTo(67062.5, -1060) + ctx.lineTo(67062.5, -965) + ctx.moveTo(66987.5 + 1150, -1060) + ctx.lineTo(66987.5 + 1150, -965) + ctx.moveTo(67062.5 + 1250, -1060) + ctx.lineTo(67062.5 + 1250, -965) + ctx.moveTo(69175, -1060) + ctx.lineTo(69175, -965) + ctx.moveTo(69875, -1060) + ctx.lineTo(69875, -965) + ctx.moveTo(74425, -620) + ctx.lineTo(74425, -712.5) + ctx.moveTo(74625, -620) + ctx.lineTo(74625, -712.5) + ctx.moveTo(77975, -1075) + ctx.lineTo(77975, -1120) + ctx.moveTo(78225, -950) + ctx.lineTo(78225, -995) + ctx.moveTo(78475, -825) + ctx.lineTo(78475, -870) + ctx.moveTo(81600, -1060) + ctx.lineTo(81600, -965) + ctx.moveTo(81700, -1060) + ctx.lineTo(81700, -965) + ctx.moveTo(81800, -1060) + ctx.lineTo(81800, -965) + ctx.moveTo(83050, -405) + ctx.lineTo(83050, -470) + ctx.moveTo(83375, -405) + ctx.lineTo(83375, -470) + ctx.moveTo(83700, -405) + ctx.lineTo(83700, -470) + ctx.moveTo(84200, -505) + ctx.lineTo(84200, -570) + ctx.stroke() + let star = 95525; + for (let i = 0; i < 3; i++) { + drawStar(star, -1540, 5, 40, 15); + star += 200; + } + drawStar(97375, -1540, 5, 25, 10) + drawStar(97675, -1540, 5, 25, 10) + drawStar(97975, -1540, 5, 25, 10) + drawStar(98275, -1540, 5, 25, 10) + drawStar(98575, -1540, 5, 25, 10) + + }; + var gradient = ctx.createLinearGradient(0, 0, 175, 0); + gradient.addColorStop(0, "#7704FF00"); + gradient.addColorStop(1, "#00FFFF"); + level.customTopLayer = () => { + if (player.position.x > 25360 && player.position.x < 46470 && player.position.y > -2348 || player.position.x > 87995 && player.position.x < 103950 && player.position.y > -1350) { + player.force.x += 0.0045 + m.airControl = () => { + if (input.up) { + player.force.y -= 0.02 + } + } + m.draw = () => { + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 + ctx.translate(player.position.x, player.position.y); + ctx.rotate(player.angle); + if (input.up) { //forward thrust drawing + ctx.rotate(`${Math.max(-0.5, Math.min(m.angle, 0.5))}`) + } else { + ctx.rotate(`${Math.max(0.5, Math.min(m.angle, -0.5))}`) + } + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.beginPath() + ctx.moveTo(30, 0) + ctx.lineTo(60, 10) + ctx.lineTo(60, 30) + ctx.lineTo(20, 40) + ctx.lineTo(0, 40) + ctx.lineTo(-50, 60) + ctx.lineTo(-50, 0) + ctx.lineTo(-40, -40) + ctx.lineTo(-40, -40) + ctx.lineTo(-30, 10) + ctx.lineTo(30, 10) + ctx.lineTo(30, 0) + ctx.fill(); + ctx.moveTo(-50, 30) + ctx.lineTo(-60, 30) + ctx.lineTo(-60, 0) + ctx.lineTo(-50, 0) + ctx.fill() + ctx.stroke() + ctx.restore(); + } + } else { + m.resetSkin() + m.airControl = () => { + if (input.up && m.buttonCD_jump + 20 < m.cycle && m.yOffWhen.stand > 23 && m.lastOnGroundCycle + 5 > m.cycle) m.jump() + if (m.buttonCD_jump + 60 > m.cycle && !(input.up) && m.Vy < 0) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y * 0.94 + }); + } + if (input.left) { + if (player.velocity.x > -m.airSpeedLimit / player.mass / player.mass) player.force.x -= m.FxAir; // move player left / a + } else if (input.right) { + if (player.velocity.x < m.airSpeedLimit / player.mass / player.mass) player.force.x += m.FxAir; //move player right / d + } + } + } + ctx.fillStyle = `rgba(68, 68, 68, ${Math.max(0.1, Math.min((-1400 - m.pos.y) / -100, 0.99))})`; + ctx.fillRect(91900, -1675, 12050, 375) + ctx.save() + ctx.translate(104700, -1675); + ctx.fillStyle = gradient; + ctx.fillRect(0, 0, 175, 1675) + ctx.restore() + }; + level.setPosToSpawn(0, -150); //spawn + level.defaultZoom = 1800 //default I think + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#0150FF"; + document.body.style.transitionDuration = "1500ms"; //smoother transitions, so that people don't complain + level.exit.x = 133150; + level.exit.y = -260; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 20); + //ground? I forgot + spawn.mapRect(-5000, 0, 110000, 1000); + //*mountains to prevent player from running away* + spawn.mapVertex(-5775, -1330, "0 0 1000 7000 -1000 7000"); + spawn.mapVertex(-7000, -330, "0 0 1000 4000 -1000 4000"); + spawn.mapVertex(-10000, -330, "0 0 1000 4000 -1000 4000"); + spawn.mapVertex(-9000, -330, "0 0 1000 4000 -1000 4000"); + spawn.mapVertex(-7500, -330, "0 0 1000 4000 -1000 4000"); + spawn.mapRect(-10000, 0, 3500, 1000); + //spawn.mapRect(-10000, -10000, 1000, 11000); + //hunter(-600, -150) + //stage one --> 0% + //spikes + spike(3000, -30); + spike(5000, -30); + spike(4925, 0); + spike(7275, -30); + spike(7375, -30); + spike(9806, -30); + spike(9900, -30); + spike(12000, -130); + spike(13050, -255); + spike(17300, -1105); + spike(17400, -1105); + spike(17200, -1105); + spike(17500, -1105); + spike(18200, -1105); + spike(18100, -1105); + spike(18300, -1105); + spike(18400, -1105); + spike(19875, -1108); + spike(19975, -930); + spike(21000, -930); + spike(21725, -780); + spike(23600, -1230); + spawn.mapVertex(62000, -300, "0 1000 1000 1000 0 0"); + //upside down spikes + let u = Math.PI * 1.5; + spike(18825, -1170, u); + spike(18925, -1170, u); + spike(19025, -1170, u); + spike(19125, -1170, u); + spike(19225, -1170, u); + spike(19325, -1170, u); + spike(49962.5, -2370, u); + spike(50062.5, -2370, u); + spike(50162.5, -2370, u); + spike(50262.5, -2370, u); + spike(50362.5, -2370, u); + //bottom of the flying part + spike(32375, -280); + spike(32475, -280); + spike(32575, -280); + spike(32675, -280); + spike(32775, -280); + spike(32875, -280); + spike(32975, -280); + spike(33075, -280); + spike(33175, -280); + spike(33275, -280); + spike(33375, -280); + spike(33475, -280); + spike(33575, -280); + spike(33675, -280); + spike(35575, -280); + spike(35675, -280); + spike(35775, -280); + spike(35875, -280); + spike(39775, -280); + spike(39875, -280); + spike(39975, -280); + spike(40075, -280); + spike(40175, -280); + spike(40275, -280); + spike(40475, -280); + spike(40575, -280); + spike(40675, -280); + spike(40775, -280); + spike(40875, -280); + spike(40975, -280); + //top of the flying part + spike(32375, -2193, u); + spike(32475, -2193, u); + spike(32575, -2193, u); + spike(32675, -2193, u); + spike(32775, -2193, u); + spike(32875, -2193, u); + spike(32975, -2193, u); + spike(33075, -2193, u); + spike(33175, -2193, u); + spike(33275, -2193, u); + spike(33375, -2193, u); + spike(33475, -2193, u); + spike(33575, -2193, u); + spike(33675, -2193, u); + spike(37750, -2193, u); + spike(37850, -2193, u); + spike(37950, -2193, u); + spike(38050, -2193, u); + spike(43025, -2193, u); + spike(43125, -2193, u); + spike(43225, -2193, u); + spike(43325, -2193, u); + spike(43425, -2193, u); + spike(43525, -2193, u); + spike(43725, -2193, u); + spike(43825, -2193, u); + spike(43925, -2193, u); + spike(44025, -2193, u); + spike(44125, -2193, u); + spike(44225, -2193, u); + spike(44325, -2193, u); + spike(44425, -2193, u); + spike(44525, -2193, u); + spike(44625, -2193, u); + spike(44725, -2193, u); + spike(44825, -2193, u); + //about 55% of the map + spike(63375, -30); + spike(63475, -30); + spike(65775, -30); + spike(65875, -30); + spike(66975, -30); + spike(67075, -30); + spike(66975, -500, u); + spike(67075, -500, u); + spike(68125, -30); + spike(68225, -30); + spike(68325, -30); + spike(68125, -500, u); + spike(68225, -500, u); + spike(68325, -500, u); + spike(69175, -500, u); + spike(69175, -30); + spike(69875, -500, u); + spike(69875, -30); + spike(70675, -30); + spike(70775, -30); + spike(73725, -30); + spike(73825, -30); + spike(74425, -195, u); + spike(74525, -195, u); + spike(74625, -195, u); + spike(75125, -30); + spawn.mapVertex(78725, -466, "0 50 100 50 50 0"); //ocd still triggers from -467 + spike(79300, -180); + spike(80800, -30); + spike(80900, -30); + spike(81600, -30); + spike(81700, -30); + spike(81800, -30); + spike(81600, -500, u); + spike(81700, -500, u); + spike(81800, -500, u); + spike(93425, -1430); + spike(93525, -1430); + spike(85800, -305); + spike(86475, -305); + spike(87150, -455); + spike(94025, -1570, u); + spike(94125, -1570, u); + spike(94500, -1430); + spike(94700, -1430); + spike(94900, -1430); + spike(94600, -1400); + spike(94800, -1400); + spike(94212.5, -1675, u); + spike(94287.5, -1675, u); + //even more 90% + spike(95525, -1400) + spike(95525, -1675, u) + spike(95625, -1400) + spike(95625, -1675, u) + spike(95725, -1400) + spike(95725, -1675, u) + spike(95825, -1400) + spike(95825, -1675, u) + spike(95925, -1400) + spike(95925, -1675, u) + spike(96025, -1400) + spike(96225, -1400) + spike(96650, -1675, u) + spike(96900, -1400) + spike(97150, -1675, u) + spike(98900, -1400) + spike(96975, -155) + spike(97075, -155) + spike(97175, -155) + spike(97275, -155) + spike(97375, -155) + spike(97475, -155) + spike(96975, -1170, u) + spike(97075, -1170, u) + spike(97175, -1170, u) + spike(97275, -1170, u) + spike(97375, -1170, u) + spike(97475, -1170, u) + spike(98700, -1070, u) + spike(98800, -1070, u) + spike(98900, -1070, u) + spike(99000, -1070, u) + spike(99100, -1070, u) + spike(99200, -1070, u) + spike(98700, -230) + spike(98800, -230) + spike(98900, -230) + spike(99000, -230) + spike(99100, -230) + spike(99200, -230) + spike(98975, -1400) + spike(99375, -1675, u) + spike(99300, -1675, u) + spike(99575, -1675, u) + spike(100000, -1400) + //actual stuff + spawn.mapRect(7425, -175, 75, 175); + spawn.mapRect(7675, -250, 75, 250); + spawn.mapRect(7925, -325, 75, 325); + spawn.mapRect(10625, -100, 725, 100); + spawn.mapRect(11625, -100, 725, 100); + spawn.mapRect(12650, -225, 800, 225); + spawn.mapRect(13675, -300, 100, 50); + spawn.mapRect(13975, -400, 100, 50); + spawn.mapRect(14275, -500, 100, 50); + spawn.mapRect(14575, -600, 100, 50); + spawn.mapRect(14875, -700, 100, 50); + spawn.mapRect(15175, -800, 100, 50); + spawn.mapRect(15475, -900, 100, 50); + spawn.mapRect(15775, -1000, 100, 50); + spawn.mapRect(16075, -1100, 100, 50); + spawn.mapRect(16375, -1200, 100, 50); + spawn.mapRect(16625, -1075, 350, 100); + spawn.mapRect(16800, -1075, 1825, 1125); + spawn.mapRect(17250, -1225, 200, 50); + spawn.mapRect(18150, -1225, 200, 50); + spawn.mapRect(18550, -975, 1050, 1025); + spawn.mapRect(19525, -1075, 400, 1125); + spawn.mapRect(18775, -1275, 600, 75); + spawn.mapRect(19825, -900, 500, 950); + spawn.mapRect(20150, -900, 375, 125); + spawn.mapRect(20750, -900, 300, 50); + spawn.mapRect(21225, -750, 550, 50); + spawn.mapRect(21950, -625, 450, 50); + spawn.mapRect(22550, -700, 100, 50); + spawn.mapRect(22750, -800, 100, 50); + spawn.mapRect(22950, -900, 100, 50); + spawn.mapRect(23150, -1000, 100, 50); + spawn.mapRect(23350, -1100, 100, 50); + spawn.mapRect(23550, -1200, 100, 50); + spawn.mapRect(23525, -975, 400, 100); + spawn.mapRect(23650, -975, 1825, 1025); + spawn.mapRect(23750, -2500, 625, 1125); + spawn.mapRect(24000, -2500, 1200, 1300); + spawn.mapRect(24900, -2500, 575, 1125); + spawn.mapRect(25425, -2500, 20000, 275); + spawn.mapRect(25425, -250, 20000, 300); + spawn.mapRect(29450, -2300, 200, 675); + spawn.mapRect(32225, -2225, 100, 100); + spawn.mapRect(33725, -2225, 100, 100); + spawn.mapRect(32225, -350, 100, 100); + spawn.mapRect(33725, -350, 100, 100); + spawn.mapRect(37600, -2225, 100, 225); + spawn.mapRect(35425, -475, 100, 225); + spawn.mapRect(39625, -400, 100, 150); + spawn.mapRect(40325, -500, 100, 250); + spawn.mapRect(41025, -600, 100, 350); + spawn.mapRect(43575, -2225, 100, 300); + spawn.mapRect(44875, -2500, 1675, 1225); + spawn.mapRect(44875, -950, 1675, 1000); + spawn.mapRect(46425, -825, 1400, 875); + spawn.mapRect(48075, -1100, 175, 1150); + spawn.mapRect(48575, -1300, 175, 1375); + spawn.mapRect(49075, -1500, 175, 1550); + spawn.mapRect(49575, -1700, 175, 975); + spawn.mapRect(49575, -500, 175, 550); + spawn.mapRect(50075, -1900, 175, 700); + spawn.mapRect(50075, -1000, 1000, 1000); + spawn.mapRect(49912.5, -2525, 500, 125); + spawn.mapRect(51300, -1200, 175, 1225); + spawn.mapRect(51700, -1400, 175, 1425); + spawn.mapRect(52100, -1600, 175, 1625); + spawn.mapRect(52500, -1800, 175, 1825); + spawn.mapRect(52900, -2000, 175, 2025); + spawn.mapRect(53300, -2200, 175, 2225); + spawn.mapRect(53700, -2400, 175, 2425); + spawn.mapRect(54100, -2600, 175, 2625); + spawn.mapRect(54500, -2800, 175, 2825); + spawn.mapRect(54900, -3000, 175, 3025); + spawn.mapRect(55050, -3000, 175, 75); + spawn.mapRect(55475, -2875, 250, 75); + spawn.mapRect(55900, -2625, 250, 75); + spawn.mapRect(56500, -2400, 375, 75); + spawn.mapRect(57200, -2200, 250, 75); + spawn.mapRect(57650, -2050, 375, 75); + spawn.mapRect(57650, -1970, 375, 1975); + spawn.mapRect(58650, -1875, 375, 75); + spawn.mapRect(58650, -1795, 375, 1975); + spawn.mapRect(59525, -1750, 175, 75); + spawn.mapRect(60125, -1600, 175, 75); + spawn.mapRect(60750, -1425, 175, 75); + spawn.mapRect(61250, -1225, 175, 75); + spawn.mapRect(61550, -1025, 225, 1125); + spawn.mapRect(63525, -100, 100, 100); + spawn.mapRect(63800, -225, 200, 50); + spawn.mapRect(64175, -100, 100, 100); + spawn.mapRect(64275, -100, 100, 100); + spawn.mapRect(64375, -100, 100, 100); + spawn.mapRect(64675, -225, 200, 50); + spawn.mapRect(65025, -325, 200, 50); + spawn.mapRect(65425, -100, 300, 100); + spawn.mapRect(66925, -650, 200, 120); + spawn.mapRect(68075, -650, 300, 120); + spawn.mapRect(69125, -650, 100, 120); + spawn.mapRect(69825, -650, 100, 120); + spawn.mapRect(70825, -100, 100, 100); + spawn.mapRect(71225, -200, 100, 200); + spawn.mapRect(71625, -300, 100, 300); + spawn.mapRect(72025, -400, 100, 400); + spawn.mapRect(72125, -400, 100, 50); + spawn.mapRect(72375, -325, 100, 50); + spawn.mapRect(72625, -200, 100, 50); + spawn.mapRect(72875, -75, 100, 50); + spawn.mapRect(74375, -300, 300, 75); + spawn.mapRect(75175, -100, 100, 100); + spawn.mapRect(75900, -150, 400, 50); + spawn.mapRect(76550, -250, 100, 50); + spawn.mapRect(76850, -325, 100, 50); + spawn.mapRect(77125, -400, 100, 50); + spawn.mapRect(77425, -475, 300, 50); + spawn.mapRect(77925, -400, 100, 100); + spawn.mapRect(78175, -275, 100, 100); + spawn.mapRect(78425, -150, 100, 100); + spawn.mapRect(78675, -50, 100, 100); + spawn.mapRect(77925, -800, 100, 100); + spawn.mapRect(78175, -675, 100, 100); + spawn.mapRect(78425, -550, 100, 100); + spawn.mapRect(78675, -450, 100, 100); + spawn.mapRect(78450, -100, 50, 125); + spawn.mapRect(79025, -150, 100, 50); + spawn.mapRect(79250, -150, 100, 50); + spawn.mapRect(79475, -150, 100, 50); + spawn.mapRect(79800, -225, 300, 50); + spawn.mapRect(80250, -150, 100, 50); + spawn.mapRect(80450, -100, 300, 50); + spawn.mapRect(81550, -650, 300, 120); + spawn.mapRect(82800, -100, 100, 100); + spawn.mapRect(82900, -100, 200, 50); + spawn.mapRect(83325, -100, 100, 50); + spawn.mapRect(83650, -100, 200, 50); + spawn.mapRect(83850, -100, 100, 100); + spawn.mapRect(83950, -200, 100, 200); + spawn.mapRect(84050, -200, 200, 50); + spawn.mapRect(84500, -350, 100, 50); + spawn.mapRect(84725, -250, 100, 50); + spawn.mapRect(84950, -150, 300, 50); + spawn.mapRect(85525, -275, 100, 50); + spawn.mapRect(85750, -275, 100, 50); + spawn.mapRect(85950, -275, 375, 50); + spawn.mapRect(86425, -275, 100, 50); + spawn.mapRect(86625, -275, 100, 50); + spawn.mapRect(86900, -425, 300, 50); + spawn.mapRect(87375, -275, 300, 50); + spawn.mapRect(87900, -300, 125, 300); + spawn.mapRect(87900, -1850, 125, 1150); + spawn.mapRect(87900, -1850, 17000, 175); + spawn.mapRect(104875, -1850, 125, 2850); //Last part + spawn.mapRect(87900, -1850, 4000, 550); + spawn.mapRect(89650, -100, 100, 100); + spawn.mapRect(89750, -200, 100, 100); + spawn.mapRect(89850, -300, 600, 100); + spawn.mapRect(90450, -200, 100, 100); + spawn.mapRect(90550, -100, 100, 100); + spawn.mapRect(89650, -1300, 100, 100); + spawn.mapRect(89750, -1200, 100, 100); + spawn.mapRect(89850, -1100, 600, 100); + spawn.mapRect(90450, -1200, 100, 100); + spawn.mapRect(90550, -1300, 100, 100); + spawn.mapRect(91950, -100, 100, 100); + spawn.mapRect(92050, -200, 100, 100); + spawn.mapRect(92150, -300, 600, 100); + spawn.mapRect(92750, -200, 100, 100); + spawn.mapRect(92850, -100, 100, 100); + spawn.mapRect(92050, -1200, 100, 100); + spawn.mapRect(92150, -1100, 600, 100); + spawn.mapRect(92750, -1200, 100, 100); + spawn.mapRect(92850, -1300, 100, 100); + spawn.mapRect(92950, -1400, 11000, 100); + spawn.mapRect(93975, -1700, 200, 100); + spawn.mapRect(96075, -1500, 100, 100); + spawn.mapRect(96500, -1675, 100, 100); + spawn.mapRect(96950, -1490, 1900, 100); + spawn.mapRect(97200, -1685, 1650, 100); + spawn.mapRect(93900, -300, 100, 300); + spawn.mapRect(93900, -400, 300, 100); + spawn.mapRect(94100, -300, 100, 300); + spawn.mapRect(95025, -1300, 100, 300); + spawn.mapRect(95025, -1000, 300, 100); + spawn.mapRect(95225, -1300, 100, 300); + spawn.mapRect(96925, -1300, 600, 100); + spawn.mapRect(96925, -125, 600, 125); + spawn.mapRect(98650, -1300, 100, 200); + spawn.mapRect(98650, -1200, 600, 100); + spawn.mapRect(99150, -1300, 100, 200); + spawn.mapRect(98650, -200, 100, 200); + spawn.mapRect(99150, -200, 100, 200); + spawn.mapRect(98650, -200, 600, 100); + spawn.mapRect(100825, -1300, 100, 300); + spawn.mapRect(100825, -1100, 1325, 100); + spawn.mapRect(102050, -1300, 100, 300); + spawn.mapRect(100825, -300, 100, 300); + spawn.mapRect(100825, -300, 1350, 100); + spawn.mapRect(102075, -300, 100, 300); + spawn.mapRect(99425, -1675, 100, 125); + spawn.mapRect(100050, -1525, 100, 125); + + spawn.mapRect(132025, -225, 2325, 525); + spawn.mapRect(132025, -1450, 500, 1750); + spawn.mapRect(133875, -1475, 475, 1775); + spawn.mapRect(132025, -1925, 2325, 475); + + // simulation.enableConstructMode() //also remove when done + coin(50165.9, -1090) + coin(78725.4, -600) + coin(103830.0, -1473) + hunter(0, -1000) + }, + yingYang() { + simulation.inGameConsole(`yingYang by Richard0820`); + + let destroyed = false; + const lock = level.door(425, -1400, 50, 300, 300); + const core = function (x, y, radius = 100 + Math.ceil(Math.random() * 25)) { + radius = 9 + radius / 8; //extra small + mobs.spawn(x, y, 6, radius, "transparent"); + let me = mob[mob.length - 1]; + me.constraint = Constraint.create({ + pointA: { + x: me.position.x, + y: me.position.y + }, + bodyB: me, + stiffness: 1, + damping: 1 + }); + Composite.add(engine.world, me.constraint); + me.stroke = "transparent"; //used for drawSneaker + me.eventHorizon = radius * 40; + me.seeAtDistance2 = (me.eventHorizon + 400) * (me.eventHorizon + 400); //vision limit is event horizon + me.accelMag = 0.00012 * simulation.accelScale; + me.frictionAir = 0.025; + me.collisionFilter.mask = cat.player | cat.bullet //| cat.body + me.showHealthBar = false; + me.memory = Infinity; + me.isBoss = true; + Matter.Body.setDensity(me, 1); //extra dense //normal is 0.001 //makes effective life much larger + me.onDeath = function () { + destroyed = true; + powerUps.spawnBossPowerUp(this.position.x, this.position.y); + } + me.do = function () { + if (this.health < 1) { + this.health += 0.001; //regen + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: this.radius / 1.5, + color: `rgba(0, 255, 20, ${Math.random() * 0.1})`, + time: simulation.drawTime + }); + } + this.curl() + this.repelBullets() + this.seePlayerCheckByDistance() + this.checkStatus(); + const eventHorizon = this.eventHorizon * (0.93 + 0.17 * Math.sin(simulation.cycle * 0.011)) + //draw darkness + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon * 0.25, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(250,250,250,0.9)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon * 0.55, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(250,250,250,0.5)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(250,250,250,0.1)"; + ctx.fill(); + //when player is inside event horizon + if (Vector.magnitude(Vector.sub(this.position, player.position)) < eventHorizon) { + if (m.immuneCycle < m.cycle) { + if (m.energy > 0) m.energy -= 0.005 + if (m.energy < 0.1) m.damage(0.0001 * simulation.dmgScale); + } + const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x); + player.force.x += 0.00125 * player.mass * Math.cos(angle) * (m.onGround ? 1.8 : 1); + player.force.y += 0.0001 * player.mass * Math.sin(angle); + //draw line to player + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineWidth = Math.min(60, this.radius * 2); + ctx.strokeStyle = "rgba(250,250,250,0.5)"; + ctx.stroke(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(250,250,250,0.3)"; + ctx.fill(); + } + } + } + const sniper = function (x, y, radius = 35 + Math.ceil(Math.random() * 30)) { //same, just white so that we can seen + mobs.spawn(x, y, 3, radius, "transparent"); //"rgb(25,0,50)") + let me = mob[mob.length - 1]; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + me.isVerticesChange = true + // Matter.Body.rotate(me, Math.PI) + me.stroke = "transparent"; //used for drawSneaker + me.alpha = 1; //used in drawSneaker + me.showHealthBar = false; + me.frictionStatic = 0; + me.friction = 0; + me.canTouchPlayer = false; //used in drawSneaker + me.isBadTarget = true; + me.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob //can't touch player + + me.memory = 30 //140; + me.fireFreq = 0.005 + Math.random() * 0.002 + 0.0005 * simulation.difficulty; //larger = fire more often + me.noseLength = 0; + me.fireAngle = 0; + me.accelMag = 0.0005 * simulation.accelScale; + me.frictionAir = 0.05; + me.torque = 0.0001 * me.inertia; + me.fireDir = { + x: 0, + y: 0 + }; + me.onDeath = function () { //helps collisions functions work better after vertex have been changed + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) + } + // spawn.shield(me, x, y); + me.do = function () { + // this.seePlayerByLookingAt(); + this.seePlayerCheck(); + this.checkStatus(); + + const setNoseShape = () => { + const mag = this.radius + this.radius * this.noseLength; + this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag; + }; + //throw a mob/bullet at player + if (this.seePlayer.recall) { + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + // this.fireDir.y -= Math.abs(this.seePlayer.position.x - this.position.x) / 1600; //gives the bullet an arc + } + //rotate towards fireAngle + const angle = this.angle + Math.PI / 2; + // c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + //rotate towards fireAngle + const dot = Vector.dot({ + x: Math.cos(angle), + y: Math.sin(angle) + }, this.fireDir) + const threshold = 0.03; + if (dot > threshold) { + this.torque += 0.000004 * this.inertia; + } else if (dot < -threshold) { + this.torque -= 0.000004 * this.inertia; + } else if (this.noseLength > 1.5 && dot > -0.2 && dot < 0.2) { + //fire + spawn.sniperBullet(this.vertices[1].x, this.vertices[1].y, 7 + Math.ceil(this.radius / 15), 5); + const v = 10 + 8 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v + Math.random(), + y: this.velocity.y + this.fireDir.y * v + Math.random() + }); + this.noseLength = 0; + // recoil + this.force.x -= 0.005 * this.fireDir.x * this.mass; + this.force.y -= 0.005 * this.fireDir.y * this.mass; + } + if (this.noseLength < 1.5) this.noseLength += this.fireFreq; + setNoseShape(); + } else if (this.noseLength > 0.1) { + this.noseLength -= this.fireFreq / 2; + setNoseShape(); + } + // else if (this.noseLength < -0.1) { + // this.noseLength += this.fireFreq / 4; + // setNoseShape(); + // } + + if (this.seePlayer.recall) { + if (this.alpha < 1) this.alpha += 0.01; + } else { + if (this.alpha > 0) this.alpha -= 0.03; + } + //draw + if (this.alpha > 0) { + if (this.alpha > 0.95) { + this.healthBar(); + if (!this.canTouchPlayer) { + this.canTouchPlayer = true; + this.isBadTarget = false; + this.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob; //can touch player + } + } + //draw body + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.fillStyle = `rgba(250,250,250,${this.alpha * this.alpha})`; + ctx.fill(); + } else if (this.canTouchPlayer) { + this.canTouchPlayer = false; + this.isBadTarget = true + this.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob //can't touch player + } + }; + } + const portal = level.portal({ + x: 650, + y: -1000 + }, Math.PI * 1.5, { + x: 525, + y: 2625 + }, -Math.PI) + document.body.style.transition = '0ms' + document.body.style.backgroundColor = "#061026" //"#061026"; + + var yy = new Image(); + yy.src = 'https://raw.githubusercontent.com/Whyisthisnotavalable/image-yy/main/Hotpot6.png'; + color.map = "#FFFFFF11"; + color.bullet = "#FFFFFF"; + level.custom = () => { + level.enter.draw(); + level.exit.drawAndCheck(); + ctx.drawImage(yy, 0 - 500, 0 - 500, 1000, 1000) + portal[0].draw(); + portal[1].draw(); + portal[2].query(); + portal[3].query(); + if (destroyed == false) { + lock.isClosing = true; + } else { + lock.isClosing = false; + } + lock.openClose(); + + }; + level.customTopLayer = () => { + lock.draw() + /* + ctx.beginPath() + ctx.strokeStyle = "transparent"; + ctx.fillStyle = "#FFFFFF22" + ctx.arc(m.pos.x, m.pos.y, 500, 0, Math.PI * 2) + ctx.fill() + ctx.fillStyle = "#FFFFFF55" + ctx.arc(m.pos.x, m.pos.y, 1000, 0, Math.PI * 2) + ctx.fill(); + ctx.stroke(); */ + ctx.beginPath(); + ctx.moveTo(m.pos.x, m.pos.y) + const arc = Math.PI / 4 + ctx.arc(m.pos.x, m.pos.y, 100, m.angle + arc, m.angle - arc) + ctx.arc(m.pos.x, m.pos.y, 4000, m.angle - arc, m.angle + arc) + ctx.fillStyle = "rgba(255,255,255,0.7)"; + ctx.globalCompositeOperation = "destination-in"; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + ctx.clip(); + }; + level.setPosToSpawn(0, -50); + level.exit.x = -275; + level.exit.y = 2900; + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + //map + spawn.mapRect(-125, -325, 225, 25); + spawn.mapRect(300, -150, 25, 325); + spawn.mapRect(-325, -125, 25, 300); + spawn.mapRect(-150, 300, 275, 25); + spawn.mapRect(125, -300, 25, 25); + spawn.mapRect(175, -275, 25, 25); + spawn.mapRect(225, -250, 25, 25); + spawn.mapRect(250, -200, 25, 25); + spawn.mapRect(-175, -300, 25, 25); + spawn.mapRect(-225, -275, 25, 25); + spawn.mapRect(-300, -200, 25, 25); + spawn.mapRect(150, 275, 25, 25); + spawn.mapRect(200, 225, 25, 25); + spawn.mapRect(250, 200, 25, 25); + spawn.mapRect(250, -225, 25, 25); + spawn.mapRect(275, -175, 25, 25); + spawn.mapRect(200, -275, 25, 25); + spawn.mapRect(150, -300, 25, 25); + spawn.mapRect(100, -325, 25, 25); + spawn.mapRect(-150, -300, 25, 25); + spawn.mapRect(-200, -300, 25, 25); + spawn.mapRect(-250, -250, 25, 25); + spawn.mapRect(-275, -225, 25, 25); + spawn.mapRect(-300, -175, 25, 50); + spawn.mapRect(275, 175, 25, 25); + spawn.mapRect(250, 200, 25, 25); + spawn.mapRect(225, 225, 25, 25); + spawn.mapRect(175, 250, 25, 25); + spawn.mapRect(125, 300, 25, 25); + spawn.mapRect(-300, 325, 200, 150); + spawn.mapRect(-400, 425, 225, 150); + spawn.mapRect(-4450, 2900, 1550, 150); + spawn.mapRect(-4500, 2525, 150, 525); + spawn.mapRect(-4800, 2150, 150, 400); + spawn.mapRect(-4400, 2025, 650, 150); + spawn.mapRect(-2425, 50, 2125, 150); + spawn.mapRect(-2425, 50, 150, 1300); + spawn.mapRect(-4600, 1175, 2325, 175); + spawn.mapRect(-5075, 1650, 450, 150); + spawn.mapRect(-4650, 1225, 75, 125); + spawn.mapRect(-4700, 1275, 75, 75); + spawn.mapRect(-425, 2925, 425, 125); + spawn.mapRect(-450, 2375, 450, 100); + spawn.mapRect(-3050, 550, 150, 450); + spawn.mapRect(-2925, 825, 100, 175); + spawn.mapRect(-2650, 375, 275, 125); + spawn.mapRect(-75, 2950, 300, 100); + spawn.mapRect(-625, -500, 125, 575); + spawn.mapRect(-1050, -325, 275, 100); + spawn.mapRect(-1075, -775, 100, 550); + spawn.mapRect(-1075, -775, 300, 100); + spawn.mapRect(-525, -1100, 1025, 625); + spawn.mapRect(450, -1000, 450, 1500); + spawn.mapRect(-300, 500, 1200, 75); + spawn.mapRect(-200, 425, 725, 100); + spawn.mapRect(525, 2450, 275, 600); + spawn.mapRect(-25, 2375, 825, 125); + spawn.mapRect(400, -1500, 500, 100); + spawn.mapRect(800, -1500, 100, 525); + spawn.mapRect(-400, 500, 1250, 1900); + spawn.mapRect(-300, 2910, 150, 25); + spawn.mapRect(-625, -1000, 125, 175); + spawn.spawnStairs(-400, 3000, 25, 2500, 2500, 250); + spawn.spawnStairs(500, 3000, 5, 250, 250, 250); + spawn.debris(-1550, -250, 100); + spawn.debris(-1100, 850, 100); + spawn.debris(-3700, 1025, 100); + spawn.debris(-3525, 2725, 100); + spawn.debris(-4750, 2050, 100); + spawn.debris(-4000, 1900, 100); + spawn.debris(225, -1225, 100); + + //mobs + spawn.sneaker(-1350, 1350); + spawn.sneaker(-2275, 2275); + sniper(-3050 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100), 1475 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100)); + sniper(-2925 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100), 1775 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100)); + sniper(-3075 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100), 1600 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100)); + sniper(-3100 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100), 1975 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100)); + sniper(-3075 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100), 1750 + Math.floor(Math.random() * 100) - Math.floor(Math.random() * 100)); + sniper(-3350, 425); + sniper(-3550, 600); + sniper(-3325, 775); + sniper(-5525, 1975); + sniper(-50, -1300); + for (let i = 0; i < 10 + simulation.difficulty; i++) { + spawn.ghoster(0 + Math.floor(Math.random() * 5000) - Math.floor(Math.random() * 5000), 0 + Math.floor(Math.random() * 5000) - Math.floor(Math.random() * 5000)) + } + core(-2000, -1000); + powerUps.spawnStartingPowerUps(0, 0) + powerUps.addResearchToLevel() + }, + staircase() { + simulation.inGameConsole(`staircase by ryanbear`); + + level.custom = () => { + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + aaa.query(); + bbb.query(); + ccc.query(); + ddd.move(); + eee.query(); + fff.query(); + ggg.query(); + hhh.query(); + iii.query(); + jjj.query(); + kk.query(); + lll.query(); + mmm.query(); + nnn.query(); + ooo.query(); + ppp.query(); + }; + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 7300; + level.exit.y = -5154; + // spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + + spawn.mapRect(-100, 0, 2100, 100); + spawn.mapRect(1984, 17, 100, 500); + spawn.mapRect(2013, 522, 1618, 100); + spawn.bodyRect(2090, 328, 100, 100); + + spawn.mapRect(3619, 14, 100, 500) + var aaa = level.hazard(1999, 10, 1618, 500); + var bbb = level.vanish(2320, -345, 234, 20); + var ccc = level.vanish(2862, -324, 234, 20); + var eee = level.vanish(3002, -1100, 234, 20); + var ddd = level.elevator(3399, -420, 200, 200, -950, 0.003, { up: 0.1, down: 0.2 }) //x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + var fff = level.vanish(3359, -1300, 234, 20); + var ggg = level.boost(3020, -1600, 700); + var hhh = level.vanish(2700, -1940, 1147, 20); + var iii = level.boost(5038, -2000, 700); + var jjj = level.vanish(5092, -3498, 100, 100); + var kk = level.boost(5092, -3772, 700); + var lll = level.boost(5372, -2824, 700); + var mmm = level.vanish(5112, -3000, 100, 100); + var nnn = level.vanish(5367, -3000, 100, 100); + var ooo = level.boost(4810, -3161, 700); + var ppp = level.vanish(5383, -3485, 100, 100); + spawn.mapRect(5377, -4198, 1000, 100); + spawn.mapRect(6390, -4359, 200, 200); + spawn.mapRect(6605, -4563, 200, 200); + spawn.mapRect(6809, -4758, 200, 200); + spawn.mapRect(7014, -4962, 200, 200); + spawn.mapRect(7212, -5158, 200, 200); + + + + spawn.mapRect(4156, -1898, 1000, 100); + // spawn.bodyRect(1540, -1110, 300, 25, 0.9); + // spawn.randomSmallMob(1300, -70); + spawn.randomMob(590, -315); + spawn.randomMob(1343, -757); + spawn.randomMob(4037, -926); + spawn.randomMob(3621, -2376); + spawn.randomMob(5026, -2441); + spawn.randomMob(4253, -2863); + spawn.randomMob(4355, -2430); + spawn.randomMob(5316, -3265); + spawn.randomMob(5885, -4427); + spawn.randomMob(6666, -4979); + + + + spawn.laserBoss(6128, -4905); + + // spawn.randomGroup(1700, -900, 0.4); + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + fortress() { + simulation.inGameConsole(`fortress by Desboot`); + const boost1 = level.boost(3600, -250, 1000) + const boost2 = level.boost(60, -604, 1000) + const boost3 = level.boost(2160, -1260, 1000) + powerUps.spawnStartingPowerUps(1033.3, -121.4) + level.custom = () => { + boost1.query(); + boost2.query(); + boost3.query(); + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 3586; //3586.5, -1464.0 + level.exit.y = -1494; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + level.customTopLayer = () => { + ctx.fillStyle = "rgba(0,0,0,0.3)" + ctx.fillRect(-272, -580, 1700, 600) + ctx.fillRect(1427.5, -487, 1280, 600) + ctx.fillRect(2707.3, -580, 1200, 600) + ctx.fillStyle = "rgba(0,0,0,0.2)" + ctx.fillRect(2752, -1744, 1075, 1164) + ctx.fillRect(937, -1590, 339, 550) + ctx.fillRect(1158, -1040, 118, 550) + ctx.fillRect(3049, -1063, 339, 500) + ctx.fillRect(1439, -1281, 297, 800) + ctx.fillRect(2130, -1182, 167, 800) + ctx.fillRect(1892, -2073, 238, 1593) + ctx.fillRect(2297, -2073, 238, 1593) + ctx.fillStyle = "rgba(0,0,0,0.15)" + ctx.fillRect(483, -1277, 350, 700) + ctx.fillRect(833, -1000, 325, 450) + ctx.fillStyle = "rgba(64,64,64,0.97)" //hidden section + ctx.fillRect(2800, -1712, 730, 300) + }; + + spawn.debris(2700, -120, 180, 3); + spawn.debris(1350, -100, 280, 3); + spawn.debris(2300, -700, 380, 5); + spawn.debris(976, -775, 38, 5); + spawn.debris(840, -1424, 3080, 5); + spawn.debris(2300, -700, 3080, 5); + + spawn.mapRect(-272, 0, 4198, 123); + spawn.mapRect(-272, -581, 132, 581); + spawn.mapRect(-272, -581, 572, 326); + spawn.mapRect(1462, -229, 92, 229); + spawn.mapRect(1462, -229, 352, 57); + spawn.mapRect(2872, -220, 1056, 330); + spawn.mapRect(170, -260, 484, 80); + spawn.mapRect(476, -581, 1162, 75); + spawn.mapRect(951, -519, 1760, 132); + spawn.mapRect(1747, -492, 506, 66); + spawn.mapRect(2462, -581, 1074, 75); + spawn.mapRect(1136, -616, 510, 100); + spawn.mapRect(3815.6, -1461, 114, 1300); //far right wall + spawn.mapRect(480, -1456, 106, 651); //far left wall + spawn.mapRect(1426, -906, 106, 400); + spawn.mapRect(480, -1302, 374, 57); + spawn.mapRect(788, -1302, 75, 308); + spawn.mapRect(788, -1055, 370, 62); + spawn.mapRect(3049, -1170, 471, 106); + spawn.mapRect(3348, -1170, 188, 663); + spawn.mapRect(2751, -1461, 1088, 53); //roof under the exit + spawn.mapRect(2751, -1743, 92, 915); //wall on left or far right side + spawn.mapRect(937, -1667, 339, 84); //upper left platform + spawn.mapRect(1135, -3239, 119, 1450); + spawn.mapRect(1440, -1346, 295, 66); //center left platform + spawn.mapRect(2090, -1240, 242, 57); //center righ platform + spawn.mapRect(1892, -2214, 88, 220); //vertical part of left L + spawn.mapRect(1892, -2073, 238, 84); //flat part of left L + spawn.mapRect(2447, -2214, 88, 220); //vertical part of right L + spawn.mapRect(2297, -2073, 238, 84); //flat part of right L + spawn.mapRect(2751, -1743, 1078, 57); //exit roof //3587.2, -1470.0 + spawn.mapRect(3584, -1470, 103, 57); //wall below door3689 + spawn.mapRect(3428, -1735, 103, 173); //wall covering secret + + spawn.mapRect(-11000, -1000, 100, 10); //SAL + spawn.mapRect(-11000, -1000, 10, 100); //SAL + spawn.mapRect(-10900, -900, 10, 100); //SAL + spawn.mapRect(-11000, -900, 100, 10); //SAL + spawn.mapRect(-11000, -800, 100, 10); //SAL + spawn.mapRect(-10800, -1000, 10, 200); //SAL + spawn.mapRect(-10700, -1000, 10, 200); //SAL + spawn.mapRect(-10800, -1000, 100, 10); //SAL + spawn.mapRect(-10800, -900, 100, 10); //SAL + spawn.mapRect(-10600, -1000, 10, 200); //SAL + spawn.mapRect(-10600, -800, 100, 10); //SAL + + spawn.mapRect(-11000, -91000, 100, 10); //SAL + spawn.mapRect(-11000, -91000, 10, 100); //SAL + spawn.mapRect(-10900, -90900, 10, 100); //SAL + spawn.mapRect(-11000, -90900, 100, 10); //SAL + spawn.mapRect(-11000, -90800, 100, 10); //SAL + spawn.mapRect(-10800, -91000, 10, 200); //SAL + spawn.mapRect(-10700, -91000, 10, 200); //SAL + spawn.mapRect(-10800, -91000, 100, 10); //SAL + spawn.mapRect(-10800, -90900, 100, 10); //SAL + spawn.mapRect(-10600, -91000, 10, 200); //SAL + spawn.mapRect(-10600, -90800, 100, 10); //SAL + //mobs + spawn.randomMob(3104.9, -1284.9, 0.2); + spawn.randomMob(1784.7, -95.9, 0.2); + spawn.randomMob(3474.2, -406.7, 0.1); + spawn.randomMob(1603.2, -1493.5, 0.4); + spawn.randomMob(772.4, -1505.2, 0.2); + spawn.randomMob(824.6, -781.3, 0.2); + spawn.randomMob(818.8, -1468.9, 0.2); + spawn.randomMob(-124.7, -853, 0.2); + spawn.randomMob(3011.1, -1978.0, -0.2); + spawn.randomMob(2428.0, -236.8, 0.1); + spawn.randomSmallMob(694.3, -385.3); + spawn.randomSmallMob(1142.0, -808.4); + spawn.randomSmallMob(791.5, -803.7); + spawn.randomSmallMob(3175.8, -830.8); + spawn.randomSmallMob(1558.5, -1940.8); + spawn.randomSmallMob(2700, -475); + spawn.randomSmallMob(2700, -475); + spawn.pulsar(1762.9, -2768.3) + spawn.pulsar(3821.5, -2373.9) + let randomBoss = Math.floor(Math.random() * 5); + spawn[["laserBoss", "blinkBoss", "shooterBoss", "launcherBoss", "pulsarBoss", "beetleBoss", "bladeBoss", "revolutionBoss", "dragonFlyBoss", "spiderBoss"][randomBoss]](2058.5, -711.4, 100, false); + + //spawn powerups + // powerUps.spawn(3167.6, -1300, "tech") + powerUps.spawn(3125.8, -1543.4, "tech") + powerUps.spawn(3125.8, -1543.4, "heal") + powerUps.spawn(3125.8, -1543.4, "ammo") + powerUps.spawn(3125.8, -1543.4, "ammo") + powerUps.spawn(3137.6, -1300, "ammo") + powerUps.spawn(1605.2, -1436.9, "heal") + powerUps.spawn(2912.9, -1940.9, "ammo") + powerUps.spawn(3167.6, -1300, "heal") + powerUps.spawn(1, 1, "ammo") + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + commandeer() { + simulation.inGameConsole(`commandeer by Desboot`); + + let waterFallWidth = 400 + let waterFallX = 15900 + let waterFallSmoothX = 0 + const elevator = level.elevator(-80.4, -931.6, 180, 50, -1550) + 15900 && player.position.x < 16300 && player.position.y > -960.2 + //const slime = level.hazard(15900, -960, 400, 6000); + const slime2 = level.hazard(15147.2, -1782.4, 2000, 822); + const boost1 = level.boost(5950, -20, 700) + const boost2 = level.boost(21088, -1672, 700) + const boost3 = level.boost(19390, -31, 1700) + const boost4 = level.boost(19390, -31, 1700) + const boost5 = level.boost(17274, -1242, 1000) + const portal = level.portal({ x: 443, y: -1636 }, Math.PI, { x: 21391.9, y: -1806.3 }, -Math.PI) + const portal2 = level.portal({ x: 16838.3, y: -626.7 }, Math.PI, { x: 16882.8, y: -2566.5 }, -Math.PI) + const buttonDoor = level.button(21889, -10) + const door = level.door(19119, -2133, 110, 510, 480) + const buttonDoor2 = level.button(18711, -2210) + const door2 = level.door(17041, -412, 110, 510, 480) + const buttonDoor3 = level.button(20456.6, -1636.2) + const door3 = level.door(20238, -781.4, 88, 452, 412) + const hazard2 = level.hazard(2550, -150, 10, 0.4) //y=-1485 + + // simulation.enableConstructMode() + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 15316; + level.exit.y = -30; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#001738"; + color.map = "#444" //custom map color + + + + level.custom = () => { + //spawn.mapRect(22330, -2688.75, 400, 800); + //spawn.mapRect(22330, -1793.5, 400, 800);//-46.25*2=-92.5 + //spawn.mapRect(22330, -804.25, 400, 800);//-46.25*3 + + + ctx.fillStyle = "rgba(250,250,250,0.8)"//lights + ctx.beginPath() + ctx.moveTo(1124, -628) + ctx.lineTo(496, 0) + ctx.lineTo(1852, 0) + ctx.lineTo(1224, -628) + ctx.fill() + + ctx.beginPath() + ctx.moveTo(906, -1365) + ctx.lineTo(206, -690) + ctx.lineTo(1706, -690) + ctx.lineTo(1006, -1365) + ctx.fill() + + ctx.beginPath() + ctx.moveTo(3330, -1905)//-700 + ctx.lineTo(2815.6, -1405.8) + ctx.lineTo(2815.6, -1230) + ctx.lineTo(4022.9, -1283.9) + ctx.lineTo(4023.5, -1405.8) + ctx.lineTo(3430, -1905) + + ctx.fill() + + + + + ctx.fillStyle = "rgba(63,247,251,0.8)" + ctx.fillRect(22330, -2713.75, 550, 700)//15845.0, -1262.2 + ctx.fillRect(22330, -1743.5, 550, 700) + ctx.fillRect(22330, -754.25, 550, 700) + + ctx.fillRect(6237, -1830.7, 550, 700) + ctx.fillRect(6237, -840.4, 550, 700) + ctx.fillStyle = "rgba(200,200,200,0.8)" + ctx.fillRect(-192, -1973, 6484, 2071) + ctx.fillStyle = "rgba(240,240,240,0.8)" + + ctx.fillRect(15109.5, -2867.5, 7284, 2971) + ctx.fillStyle = "rgba(35,35,35,0.8)" + ctx.fillRect(15145.9, -960, 200, 25) + + + + + ctx.fillStyle = "rgba(255,255,255,0.9)" + + + + + + buttonDoor.query(); + buttonDoor.draw(); + buttonDoor2.query(); + buttonDoor2.draw(); + buttonDoor3.query(); + buttonDoor3.draw(); + + + //slime.query(); + slime2.query(); + + + if (buttonDoor.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + if (buttonDoor2.isUp) { + door2.isClosing = true + } else { + door2.isClosing = false + } + if (buttonDoor3.isUp) { + door3.isClosing = true + } else { + door3.isClosing = false + } + door.openClose(); + door2.openClose(); + door3.openClose(); + portal[2].query() + portal[3].query() + portal2[2].query() + portal2[3].query() + + boost1.query(); + boost2.query(); + boost3.query(); + boost4.query(); + boost5.query(); + level.exit.drawAndCheck(); + level.enter.draw(); + ctx.fillStyle = "rgba(0,0,0,0.2)"//shadows + ctx.fillRect(2773, -682, 469, 500) + ctx.fillRect(3947, -851, 469, 700) + ctx.fillRect(4818, -1006, 400, 400) + ctx.fillRect(5313, -1309, 1000, 700) + + ctx.fillRect(16705, -2831, 40, 700) + ctx.fillRect(16140, -2812, 40, 400) + ctx.fillRect(15559, -2855, 40, 800) + ctx.fillRect(16530, -2855, 30, 200) + + + ctx.beginPath() + ctx.moveTo(18254.7, -2194.1) + ctx.lineTo(18554.6, -1952.7) + ctx.lineTo(18554.6, -1992.7) + ctx.lineTo(18294.7, -2194.1) + ctx.fill() + ctx.beginPath() + ctx.moveTo(18154.7, -1004.1) + ctx.lineTo(18554.6, -762.7) + ctx.lineTo(18554.6, -802.7) + ctx.lineTo(18214.7, -1004.1) + ctx.fill() + + ctx.beginPath() + ctx.moveTo(17585.2, -1123.8) + ctx.lineTo(17151.2, -781.7) + ctx.lineTo(17151.2, -741.7) + ctx.lineTo(17625.2, -1123.8) + ctx.fill() + + + ctx.fillRect(20540, -1103, 610, 300) + ctx.fillRect(20820, -243, 410, 300) + ctx.fillRect(5772, -609, 469, 700) + ctx.fillRect(5772, -609, 469, 700) + + ctx.fillStyle = "rgba(48,184,140,255)" + ctx.fillRect(waterFallX, -960, waterFallWidth, 6000) + ctx.fillStyle = `hsla(160, 100%, 43%,${0.3 + 0.07 * Math.random()})` + ctx.fillRect(waterFallX + waterFallWidth * Math.random(), -900 - Math.random() * 400, Math.random() * 5 + 8, 6000) + ctx.fillRect(waterFallX + waterFallWidth * Math.random(), -900 - Math.random() * 400, Math.random() * 5 + 5, 6000) + waterFallWidth = 0.995 * waterFallWidth + 4 * Math.random()//4.7 + waterFalSmoothlX = 0.96 * waterFallSmoothX + 20 * Math.random()//3.5 + waterFallX = waterFallSmoothX + 15900 + + + ctx.fillStyle = "rgba(0,0,0,0.4)"//wires + ctx.fillRect(20990, -2672, 20, 112) + ctx.fillRect(21090, -2506, 72, 20) + ctx.fillRect(21090, -1970, 72, 20) + + + + ctx.fillRect(16901.8, -2497.7, 25, 100) + ctx.fillRect(16901.8, -2397.7, 50, 25) + ctx.fillRect(16951.8, -2397.7, 25, 1640) + ctx.fillRect(16901.8, -782.7, 50, 25) + ctx.fillRect(16901.8, -757.7, 25, 100) + + + ctx.fillRect(20900, -2666, 500, 9) + ctx.fillRect(20900, -2651, 1315, 9) + ctx.fillRect(20900, -2636, 1300, 9) + ctx.fillRect(20900, -2621, 245, 9) + ctx.fillRect(20900, -2606, 230, 9) + ctx.fillRect(20900, -2591, 215, 9) + ctx.fillRect(20900, -2576, 200, 9) + + ctx.fillRect(21145, -2621, 9, 700) + ctx.fillRect(21130, -2606, 9, 1000) + ctx.fillRect(21115, -2591, 9, 1000) + ctx.fillRect(21100, -2576, 9, 850) + + ctx.fillRect(21400, -3066, 9, 409) + + + ctx.fillRect(20900, -1726, 209, 9) + ctx.fillRect(21145, -1921, 270, 9) + ctx.fillRect(21415, -1921, 9, 50) + + ctx.fillRect(22200, -2636, 9, 1300) + ctx.fillRect(22215, -2651, 9, 300) + + ctx.fillRect(22200, -1336, 300, 9) + ctx.fillRect(22215, -2351, 300, 9) + + + //943.9, -1698.0 + + ctx.fillRect(916.5, -1725, 80, 80)//+55 // 55/2=27.5 + ctx.fillRect(1204, -1706, 25, 40)//179 + ctx.fillRect(1354, -1706, 25, 40) + ctx.fillRect(1504, -1885, 25, 40) + ctx.fillRect(3504, -1885, 25, 40) + ctx.fillRect(5504, -1885, 25, 40) + + + ctx.fillRect(1019, -1718, 9, 20) + ctx.fillRect(1019, -1674, 9, 20) + + ctx.fillRect(996, -1718, 23, 9) + ctx.fillRect(996, -1663, 23, 9) + + + + + ctx.fillRect(1019, -1698, 425, 9) + ctx.fillRect(1444, -1868, 9, 179) + ctx.fillRect(1444, -1877, 4700, 9) + + ctx.fillRect(1019, -1683, 440, 9) + ctx.fillRect(1459, -1853, 9, 179) + ctx.fillRect(1459, -1862, 4670, 9) + + ctx.fillRect(6144, -1877, 9, 100) + ctx.fillRect(6144, -1777, 100, 9) + + ctx.fillRect(6129, -1862, 9, 1100) + ctx.fillRect(6129, -762, 150, 9) + + + + + + + + }; + + + level.customTopLayer = () => { + + + + door.draw(); + door2.draw(); + door3.draw(); + + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + elevator.move() + + + // if (player.position.x > 15900 && player.position.x < 16300 && player.position.y > -1360.2) { + // Matter.Body.setVelocity(player, { + // x: player.velocity.x, + // y: player.velocity.y + 10 + // }); + // }else{ + // if (Math.abs(player.velocity.x) > 0.5){ + // if (m.onGround){ + // Matter.Body.setVelocity(player, { + // x: player.velocity.x + (0.07 * (Math.abs(player.velocity.x) / player.velocity.x)), + // y: player.velocity.y - 0.2 + + // }); + // }else{ + // Matter.Body.setVelocity(player, { + // x: player.velocity.x, + // y: player.velocity.y - 0.2 + // }); + // } + // }else{ + // Matter.Body.setVelocity(player, { + // x: player.velocity.x, + // y: player.velocity.y - 0.2 + // }); + // } + // } + + if (player.position.x > 15900 && player.position.x < 16300 && player.position.y > -1360.2) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y + 2 + }); + } else { + if (Math.abs(player.velocity.x) > 0.5) { + if (m.onGround) { + Matter.Body.setVelocity(player, { + x: player.velocity.x + (0.07 * (Math.abs(player.velocity.x) / player.velocity.x)), + y: player.velocity.y - 0.2 + + }); + } else { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y - 0.2 + }); + } + } else { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y - 0.2 + }); + } + } + hazard2.opticalQuery(); + + + }; + + + + + + //1273.2, -1404.7 + + spawn.mapRect(1124, -653, 100, 25); + spawn.mapRect(906, -1390, 100, 25); + spawn.mapRect(3330, -1930, 100, 25); + + + //first ship base + spawn.mapRect(-300, 0, 6684, 100);//lower floor + spawn.mapRect(-300, -2071, 154, 2071);//left right wall + spawn.mapRect(2511, -300, 1309, 308);//left big block + spawn.mapRect(3820, -184, 1309, 184);//right big block + spawn.mapRect(-300, -739, 2549, 100);//upper right floor + spawn.mapRect(2056, -1309, 2764, 169);//upper center floor + spawn.mapRect(2056, -1309, 193, 650);//upper left floor wall + spawn.mapRect(4636, -1309, 193, 793);//upper right floor wall + spawn.mapRect(4821, -654, 955, 138);//upper right floor + spawn.mapRect(6237, -2071, 147, 2071);//far right wall + spawn.mapRect(-300, -2071, 6684, 154);//roof + + //first ship details + spawn.mapRect(245, -360, 70, 400);//start room wall + spawn.mapRect(500, -1929, 154, 462); + spawn.mapRect(185, -1517, 469, 77); + spawn.mapRect(2773, -682, 469, 77);//walls in 1st room + spawn.mapRect(3743, -566, 77, 469); + spawn.mapRect(3947, -851, 469, 77); + spawn.mapRect(5313, -1309, 1000, 70);//walls in second area + spawn.mapRect(4818, -1006, 400, 70); + spawn.mapRect(4768, -1626, 800, 70); + spawn.mapRect(4760, -1626, 70, 400); + spawn.mapRect(645.1, -1480.8, 700, 100);//room for shielding boss + spawn.mapVertex(515, -1447, "0 0 0 100 -400 0"); + spawn.mapRect(1245.1, -1980.8, 100, 500); + spawn.mapRect(2346.9, -1658.8, 469, 77); + spawn.mapRect(4023.6, -1723.7, 469, 77); + + //engines //y -2972 -> 0 + spawn.mapRect(6237, -1880.7, 400, 800); + spawn.mapRect(6237, -890.4, 400, 800); + + + //first ship blocks/debris + spawn.debris(3267.6, -797.1, 700, 5); //16 debris per level + spawn.debris(1626.0, -372.5, 1700, 8); //16 debris per level + spawn.debris(1880.1, -1508.9, 3700, 16); //16 debris per level + spawn.debris(5335.3, -1431.6, 3700, 16); //16 debris per level + spawn.debris(1563.8, -1087.9, 700, 5); //16 debris per level + spawn.bodyRect(1540, -1110, 218, 125, 0.9); + + + + //first ship mobs + spawn.randomSmallMob(893.5, -120.8); + + // spawn.randomMob(2903.9, -754.5, 0.4); + // spawn.randomMob(5577.0, -217.0, 0.2); + // spawn.randomMob(765.8, -1029.7, 0.5); + // spawn.randomMob(2680.1, -1779.2, 0.6); + // spawn.randomMob(20079.4, -2219.7, 0.4); + // spawn.randomMob(3924.9, -1504.1, 0.5); + // spawn.randomMob(21284.2, -983.1, 0.3); + // spawn.randomMob(20381.0, -254.2, 0.5); + // spawn.randomMob(18375.6, -1574.4, 0.6); + // spawn.randomMob(19448.2, -1323.3, 0.3); + // spawn.randomMob(18397.7, -711.2, 0.3); + // spawn.randomMob(15547.2, -2249.6, 0.5); + // spawn.randomSmallMob(16114.6, -2524.2); + // spawn.randomSmallMob(15378.9, -2549.6); + + // spawn.randomSmallMob(3266.4, -1578.4); + // spawn.randomSmallMob(4386.2, -439.6); + // spawn.randomSmallMob(5667.0, -847.8); + // spawn.randomSmallMob(3158.5, -1581.8); + // spawn.randomSmallMob(3866.7, -1483.2); + // spawn.randomSmallMob(4652.3, -1729.4); + // spawn.randomSmallMob(1068.7, -106.1); + // spawn.randomSmallMob(3382.5, -1590.6);//3545.0, -413.0 + // spawn.randomSmallMob(5099.7, -1204.2); + // spawn.randomSmallMob(1456.4, -1014.8); + // spawn.randomSmallMob(20432.4, -1374.3); + // spawn.randomSmallMob(20381.0, -254.2); + // spawn.randomSmallMob(3505.1, -1531.1); + // spawn.randomSmallMob(20648.1, -136.8); + // spawn.randomSmallMob(17502.8, -1520.6); + // spawn.randomSmallMob(17438.7, -876.7); + + spawn.randomMob(18375.6, -1574.4, 0.2); + spawn.randomSmallMob(15378.9, -2549.6); + spawn.randomSmallMob(5820.2, -1545.2); + spawn.randomMob(765.8, -1029.7, 0.2); + spawn.randomMob(21284.2, -983.1, 0.3); + spawn.randomSmallMob(3382.5, -1590.6); + spawn.randomSmallMob(3545.0, -413.0); + spawn.randomMob(20381.0, -254.2, 0.6); + spawn.randomSmallMob(20432.4, -1374.3); + spawn.randomSmallMob(5667.0, -847.8); + spawn.randomMob(2903.9, -754.5, 0.2); + spawn.randomSmallMob(3266.4, -1578.4); + spawn.randomSmallMob(20648.1, -136.8); + spawn.randomSmallMob(16114.6, -2524.2); + spawn.randomSmallMob(20381.0, -254.2); + spawn.randomMob(5577.0, -217.0, 0.3); + spawn.randomSmallMob(1456.4, -1014.8); + spawn.randomSmallMob(1068.7, -106.1); + spawn.randomSmallMob(5099.7, -1204.2); + spawn.randomSmallMob(17502.8, -1520.6); + spawn.randomMob(15547.2, -2249.6, 0.2); + spawn.randomMob(19448.2, -1323.3, 0.7); + spawn.randomSmallMob(3158.5, -1581.8); + spawn.randomSmallMob(17438.7, -876.7); + spawn.randomMob(20079.4, -2219.7, 0.2); + spawn.randomMob(2680.1, -1779.2, 0.6); + spawn.randomMob(3924.9, -1504.1, 0.3); + spawn.randomSmallMob(4652.3, -1729.4); + spawn.randomMob(18397.7, -711.2, 0.3); + spawn.randomSmallMob(4386.2, -439.6); + + spawn.randomSmallMob(3505.1, -1531.1); + spawn.randomSmallMob(3866.7, -1483.2); + + + + + //second ship mobs + spawn.debris(17732.3, -550.0, 700, 5); //16 debris per level + spawn.debris(17827.2, -2357.1, 700, 5); //16 debris per level + spawn.debris(16108.6, -2621.1, 700, 5); //16 debris per level + spawn.debris(20823.6, -1332.1, 1300, 5); //16 debris per level + spawn.debris(21095.5, -423.4, 700, 5); //16 debris per level + spawn.debris(20534.5, -1282.1, 700, 5); //16 debris per level + + + + + + + + spawn.randomSmallMob(1300, -70); + spawn.shieldingBoss(943.9, -1698.0) + + + //second ship base + spawn.mapRect(15000, 0, 515, 185);//lower floor 1 + spawn.mapRect(17015, 0, 5500, 185);//lower floor 2 + spawn.mapRect(15000, -2972, 185, 2972);//left wall + spawn.mapRect(15000, -2972, 7515, 185);//roof + spawn.mapRect(22330, -2972, 185, 2972);//right wall + spawn.mapRect(17002, -2972, 169, 2564);//left middle wall + spawn.mapRect(19089, -2972, 169, 855);//right middle wall upper + spawn.mapRect(19089, -1625, 169, 1800);//right middle wall lower + spawn.mapRect(20760, -2972, 169, 1350);//medium wall left of portal + spawn.mapRect(19720, -1625, 1725, 162);//right room upper floor + spawn.mapRect(21440, -2325, 169, 863);//medium wall right of portal + spawn.mapRect(19720, -855, 2725, 162);//right room lower floor + + //engines //y -2972 -> 0 + spawn.mapRect(22330, -2763.75, 400, 800); + spawn.mapRect(22330, -1793.5, 400, 800); + spawn.mapRect(22330, -804.25, 400, 800); + + + + //second ship details + spawn.mapRect(19904, -1465, 85, 362);//upper L + spawn.mapRect(19542, -1191, 412, 88);//lower L + spawn.mapRect(18546, -2199, 600, 82);//2nd room enternce wall + spawn.mapRect(18546, -2499, 82, 2300); + spawn.mapRect(18108, -326, 500, 82);//walls/floors in middle room + spawn.mapRect(17750, -682, 300, 82); + spawn.mapRect(17156, -468, 500, 60); + spawn.mapRect(18022, -1082, 600, 82); + spawn.mapRect(17151, -1196, 500, 82); + spawn.mapRect(17453, -2060, 500, 82); + spawn.mapRect(18197, -2269, 400, 82); + spawn.mapRect(18108, -326, 500, 82); + spawn.mapRect(20542, -1191, 612, 88); + spawn.mapRect(20238, -1191, 88, 412); + spawn.mapRect(21520, -1468, 88, 412); + spawn.mapRect(20238, -330.2, 88, 412); + spawn.mapRect(20819, -328.3, 412, 88); + spawn.mapRect(21532, -708, 88, 412); + spawn.mapRect(15483.8, 12.5, 388, 30);//broken floor + spawn.mapRect(15487.6, 76.6, 488, 24); + spawn.mapRect(15506.5, 134.2, 288, 45); + spawn.mapVertex(16758.6, 135.3, "400 -30 -350 -40 -400 30 400 30"); + spawn.mapVertex(16758.6, 55.3, "423 -30 -408 -20 -400 20 400 20"); + //tank + spawn.mapRect(15310, -960, 600, 135); + spawn.mapRect(16290, -960, 800, 135); + //in tank + spawn.mapRect(16524.8, -2726.8, 40, 400); + spawn.mapRect(16524.8, -2130.9, 400, 40); + spawn.mapRect(16010.2, -2412.2, 300, 40); + spawn.mapRect(15379.2, -2055.1, 400, 40); + + spawn.mapVertex(17626.3, -3035, "-245 0 -220 -110 -173 -173 -110 -220 0 -250 110 -220 173 -173 220 -110 245 0"); + spawn.mapRect(17226.3, -3035, 400, 40); + + spawn.mapVertex(17626.3, 225, "-245 0 -220 110 -173 173 -110 220 0 250 110 220 173 173 220 110 245 0"); + spawn.mapRect(17226.3, 225, 400, 40); + + spawn.mapVertex(19626.3, -3035, "-245 0 -220 -110 -173 -173 -110 -220 0 -250 110 -220 173 -173 220 -110 245 0"); + spawn.mapRect(19226.3, -3035, 400, 40); + + spawn.mapVertex(19626.3, 225, "-245 0 -220 110 -173 173 -110 220 0 250 110 220 173 173 220 110 245 0"); + spawn.mapRect(19226.3, 225, 400, 40); + + spawn.mapVertex(21626.3, -3035, "-245 0 -220 -110 -173 -173 -110 -220 0 -250 110 -220 173 -173 220 -110 245 0"); + spawn.mapRect(21226.3, -3035, 400, 40); + + spawn.mapVertex(21626.3, 225, "-245 0 -220 110 -173 173 -110 220 0 250 110 220 173 173 220 110 245 0"); + spawn.mapRect(21226.3, 225, 400, 40); + + + + //add fuel tanks in the last room + + + spawn.mapRect(21531.9, -707.8, 488, 8); + + //22185.5, -114.8 + spawn.mapVertex(22207.8, -103, "325 -200 100 -200 325 -300"); + spawn.mapRect(22056.6, -70, 225, 212); + + spawn.mapVertex(20723.1, -1734, "325 -200 100 -200 325 -300"); + spawn.mapRect(20571.9, -1701.0, 225, 212); + + spawn.mapVertex(22207.8, -103, "325 -200 100 -200 325 -300"); + spawn.mapRect(22056.6, -70, 225, 212); + //spawn.mapVertex(x,y, "coordinates") + //the parts in quotes is "x y x y x y x y x y" x and y need to be the coordinates of points that define the shape in a concave clockwise direction + + //second ship blocks/debris + spawn.bodyRect(21525, -113, 50, 50, 9);//first button block + spawn.bodyRect(18993, -2283, 50, 50, 9);//second button block + spawn.bodyRect(20303, -1736, 50, 50, 9);//third button block + + + + // spawn.randomLevelBoss(17902, -1689, ["blinkBoss", "shooterBoss", "launcherBoss", "pulsarBoss", "blockBoss", "bladeBoss", "revolutionBoss", "spawnerBossCulture", "spiderBoss", "sneakBoss", "snakeSpitBoss"]) + spawn.randomLevelBoss(17902, -1689, ["launcherBoss", "laserTargetingBoss", "blinkBoss", "streamBoss", "historyBoss", "grenadierBoss", "blockBoss", "revolutionBoss", "slashBoss"]); + + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + // spawn.bodyRect(1540, -1110, 300, 25, 0.9); + // spawn.randomSmallMob(1300, -70); + // spawn.randomMob(2650, -975, 0.8); + // spawn.randomGroup(1700, -900, 0.4); + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + // spawn.secondaryBossChance(100, -1500) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + clock() { + simulation.inGameConsole(`clock by Cornbread 2100`); + + function drawBackgroundGear(x, y, r1, r2, rot, color, speed, numTeeth = 5, toothWidth = 75, linew = 2) { + var vertices = getGearVertices(x, y, r1, r2, numTeeth, simulation.cycle * speed + rot, toothWidth / 100); + + // draw gear + ctx.beginPath(); + ctx.moveTo(vertices[0].x, vertices[0].y); + for (var i = 1; i < vertices.length; i++) { + ctx.lineTo(vertices[i].x, vertices[i].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 2; + ctx.fillStyle = color; + ctx.fill(); + ctx.strokeStyle = "#3a3f20"; + ctx.lineWidth = linew; + ctx.stroke(); + } + + function drawFallingBackgroundGear(x, y, r1, r2, rot, color, speed, fallSpeed, startCycle, numTeeth = 5, linew = 2) { + rot *= speed; + numTeeth *= 2; + + const gearInc = (2 * Math.PI) / numTeeth; + ctx.beginPath() + for (var i = 0; i <= numTeeth; i++) { + var gear_r = r2; + if (i % 2 == 1) gear_r = r1; + ctx.arc(x, y + (simulation.cycle - startCycle) * fallSpeed, gear_r, (i * gearInc) + rot, ((i + 1) * gearInc) + rot); + } + ctx.fillStyle = color; + ctx.fill(); + ctx.strokeStyle = "#3a3f20"; + ctx.lineWidth = linew; + ctx.stroke(); + } + + function getGearVertices(x, y, r1, r2, numTeeth, rot = 0, teethWidth = 0) { + if (teethWidth == 0) { + teethWidth = (2 * Math.PI) / (2 * numTeeth); + } + const gearInc = (2 * Math.PI) / numTeeth; + var vertices = []; + + for (var i = 0; i < numTeeth; i++) { + //inner vertices of gear teeth + var distance = i * gearInc + rot; + var vX = Math.sin(distance + teethWidth / 2) * r1; + var vY = Math.cos(distance + teethWidth / 2) * r1; + + var point1 = { x: vX, y: vY, point: 1 }; + + vX = Math.sin(distance - teethWidth / 2) * r1; + vY = Math.cos(distance - teethWidth / 2) * r1; + + var point4 = { x: vX, y: vY, point: 4 }; + + vX = Math.sin(distance) * r1; + vY = Math.cos(distance) * r1; + + if (vX == 0) { + vX = 0.0001 + } + + var slope = vY / vX; + + var angle = Math.atan2(vY, vX); + + //outer vertices of gear teeth + var point2 = { x: point1.x, y: point1.y, point: 2 }; + point2.x += Math.cos(angle) * (r2 - r1); + point2.y += Math.sin(angle) * (r2 - r1); + + var point3 = { x: point4.x, y: point4.y, point: 3 }; + point3.x += Math.cos(angle) * (r2 - r1); + point3.y += Math.sin(angle) * (r2 - r1); + + vertices.push(point4); + vertices.push(point3); + vertices.push(point2); + vertices.push(point1); + } + + for (var i = 0; i < vertices.length; i++) { + vertices[i].x += x; + vertices[i].y += y; + } + + return vertices; + } + + function getGearTeethVertices(x, y, r1, r2, numTeeth, toothIndex, teethWidth = 0) { + if (teethWidth == 0) { + teethWidth = (2 * Math.PI) / (2 * numTeeth); + } + + const gearInc = (2 * Math.PI) / numTeeth; + var vertices = []; + + for (var i = 0; i < numTeeth; i++) { + //inner vertices of gear teeth + var distance = i * gearInc; + var vX = Math.sin(distance + teethWidth / 2) * r1; + var vY = Math.cos(distance + teethWidth / 2) * r1; + + var point1 = { x: vX, y: vY, point: 1 }; + + vX = Math.sin(distance - teethWidth / 2) * r1; + vY = Math.cos(distance - teethWidth / 2) * r1; + + var point4 = { x: vX, y: vY, point: 4 }; + + vX = Math.sin(distance) * r1; + vY = Math.cos(distance) * r1; + + if (vX == 0) { + vX = 0.0001 + } + + var slope = vY / vX; + + var angle = Math.atan2(vY, vX); + + //outer vertices of gear teeth + var point2 = { x: point1.x, y: point1.y, point: 2 }; + point2.x += Math.cos(angle) * (r2 - r1); + point2.y += Math.sin(angle) * (r2 - r1); + + var point3 = { x: point4.x, y: point4.y, point: 3 }; + point3.x += Math.cos(angle) * (r2 - r1); + point3.y += Math.sin(angle) * (r2 - r1); + + if (i == toothIndex) { + vertices.push(point4); + vertices.push(point3); + vertices.push(point2); + vertices.push(point1); + } + } + + for (var i = 0; i < vertices.length; i++) { + vertices[i].x += x; + vertices[i].y += y; + } + + return vertices; + } + + function mapGear(x, y, r1, r2, rot, speed, numTeeth = 5, toothWidth = 50, additionalCircleRadius = 10) { + const part1 = body[body.length] = Bodies.polygon(x, y, 0, r1 + additionalCircleRadius, { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + isNotHoldable: true, + frictionAir: 0, + friction: 1, + frictionStatic: 1, + restitution: 0 + }); + + var parts = [part1]; + + for (var i = 0; i < numTeeth; i++) { + var toothVertices = getGearTeethVertices(0, 0, r2 - r1, toothWidth + r2 - r1, numTeeth, i, 70); // for some reason the teeth are sideways + + var center = { // the center of the inner line of the gear + x: toothVertices[3].x - toothVertices[0].x, + y: toothVertices[3].y - toothVertices[0].y + }; + + distanceToCenter = Math.sqrt((center.x ** 2) + (center.y ** 2)); + + var radiusScale = (r1 + ((r2 - r1) / 2)) / distanceToCenter; + + gearToothSlope = center.y / center.x; + + var newPart = body[body.length] = Bodies.fromVertices(x + center.x * radiusScale, y + center.y * radiusScale, toothVertices, { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + isNotHoldable: true, + frictionAir: 0.01, + friction: 1, + frictionStatic: 1, + restitution: 0 + }); + + parts.push(newPart); + } + + const who = Body.create({ + parts: parts + }); + + Composite.add(engine.world, who); + composite[composite.length] = who; + who.collisionFilter.category = cat.body; + who.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mob | cat.mobBullet | cat.map + + const constraint = Constraint.create({ + pointA: { + x: x, + y: y + }, + bodyB: who, + stiffness: 1, + damping: 1 + }); + + + Matter.Body.setDensity(who, 0.0001) + Composite.add(engine.world, constraint); + Matter.Body.setAngle(who, 0) + Matter.Body.setAngularVelocity(who, 0); + who.center = { x: x, y: y } + + who.rotate = function () { + var rotation = simulation.cycle * speed + rot; + Matter.Body.setAngle(who, rotation); + } + + who.gearSettings = { + x: x, + y: y, + r1: r1, + r2: r2, + rot: rot, + speed: speed, + numTeeth: numTeeth, + toothWidth: toothWidth + } + + return who; + } + + function clockHand(x, y, width, height, speed = 15 * Math.PI / 180, angle = 0, density = 0.001) { + var who1 = body[body.length] = Bodies.rectangle(x, y + height / 2, width, height, { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + isNotHoldable: true, + friction: 1, + frictionStatic: 1, + restitution: 0 + }); + + const who = Body.create({ + parts: [who1], + handRotation: 0 + }); + + Composite.add(engine.world, who); + composite[composite.length] = who; + who.collisionFilter.category = cat.body; + who.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mob | cat.mobBullet | cat.map + + who.position.y = y; + + const constraint = Constraint.create({ + pointA: { + x: who.position.x, + y: who.position.y + }, + bodyB: who, + stiffness: 1, + damping: 1 + }); + + Matter.Body.setDensity(who, density) + Composite.add(engine.world, constraint); + who.center = { x: who.position.x, y: who.position.y } + + who.rotate = function () { + if (simulation.cycle % 60 == 0) { + who.handRotation += speed; + if (Math.abs(who.handRotation % (Math.PI * 2) - Math.PI) < 0.2) { + // spawn random mob at exit door + const pick = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]; + spawn[pick](300, 600); + } + if (Matter.Query.collides(player, [this]).length != 0) { + var playerAngle = Math.atan((m.pos.y - y) / (m.pos.x - x)); + if (m.pos.x - x < 0) playerAngle += Math.PI; + const playerDistance = Math.sqrt((m.pos.x - x) ** 2 + (m.pos.y - y) ** 2); + Matter.Body.setPosition(player, { + x: x + Math.cos(playerAngle + speed) * playerDistance, + y: y + Math.sin(playerAngle + speed) * playerDistance + }) + } + } + Matter.Body.setAngle(who, who.handRotation + angle); + } + + return who + } + + function pendulum(x, y, width, height, swingTime = 50, swingDistanceMultiplier = 0.5, bobSides = 0, bobRadius = 200, density = 100, angle = 0, frictionAir = 0, angularVelocity = 0) { + const who1 = body[body.length] = Bodies.rectangle(x, y + height / 2, width, height, { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + isNotHoldable: true, + frictionAir: frictionAir, + friction: 1, + frictionStatic: 1, + restitution: 0 + }); + + const who2 = body[body.length] = Bodies.polygon(x, y + height, bobSides, bobRadius, { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + isNotHoldable: true, + frictionAir: 0.01, + friction: 1, + frictionStatic: 1, + restitution: 0 + }); + + const who = Body.create({ + parts: [who1, who2], + }); + + Composite.add(engine.world, who); + composite[composite.length] = who; + who.collisionFilter.category = cat.body; + who.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mob | cat.mobBullet | cat.map + + who.position.y = y; + + const constraint = Constraint.create({ + pointA: { + x: x, + y: y + }, + bodyB: who, + stiffness: 1, + damping: 1 + }); + + + Matter.Body.setDensity(who, density) + Composite.add(engine.world, constraint); + Matter.Body.setAngle(who, angle) + Matter.Body.setAngularVelocity(who, angularVelocity); + who.center = { x: x, y: y + height / 2 } + + who.rotate = function () { + var rotation = Math.sin(simulation.cycle / swingTime) * swingDistanceMultiplier; + + if (Matter.Query.collides(player, [this]).length != 0) { + var playerAngle = Math.atan((player.position.y - y) / (player.position.x - x)) + rotation - Math.sin((simulation.cycle - 1) / swingTime) * swingDistanceMultiplier; + if (player.position.x - x < 0) playerAngle += Math.PI; + const playerDistance = Math.sqrt((player.position.x - x) ** 2 + (player.position.y - y) ** 2); + Matter.Body.setPosition(player, { + x: x + Math.cos(playerAngle) * playerDistance, + y: y + Math.sin(playerAngle) * playerDistance + }) + } + + Matter.Body.setAngle(who, rotation); + } + + return who; + } + + function gearMob(x, y, leaveBody = true, autoFindPlayer = false, radius = Math.floor(25 + 40 * Math.random()), teethRadius = 0) { + if (teethRadius == 0) { + teethRadius = radius + 15 + Math.floor(Math.random() * 20); + } + + mobs.spawn(x, y, 0, teethRadius, "transparent"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + + me.delay = 100 + 40 * simulation.CDScale; + me.accelMag = Math.PI / 10000; + me.memory = 120; + me.seeAtDistance2 = 2000000; // 140 + Matter.Body.setDensity(me, 0.001); + + me.leaveBody = leaveBody; + + const numTeeth = Math.round(5 + Math.random() * 3); + + me.gearRotation = 0; + me.gearSpeed = Math.round(-0.1 + Math.random() * 0.2); + me.gearAccelerating = true; + + me.do = function () { + if (autoFindPlayer) { + me.locatePlayer(); + } + + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + + if (me.gearAccelerating && (Math.random() > 0.99 || me.gearSpeed >= 0.1)) { + me.gearAccelerating = false; + } else if (!me.gearAccelerating && (Math.random() > 0.99 || me.gearSpeed <= -0.1)) { + me.gearAccelerating = true; + } + + if (me.gearAccelerating) { + me.gearSpeed += 0.001; + } else { + me.gearSpeed -= 0.001; + } + + me.gearRotation += me.gearSpeed; + + var newVertices = getGearVertices(me.position.x, me.position.y, radius, teethRadius, numTeeth, me.gearRotation); + // draw body + ctx.beginPath(); + ctx.moveTo(newVertices[0].x, newVertices[0].y); + for (let i = 1; i < newVertices.length; i++) { + ctx.lineTo(newVertices[i].x, newVertices[i].y); + } + ctx.lineTo(newVertices[0].x, newVertices[0].y); + ctx.fillStyle = "#7b3f00"; + ctx.fill(); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 2; + ctx.stroke(); + } + } + + function customDoor(x, y, width, height) { + x = x + width / 2 + y = y + height / 2 + const doorBlock = body[body.length] = Bodies.rectangle(x, y, width, height, { + collisionFilter: { + category: cat.map, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 1, + frictionStatic: 1, + restitution: 0, + isClosing: false, + setPos(x, y) { + if (y - this.position.y <= 0 || ( // only move down if clear of stuff + Matter.Query.ray([player], Matter.Vector.create(this.position.x - width / 2, this.position.y + height / 2), Matter.Vector.create(this.position.x + width / 2, this.position.y + height / 2), 5).length === 0 && + Matter.Query.ray(body, Matter.Vector.create(this.position.x - width / 2, this.position.y + height / 2), Matter.Vector.create(this.position.x + width / 2, this.position.y + height / 2), 5).length <= 1 && + Matter.Query.ray(mob, Matter.Vector.create(this.position.x - width / 2, this.position.y + height / 2), Matter.Vector.create(this.position.x + width / 2, this.position.y + height / 2), 5).length === 0) + ) { + const position = { + x: x, + y: y + } + Matter.Body.setPosition(this, position); + } + }, + draw() { + ctx.fillStyle = "#555" + ctx.beginPath(); + const v = this.vertices; + ctx.moveTo(v[0].x, v[0].y); + for (let i = 1; i < v.length; ++i) { + ctx.lineTo(v[i].x, v[i].y); + } + ctx.lineTo(v[0].x, v[0].y); + ctx.fill(); + } + }); + Matter.Body.setStatic(doorBlock, true); //make static + Composite.add(engine.world, doorBlock); //add to world + doorBlock.classType = "body" + return doorBlock + } + + function horizontalDoor(x, y, width, height, distance, speed = 1) { + x = x + width / 2 + y = y + height / 2 + const doorBlock = body[body.length] = Bodies.rectangle(x, y, width, height, { + collisionFilter: { + category: cat.map, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 1, + frictionStatic: 1, + restitution: 0, + isClosing: false, + openClose() { + if (!m.isTimeDilated) { + if (this.isClosing) { + if (this.position.x > x) { //try to close + if ( //if clear of stuff + Matter.Query.collides(this, [player]).length === 0 && + Matter.Query.collides(this, body).length < 2 && + Matter.Query.collides(this, mob).length === 0 + ) { + const position = { + x: this.position.x - speed, + y: this.position.y + } + Matter.Body.setPosition(this, position) + } + } + } else { + if (this.position.x < x + distance) { //try to open + const position = { + x: this.position.x + speed, + y: this.position.y + } + Matter.Body.setPosition(this, position) + } + } + } + }, + isClosed() { + return this.position.x < x + 1 + }, + draw() { + ctx.fillStyle = "#555" + ctx.beginPath(); + const v = this.vertices; + ctx.moveTo(v[0].x, v[0].y); + for (let i = 1; i < v.length; ++i) { + ctx.lineTo(v[i].x, v[i].y); + } + ctx.lineTo(v[0].x, v[0].y); + ctx.fill(); + } + }); + Matter.Body.setStatic(doorBlock, true); //make static + Composite.add(engine.world, doorBlock); //add to world + doorBlock.classType = "body" + return doorBlock + } + + function drawBelt(circle1, circle2) { + // circle 1 + const distance = Math.sqrt((circle2.x - circle1.x) ** 2 + (circle2.y - circle1.y) ** 2); + const distanceToIntersection = (-circle1.radius * distance) / (-circle1.radius + circle2.radius); + const slopeAngle = Math.atan((circle2.y - circle1.y) / (circle2.x - circle1.x)); + const angleToTangent = Math.acos(-circle1.radius / distanceToIntersection); + const tangentIntersection = { + x: Math.cos(slopeAngle) * distanceToIntersection + circle1.x, + y: Math.sin(slopeAngle) * distanceToIntersection + circle1.y + } + const tangentPoint = { + x: Math.cos(angleToTangent + slopeAngle) * -circle1.radius + circle1.x, + y: Math.sin(angleToTangent + slopeAngle) * -circle1.radius + circle1.y + } + const invertedTangentPoint = { + x: Math.cos(-angleToTangent + slopeAngle) * -circle1.radius + circle1.x, + y: Math.sin(-angleToTangent + slopeAngle) * -circle1.radius + circle1.y + } + + // circle 2 + const tangentPoint2 = { + x: Math.cos(angleToTangent + slopeAngle) * -circle2.radius + circle2.x, + y: Math.sin(angleToTangent + slopeAngle) * -circle2.radius + circle2.y + } + const invertedTangentPoint2 = { + x: Math.cos(-angleToTangent + slopeAngle) * -circle2.radius + circle2.x, + y: Math.sin(-angleToTangent + slopeAngle) * -circle2.radius + circle2.y + } + + // draw + ctx.beginPath(); + ctx.moveTo(tangentPoint.x, tangentPoint.y); + ctx.lineTo(tangentPoint2.x, tangentPoint2.y); + const newAngle = Math.atan((tangentPoint2.y - circle2.y) / (tangentPoint2.x - circle2.x)); + const newAngle2 = Math.atan((invertedTangentPoint2.y - circle2.y) / (invertedTangentPoint2.x - circle2.x)); + ctx.arc(circle2.x, circle2.y, circle2.radius, newAngle, newAngle2 + Math.PI); + ctx.lineTo(invertedTangentPoint.x, invertedTangentPoint.y); + const newAngle3 = Math.atan((invertedTangentPoint.y - circle1.y) / (invertedTangentPoint.x - circle1.x)); + const newAngle4 = Math.atan((tangentPoint.y - circle1.y) / (tangentPoint.x - circle1.x)); + ctx.arc(circle1.x, circle1.y, circle1.radius, newAngle3 + Math.PI, newAngle4); + ctx.strokeStyle = '#000'; + ctx.lineWidth = 5; + ctx.stroke(); + } + + function drawDiagonalBelt(circle1, circle2) { + // circle 1 + const distance = Math.sqrt((circle2.x - circle1.x) ** 2 + (circle2.y - circle1.y) ** 2); + const distanceToIntersection = (circle1.radius * distance) / (circle1.radius + circle2.radius); + const slopeAngle = Math.atan((circle2.y - circle1.y) / (circle2.x - circle1.x)); + const angleToTangent = Math.acos(circle1.radius / distanceToIntersection); + const tangentIntersection = { + x: Math.cos(slopeAngle) * distanceToIntersection + circle1.x, + y: Math.sin(slopeAngle) * distanceToIntersection + circle1.y + } + const tangentPoint = { + x: Math.cos(angleToTangent + slopeAngle) * circle1.radius + circle1.x, + y: Math.sin(angleToTangent + slopeAngle) * circle1.radius + circle1.y + } + const invertedTangentPoint = { + x: Math.cos(-angleToTangent + slopeAngle) * circle1.radius + circle1.x, + y: Math.sin(-angleToTangent + slopeAngle) * circle1.radius + circle1.y + } + + // circle 2 + const tangentPoint2 = { + x: Math.cos(angleToTangent + slopeAngle) * -circle2.radius + circle2.x, + y: Math.sin(angleToTangent + slopeAngle) * -circle2.radius + circle2.y + } + const invertedTangentPoint2 = { + x: Math.cos(-angleToTangent + slopeAngle) * -circle2.radius + circle2.x, + y: Math.sin(-angleToTangent + slopeAngle) * -circle2.radius + circle2.y + } + + // draw + ctx.beginPath(); + ctx.moveTo(tangentPoint.x, tangentPoint.y); + ctx.lineTo(tangentPoint2.x, tangentPoint2.y); + const newAngle = Math.atan((tangentPoint2.y - circle2.y) / (tangentPoint2.x - circle2.x)); + const newAngle2 = Math.atan((invertedTangentPoint2.y - circle2.y) / (invertedTangentPoint2.x - circle2.x)); + ctx.arc(circle2.x, circle2.y, circle2.radius, newAngle, newAngle2 + Math.PI); + ctx.lineTo(invertedTangentPoint.x, invertedTangentPoint.y); + const newAngle3 = Math.atan((invertedTangentPoint.y - circle1.y) / (invertedTangentPoint.x - circle1.x)); + const newAngle4 = Math.atan((tangentPoint.y - circle1.y) / (tangentPoint.x - circle1.x)); + ctx.arc(circle1.x, circle1.y, circle1.radius, newAngle3, newAngle4 + Math.PI, true); + ctx.strokeStyle = '#000'; + ctx.lineWidth = 5; + ctx.stroke(); + } + + function getIntersection(v1, v1End, domain) { + const intersections = getIntersections(v1, v1End, domain); + + var best = { + x: v1End.x, + y: v1End.y, + dist: Math.sqrt((v1End.x - v1.x) ** 2 + (v1End.y - v1.y) ** 2) + } + for (const intersection of intersections) { + const dist = Math.sqrt((intersection.x - v1.x) ** 2 + (intersection.y - v1.y) ** 2); + if (dist < best.dist) { + best = { + x: intersection.x, + y: intersection.y, + dist: dist + }; + } + } + + return best; + } + + function getIntersections(v1, v1End, domain) { + const intersections = []; + + for (const obj of domain) { + for (var i = 0; i < obj.vertices.length - 1; i++) { + results = simulation.checkLineIntersection(v1, v1End, obj.vertices[i], obj.vertices[i + 1]); + if (results.onLine1 && results.onLine2) intersections.push({ x: results.x, y: results.y }); + } + results = simulation.checkLineIntersection(v1, v1End, obj.vertices[obj.vertices.length - 1], obj.vertices[0]); + if (results.onLine1 && results.onLine2) intersections.push({ x: results.x, y: results.y }); + } + + return intersections; + } + + function circleLoS(pos, radius, domain) { + + function allCircleLineCollisions(c, radius, domain) { + var lines = []; + for (const obj of domain) { + //const obj = domain[0] + for (var i = 0; i < obj.vertices.length - 1; i++) { + lines.push(circleLineCollisions(obj.vertices[i], obj.vertices[i + 1], c, radius)); + } + lines.push(circleLineCollisions(obj.vertices[obj.vertices.length - 1], obj.vertices[0], c, radius)); + } + + const collisionLines = []; + for (const line of lines) { + if (line.length == 2) { + const distance1 = Math.sqrt((line[0].x - c.x) ** 2 + (line[0].y - c.y) ** 2) + const angle1 = Math.atan2(line[0].y - c.y, line[0].x - c.x); + const queryPoint1 = { + x: Math.cos(angle1) * (distance1 - 1) + c.x, + y: Math.sin(angle1) * (distance1 - 1) + c.y + } + const distance2 = Math.sqrt((line[1].x - c.x) ** 2 + (line[1].y - c.y) ** 2) + const angle2 = Math.atan2(line[1].y - c.y, line[1].x - c.x); + const queryPoint2 = { + x: Math.cos(angle2) * (distance2 - 1) + c.x, + y: Math.sin(angle2) * (distance2 - 1) + c.y + } + + collisionLines.push(line) + } + } + + return collisionLines; + } + + function circleLineCollisions(a, b, c, radius) { + // calculate distances + const angleOffset = Math.atan2(b.y - a.y, b.x - a.x); + const sideB = Math.sqrt((a.x - c.x) ** 2 + (a.y - c.y) ** 2); + const sideC = Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); + const sideA = Math.sqrt((c.x - b.x) ** 2 + (c.y - b.y) ** 2); + + // calculate the closest point on line AB to point C + const angleA = Math.acos((sideB ** 2 + sideC ** 2 - sideA ** 2) / (2 * sideB * sideC)) * (a.x - c.x) / -Math.abs(a.x - c.x) + const sideAD = Math.cos(angleA) * sideB; + const d = { // closest point + x: Math.cos(angleOffset) * sideAD + a.x, + y: Math.sin(angleOffset) * sideAD + a.y + } + const distance = Math.sqrt((d.x - c.x) ** 2 + (d.y - c.y) ** 2); + if (distance == radius) { + // tangent + return [d]; + } else if (distance < radius) { + // secant + const angleOffset = Math.atan2(d.y - c.y, d.x - c.x); + const innerAngle = Math.acos(distance / radius); + const intersection1 = { + x: Math.cos(angleOffset + innerAngle) * radius + c.x, + y: Math.sin(angleOffset + innerAngle) * radius + c.y + } + + const intersection2 = { + x: Math.cos(angleOffset - innerAngle) * radius + c.x, + y: Math.sin(angleOffset - innerAngle) * radius + c.y + } + + const distance1 = { + a: Math.sqrt((intersection1.x - a.x) ** 2 + (intersection1.y - a.y) ** 2), + b: Math.sqrt((intersection1.x - b.x) ** 2 + (intersection1.y - b.y) ** 2) + } + const distance2 = { + a: Math.sqrt((intersection2.x - a.x) ** 2 + (intersection2.y - a.y) ** 2), + b: Math.sqrt((intersection2.x - b.x) ** 2 + (intersection2.y - b.y) ** 2) + } + const result = []; + if (Math.abs(sideC - (distance1.a + distance1.b)) < 0.01) { + result.push(intersection1); + } else { + if (distance1.a < distance1.b) { + if (sideB <= radius) result.push(a); + } else { + if (sideA <= radius) result.push(b) + } + } + if (Math.abs(sideC - (distance2.a + distance2.b)) < 0.01) { + result.push(intersection2); + } else { + if (distance2.a <= distance2.b) { + if (sideB <= radius) result.push(a); + } else { + if (sideA <= radius) result.push(b) + } + } + + return result; + } else { + // no intersection + return []; + } + } + + var vertices = []; + for (const obj of losDomain) { + for (var i = 0; i < obj.vertices.length; i++) { + const vertex = obj.vertices[i]; + const angleToVertex = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + const queryPoint = { + x: Math.cos(angleToVertex + Math.PI) + vertex.x, + y: Math.sin(angleToVertex + Math.PI) + vertex.y + } + + if (Matter.Query.ray(domain, pos, queryPoint).length == 0) { + var distance = Math.sqrt((vertex.x - pos.x) ** 2 + (vertex.y - pos.y) ** 2); + var endPoint = { + x: vertex.x, + y: vertex.y + } + + if (distance > radius) { + const angle = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + endPoint = { + x: Math.cos(angle) * radius + pos.x, + y: Math.sin(angle) * radius + pos.y + } + + distance = radius + } + + var best = getIntersection(pos, endPoint, domain); + + if (best.dist >= distance) { + best = { + x: endPoint.x, + y: endPoint.y, + dist: distance + } + } + vertices.push(best) + + + var angle = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + endPoint = { + x: Math.cos(angle + 0.001) * radius + pos.x, + y: Math.sin(angle + 0.001) * radius + pos.y + } + + best = getIntersection(pos, endPoint, domain); + + if (best.dist >= radius) { + best = { + x: endPoint.x, + y: endPoint.y, + dist: radius + } + } + vertices.push(best) + + + angle = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + endPoint = { + x: Math.cos(angle - 0.001) * radius + pos.x, + y: Math.sin(angle - 0.001) * radius + pos.y + } + + best = getIntersection(pos, endPoint, domain); + + if (best.dist >= radius) { + best = { + x: endPoint.x, + y: endPoint.y, + dist: radius + } + } + vertices.push(best) + } + } + } + + const outerCollisions = allCircleLineCollisions(pos, radius, domain); + const circleCollisions = []; + for (const line of outerCollisions) { + for (const vertex of line) { + const distance = Math.sqrt((vertex.x - pos.x) ** 2 + (vertex.y - pos.y) ** 2) + const angle = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + const queryPoint = { + x: Math.cos(angle) * (distance - 1) + pos.x, + y: Math.sin(angle) * (distance - 1) + pos.y + } + if (Math.abs(distance - radius) < 1 && Matter.Query.ray(domain, pos, queryPoint).length == 0) circleCollisions.push(vertex) + } + } + + for (var i = 0; i < circleCollisions.length; i++) { + const vertex = circleCollisions[i]; + var nextIndex = i + 1; + if (nextIndex == circleCollisions.length) nextIndex = 0; + const nextVertex = circleCollisions[nextIndex]; + const angle1 = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + const angle2 = Math.atan2(nextVertex.y - pos.y, nextVertex.x - pos.x); + var newAngle; + if (Math.abs(angle1) > Math.PI / 2 && Math.abs(angle2) > Math.PI / 2 && angle1 / Math.abs(angle1) != angle2 / Math.abs(angle2)) { + // if the arc between the to points crosses over the left side (+/- pi radians) + const newAngle1 = (Math.PI - Math.abs(angle1)) * (angle1 / Math.abs(angle1)); + const newAngle2 = (Math.PI - Math.abs(angle2)) * (angle2 / Math.abs(angle2)); + newAngle = (newAngle1 + newAngle2) / 2; + var multiplier; + if (newAngle == 0) { + multiplier = 1; + } else { + multiplier = newAngle / Math.abs(newAngle); + } + newAngle = Math.PI * multiplier - newAngle * multiplier; + test = true; + } else { + newAngle = (angle1 + angle2) / 2; + } + + // shoot ray between them + var endPoint = { + x: Math.cos(newAngle) * radius + pos.x, + y: Math.sin(newAngle) * radius + pos.y + } + + var best = getIntersection(pos, endPoint, domain); + + vertices.push(vertex); + + if (best.dist <= radius) vertices.push({ x: best.x, y: best.y }) + } + + vertices.sort((a, b) => Math.atan2(a.y - pos.y, a.x - pos.x) - Math.atan2(b.y - pos.y, b.x - pos.x)); + return vertices; + } + + function compareArrays(array1, array2) { + for (var i = 0; i < array1.length; i++) { + if (array1[i] != array2[i]) return false; + } + + return true; + } + + function generateIntersectMap() { + // include intersections in map elements to avoid LoS issues with overlapping + const intersectMap = []; + for (var i = 0; i < map.length; i++) { + const obj = map[i]; + const newVertices = []; + const restOfMap = [...map].slice(0, i).concat([...map].slice(i + 1)) + for (var j = 0; j < obj.vertices.length - 1; j++) { + var intersections = getIntersections(obj.vertices[j], obj.vertices[j + 1], restOfMap); + newVertices.push(obj.vertices[j]); + for (const vertex of intersections) { + newVertices.push({ x: vertex.x, y: vertex.y }); + } + } + intersections = getIntersections(obj.vertices[obj.vertices.length - 1], obj.vertices[0], restOfMap); + newVertices.push(obj.vertices[obj.vertices.length - 1]); + for (const vertex of intersections) { + newVertices.push({ x: vertex.x, y: vertex.y }); + } + + intersectMap.push({ vertices: newVertices }); + } + + return intersectMap; + } + + function addPartToMap(len) { // from "run" map + map[len].collisionFilter.category = cat.map; + map[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(map[len], true); + Composite.add(engine.world, map[len]); + } + + level.setPosToSpawn(-500, -50); + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = 250; + level.exit.y = 720; + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + level.defaultZoom = 1800; + simulation.zoomTransition(level.defaultZoom); + document.body.style.backgroundColor = "#d8dadf"; + + spawn.mapRect(-925, 0, 2650, 100); + + spawn.mapRect(-925, -1700, 325, 1800); + spawn.mapRect(-650, -325, 325, 50); + spawn.mapRect(-650, -1400, 325, 50); + spawn.mapRect(-1700, -1700, 1100, 200); + spawn.mapRect(-1700, -4600, 300, 3100); + spawn.mapRect(-1700, -4600, 1250, 200); + spawn.mapRect(200, -4600, 2750, 200); + spawn.mapRect(-400, -4225, 200, 50); + spawn.mapRect(2800, -4600, 150, 1400); + + spawn.mapRect(1350, -325, 100, 50); + spawn.mapRect(1400, -1500, 325, 1600); + spawn.mapRect(1400, -1500, 1550, 50); + spawn.mapRect(1250, -1900, 1050, 50); + spawn.mapRect(1250, -2900, 100, 1050); + + spawn.mapRect(-600, -2900, 3550, 100); + spawn.mapRect(2850, -2900, 100, 700); + spawn.mapRect(2850, -2200, 100, 350); + map[map.length - 1].fallsOff2 = true; // this piece will fall off in the middle of cutscene + + spawn.mapRect(2300, -1900, 500, 50); + map[map.length - 1].fallsOff = true; // this piece wall fall off at the start of cutscene + + spawn.mapRect(2800, -1900, 200, 50); + spawn.mapRect(2900, -1900, 50, 450); + powerUps.directSpawn(2700, -1675, "tech"); + + spawn.mapRect(2800, -3300, 825, 100); + spawn.mapRect(3525, -3300, 100, 3000); + spawn.mapRect(3400, -2850, 225, 50); + spawn.mapRect(2875, -2525, 175, 25); + spawn.mapRect(3325, -2675, 150, 25); + spawn.mapRect(3400, -2850, 75, 200); + spawn.mapRect(3150, -2225, 100, 25); + + spawn.mapRect(-2300, 750, 5450, 100); + + pendulum1 = pendulum(400, -2500, 75, 1700, 50, 0.3, 0, 300); + const gear1 = mapGear(-1200, -2000, 100, 200, 0, -0.05, 5, 75); + const gear2 = mapGear(-700, -2500, 150, 270, -0.5, 0.05, 5, 50); + const gear3 = mapGear(-3500, -1000, 1100, 1500, -0.5, 0.005, 10, 150, 40); + const piston1 = customDoor(1650, -1850, 100, 350); // x, y, width, height, distance, speed = 1 + const piston2 = customDoor(1950, -1850, 100, 350); + const piston3 = horizontalDoor(-2000, -4200, 300, 100, 300, 20); + const piston4 = horizontalDoor(-2000, -3800, 300, 100, 300, 20); + const piston5 = horizontalDoor(-2000, -3400, 300, 100, 300, 20); + const piston6 = horizontalDoor(-2000, -3000, 300, 100, 300, 20); + const piston7 = horizontalDoor(-2000, -2600, 300, 100, 300, 20); + const hand1 = clockHand(400, -3700, 75, 600); + const elevator1 = level.elevator(3200, 0, 150, 50, -1750, 0.0025, { up: 0.05, down: 0.2 }); + const lightButton = level.button(1400, -1900); + lightButton.isUp = true; + var lightOn = false; + simulation.ephemera.push({ + name: "lightWire", + do() { + if (level.levels[level.onLevel] == "clock") { + // light wire + ctx.beginPath(); + ctx.moveTo(1460, -1887); + ctx.lineTo(1300, -1887); + ctx.lineTo(1300, -2860); + ctx.lineTo(400, -2860); + ctx.lineTo(400, -2800); + ctx.lineWidth = 6; + ctx.strokeStyle = lightOn ? "#ffd700" : "000"; + ctx.stroke(); + } else { + simulation.removeEphemera(this.name); + } + }, + }) + + spawn.debris(-300, 0, 1300, 6); + spawn.debris(0, -2900, 2500, 8); + + spawn.randomSmallMob(-500, -500, 1); + spawn.randomMob(190, -1300, 1); + spawn.randomMob(200, -320, 0.3); + spawn.randomMob(1000, -1100, 1); + spawn.randomMob(-160, -2050, 1); + spawn.randomMob(-1100, -2900, 0.5); + // spawn.randomLevelBoss(1900, -3800, spawn.randomBossList.splice(0, spawn.randomBossList.indexOf("shieldingBoss"), 1).concat(spawn.randomBossList.splice(spawn.randomBossList.indexOf("shieldingBoss") + 1))); // shieldingBoss lags out the lighting system for some reason + spawn.randomLevelBoss(1900, -3800, [...spawn.randomBossList].splice(0, spawn.randomBossList.indexOf("shieldingBoss"), 1).concat([...spawn.randomBossList].splice(spawn.randomBossList.indexOf("shieldingBoss") + 1))); // shieldingBoss lags out the lighting system for some reason + spawn.randomMob(2500, -3500, 0.3); + spawn.randomMob(1300, -4100, 0.5); + spawn.randomMob(3400, -2450, 1); + spawn.randomMob(2850, -2050, 0.4); + spawn.randomGroup(-150, -2400, 0.5); + spawn.randomMob(-1250, -5150, 1); + spawn.randomMob(-2900, -4000, 0.4); + spawn.randomMob(-1350, -950, 1); + spawn.randomMob(2700, -850, 0.4); + spawn.randomMob(2500, -50, 0.4); + + powerUps.addResearchToLevel() // needs to run after mobs are spawned + + var dealtPiston1Damage = false; + var dealtPiston2Damage = false; + var dealtPiston1MobDamage = false; + var dealtPiston2MobDamage = false; + var lastPistonDirection = false; + var pistonsLocked = false; + var finishedGearFight = false; + var roofReadyToFall = false; + var roofFallCycle = 0; + var drawGear = false; + var gearCycle = simulation.cycle; + var gearPositions = []; + var pistonUnlockCycle = 0; + + for (var i = 0; i < 15; i++) { + gearPositions.push({ + x: 2400 + Math.random() * 200, + y: -3300 - Math.random() * 3000 + }); + } + + var gearSizes = []; + + for (var i = 0; i < 15; i++) { + const r1 = 30 + Math.random() * 50; + gearSizes.push({ + r1: r1, + r2: r1 + 15 + Math.random() * 30 + }) + } + + var circleHead = Matter.Bodies.polygon(m.pos.x, m.pos.y, 0, 31); + var losDomain = generateIntersectMap().concat(mob.filter((obj) => { return obj.isNotCloaked == null && (obj.isBoss || obj.label != 'Circle Body') }), [pendulum1, gear1, gear2, player, circleHead]); + var oldMap = [...map]; + var oldMob = [...mob]; + var spawnGearMobCycle = 0; + var gearsSpawned = 0; + var lastSmallGearRot = 0; + var smallGearRot = 0; + var smallGearPosRot = 0; + var bigGearRot = 0; + var finalGearRot; + var lastFinalGearRot; + var startCycle = simulation.cycle; // used to offset simulation.cycle to avoid the swing starting halfway through at the start of the level and messing up syncronization + + level.custom = () => { + if (lightOn) { + Matter.Body.setPosition(circleHead, m.pos) + if (!(compareArrays(oldMap, map) && compareArrays(oldMob, mob))) losDomain = generateIntersectMap().concat(mob.filter((obj) => { return obj.isNotCloaked == null && (obj.isBoss || obj.label != 'Circle Body') }), [pendulum1, gear1, gear2, player, circleHead]); + oldMap = [...map]; + oldMob = [...mob]; + } + ctx.fillStyle = "#b0b0b2"; + ctx.fillRect(-600, -1700, 2000, 1700); + ctx.fillRect(1350, -1851, 1550, 350); + ctx.fillRect(-1400, -2950, 4250, 1450); + ctx.fillRect(-1400, -4400, 4350, 1500); + ctx.fillRect(-450, -4600, 650, 250); + ctx.fillRect(2750, -3200, 200, 1300); + ctx.fillRect(2750, -3200, 200, 1300); + ctx.fillStyle = "#000"; + ctx.fillRect(350, -2800, 100, 25); + // light + if (lightOn) { + var lightPos = { x: 400, y: -2775 }; + var lightRadius = 2950; + const vertices = circleLoS(lightPos, lightRadius, map.concat(mob.filter((obj) => { return obj.isNotCloaked == null && (obj.isBoss || obj.label != 'Circle Body') }), [pendulum1, gear1, gear2, player, circleHead])); if (vertices.length > 0 && vertices[0].x) { + ctx.beginPath(); + ctx.moveTo(vertices[0].x, vertices[0].y); + for (var i = 1; i < vertices.length; i++) { + var currentDistance = Math.sqrt((vertices[i - 1].x - lightPos.x) ** 2 + (vertices[i - 1].y - lightPos.y) ** 2); + var newDistance = Math.sqrt((vertices[i].x - lightPos.x) ** 2 + (vertices[i].y - lightPos.y) ** 2); + if (Math.abs(currentDistance - lightRadius) < 1 && Math.abs(newDistance - lightRadius) < 1) { + const currentAngle = Math.atan2(vertices[i - 1].y - lightPos.y, vertices[i - 1].x - lightPos.x); + const newAngle = Math.atan2(vertices[i].y - lightPos.y, vertices[i].x - lightPos.x); + ctx.arc(lightPos.x, lightPos.y, lightRadius, currentAngle, newAngle); + } else { + ctx.lineTo(vertices[i].x, vertices[i].y) + } + } + newDistance = Math.sqrt((vertices[0].x - lightPos.x) ** 2 + (vertices[0].y - lightPos.y) ** 2); + currentDistance = Math.sqrt((vertices[vertices.length - 1].x - lightPos.x) ** 2 + (vertices[vertices.length - 1].y - lightPos.y) ** 2); + if (Math.abs(currentDistance - lightRadius) < 1 && Math.abs(newDistance - lightRadius) < 1) { + const currentAngle = Math.atan2(vertices[vertices.length - 1].y - lightPos.y, vertices[vertices.length - 1].x - lightPos.x); + const newAngle = Math.atan2(vertices[0].y - lightPos.y, vertices[0].x - lightPos.x); + ctx.arc(lightPos.x, lightPos.y, lightRadius, currentAngle, newAngle); + } else { + ctx.lineTo(vertices[0].x, vertices[0].y) + } + ctx.fillStyle = "rgba(216, 218, 223, 0.5)"; + ctx.fill(); + } + } + + ctx.beginPath(); + ctx.moveTo(425, -2775); + ctx.arc(400, -2775, 25, 0, Math.PI); + ctx.fillStyle = lightOn ? "#ffe245" : "transparent"; + ctx.fill(); + ctx.strokeStyle = "#000000"; + ctx.lineWidth = 1; + ctx.stroke(); + pendulum1.rotate(); + gear1.rotate(); + gear2.rotate(); + gear3.rotate(); + hand1.rotate(); + drawBackgroundGear(-1200, -2300, 75, 150, 0.3, "#ccc", -0.05); + drawBackgroundGear(-1010, -2380, 30, 100, -0.1, "#ccc", 0.05); + + // pendulum gears + if (!m.isTimeDilated) smallGearPosRot += Math.sin((simulation.cycle - startCycle) / 50) * 0.3 - Math.sin((simulation.cycle - startCycle - 1) / 50) * 0.3; + if (smallGearPosRot > 0.1) smallGearPosRot = 0.1; + if (smallGearPosRot < -0.1) smallGearPosRot = -0.1; + var circ = 2 * Math.PI * 150; + var arcLength = ((smallGearPosRot - Math.sin((simulation.cycle - startCycle) / 50) * 0.2) / (Math.PI * 2)) * circ; + lastSmallGearRot = smallGearRot; + smallGearRot = arcLength / (2 * Math.PI * 50) * Math.PI * -2 + 0.6; + + if (Math.abs(smallGearPosRot) == 0.1) { + bigGearRot += Math.abs((smallGearRot - lastSmallGearRot) * (50 / 75)); + } + + drawBackgroundGear(740, -2625, 270, 330, bigGearRot, "#d2d3d4", 0, 15, 20); // the big one in the background + + drawBackgroundGear(400, -2500, 100, 150, Math.sin((simulation.cycle - startCycle) / 50) * -0.3, "#ccc", 0, 8, 20); // attached to pendulum + + drawBackgroundGear(400 + Math.cos(smallGearPosRot) * 200, -2500 + Math.sin(smallGearPosRot) * 200, 50, 75, smallGearRot, "#ccc", 0, 7, 20); + ctx.beginPath(); + ctx.arc(400 + Math.cos(smallGearPosRot) * 200, -2500 + Math.sin(smallGearPosRot) * 200, 10, 0, 2 * Math.PI); + ctx.strokeStyle = "#444"; + ctx.lineWidth = 10; + ctx.stroke(); + ctx.beginPath(); + ctx.arc(400, -2500, 200, -0.1, 0.1); + ctx.strokeStyle = "#444"; + ctx.lineWidth = 10; + ctx.stroke(); + + drawBackgroundGear(740, -2625, 75, 110, bigGearRot, "#ccc", 0, 8, 20); + ctx.beginPath(); + ctx.arc(740, -2625, 40, 0, 2 * Math.PI); + ctx.fillStyle = "#bbb"; + ctx.fill(); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 2; + ctx.stroke(); + drawBackgroundGear(740, -2375, 75, 110, bigGearRot * -1, "#ccc", 0, 8, 20); + ctx.beginPath(); + ctx.arc(740, -2375, 40, 0, 2 * Math.PI); + ctx.fillStyle = "#bbb"; + ctx.fill(); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 2; + ctx.stroke(); + + drawDiagonalBelt({ x: 740, y: -2625, radius: 40 }, { x: 740, y: -2375, radius: 40 }) + + if (finalGearRot != null) lastFinalGearRot = finalGearRot; + finalGearRot = Math.round((-bigGearRot * 294.72 / 25) * 100) / 100 + Math.PI / 2; + + drawBackgroundGear(1080, -2650, 10, 20, finalGearRot, "#ccc", 0, 5, 50); + ctx.beginPath(); + ctx.arc(1080, -2650, 10, 0, 2 * Math.PI); + ctx.fillStyle = "#bbb"; + ctx.fill(); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 2; + ctx.stroke(); + drawBackgroundGear(1650, -2550, 300, 360, finalGearRot, "#ccc", 0, 6, 50); + ctx.beginPath(); + ctx.arc(1650, -2550, 100, 0, 2 * Math.PI); + ctx.fillStyle = "#bbb"; + ctx.fill(); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 2; + ctx.stroke(); + drawBelt({ x: 1080, y: -2650, radius: 10 }, { x: 1650, y: -2550, radius: 100 }); + ctx.beginPath(); + ctx.arc(Math.cos(-finalGearRot) * 294 + 1650, Math.sin(-finalGearRot) * 294 - 2550, 25, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + drawBackgroundGear(2300, -2550, 300, 360, -finalGearRot + 0.5, "#ccc", 0, 6, 50); + ctx.beginPath(); + ctx.arc(Math.cos(finalGearRot) * 294 + 2300, Math.sin(finalGearRot) * 294 - 2550, 25, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + + ctx.beginPath(); + ctx.arc(1630, -2215, 15, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(1670, -2215, 15, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + + ctx.beginPath(); + ctx.arc(1940, -2250, 15, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(2300, -2215, 15, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + + if (!finishedGearFight && !pistonsLocked && m.pos.x > 2100 && m.pos.x < 2900 && m.pos.y > -1850 && m.pos.y < -1500) { + pistonsLocked = true; + roofFallCycle = simulation.cycle + 250; + roofReadyToFall = true; + } + + if (roofReadyToFall && simulation.cycle >= roofFallCycle) { + // section of roof is deleted + for (var i = 0; i < map.length; i++) { + if (map[i].fallsOff) { + Matter.Composite.remove(engine.world, map[i]); + map.splice(i, 1); + } + } + + // replace it with a block + spawn.bodyRect(2310, -1900, 480, 50); + roofReadyToFall = false; + drawGear = true; + gearCycle = simulation.cycle + 100; + } + + //draw some background gears falling when roof falls + if (drawGear && simulation.cycle >= gearCycle) { + for (var i = 0; i < 15; i++) { + drawFallingBackgroundGear(gearPositions[i].x, gearPositions[i].y, gearSizes[i].r1, gearSizes[i].r2, simulation.cycle, "#ccc", 0.1, 25, gearCycle); + } + + if (spawnGearMobCycle == 0) { + spawnGearMobCycle = simulation.cycle + 100; + } + } + + if (spawnGearMobCycle > 0 && simulation.cycle >= spawnGearMobCycle) { + if (gearsSpawned < 40) { + gearMob(1600 + Math.random() * 1000, -2300 - Math.random() * 300, false, true); + gearsSpawned++; + spawnGearMobCycle = simulation.cycle + 25 - (simulation.difficulty - simulation.difficultyMode) / 2; + } else if (pistonUnlockCycle == 0) { + pistonUnlockCycle = simulation.cycle + 50; + } + } + + if (!finishedGearFight && pistonUnlockCycle > 0 && simulation.cycle > pistonUnlockCycle) { + pistonsLocked = false; + finishedGearFight = true; + + for (var i = 0; i < map.length; i++) { + if (map[i].fallsOff2) { + Matter.Composite.remove(engine.world, map[i]); + map.splice(i, 1); + } + } + + spawn.bodyRect(2850, -2180, 100, 280); + Matter.Body.setAngularVelocity(body[body.length - 1], 0.025); + } + + if (Math.sin((simulation.cycle + 15) / 25) < 0 && !lastPistonDirection) { // 15 cycles early to line up better with pendulum + piston3.isClosing = true; + piston4.isClosing = false; + piston5.isClosing = true; + piston6.isClosing = false; + piston7.isClosing = true; + } else if (Math.sin((simulation.cycle + 15) / 25) > 0 && lastPistonDirection) { + piston3.isClosing = false; + piston4.isClosing = true; + piston5.isClosing = false; + piston6.isClosing = true; + piston7.isClosing = false; + } + + if (Math.sin(-finalGearRot) - Math.sin(-lastFinalGearRot) < -0.01) { + dealtPiston1Damage = false; + dealtPiston1MobDamage = false; + } + if (Math.sin(-finalGearRot) - Math.sin(-lastFinalGearRot) > 0.01) { + dealtPiston2Damage = false; + dealtPiston2MobDamage = false; + } + + piston3.openClose(); + piston4.openClose(); + piston5.openClose(); + piston6.openClose(); + piston7.openClose(); + + if (!pistonsLocked) { + piston1.isLocked = false; + } + + if (!pistonsLocked || ((Math.sin(-finalGearRot) - Math.sin(-lastFinalGearRot) != 0 || piston1.position.y < -1850) && !piston1.isLocked)) { + piston1.setPos(1650, -1850 + Math.sin(-finalGearRot) * 175); + } else { + piston1.isLocked = true; + } + + piston2.setPos(1950, -1850 + Math.sin(finalGearRot) * 175); + ctx.beginPath(); + ctx.moveTo(Math.cos(-finalGearRot) * 294 + 1650, Math.sin(-finalGearRot) * 294 - 2550); + ctx.lineTo(1650, -2230); + ctx.lineTo(piston1.position.x, piston1.position.y - 175) + ctx.strokeStyle = "#777"; + ctx.lineWidth = 10; + ctx.stroke(); + + var circle1; + var circle2; + if (Math.cos(finalGearRot) * 294 > 0) { + circle1 = { + x: Math.cos(finalGearRot) * 294 + 2300, + y: Math.sin(finalGearRot) * 294 - 2550, + radius: -25 + } + + circle2 = { + x: 2300, + y: -2215, + radius: -15 + } + } else { + circle1 = { + x: Math.cos(finalGearRot) * 294 + 2300, + y: Math.sin(finalGearRot) * 294 - 2550, + radius: 25 + } + + circle2 = { + x: 2300, + y: -2215, + radius: 15 + } + } + + // same method used in drawBelt() + var distance = Math.sqrt((circle2.x - circle1.x) ** 2 + (circle2.y - circle1.y) ** 2); + var distanceToIntersection = (-circle1.radius * distance) / (-circle1.radius + circle2.radius); + var slopeAngle = Math.atan((circle2.y - circle1.y) / (circle2.x - circle1.x)); + var angleToTangent = Math.acos(-circle1.radius / distanceToIntersection); + const tangentPoint = { + x: Math.cos(angleToTangent + slopeAngle) * -circle2.radius + circle2.x, + y: Math.sin(angleToTangent + slopeAngle) * -circle2.radius + circle2.y + } + + // same method used in drawDiagonalBelt() + const circle3 = { + x: 1940, + y: -2250, + radius: 15 + } + + distance = Math.sqrt((circle2.x - circle3.x) ** 2 + (circle2.y - circle3.y) ** 2); + distanceToIntersection = (circle3.radius * distance) / (circle3.radius + circle2.radius); + slopeAngle = Math.atan((circle2.y - circle3.y) / (circle2.x - circle3.x)); + angleToTangent = Math.acos(circle3.radius / distanceToIntersection); + const invertedTangentPoint2 = { + x: Math.cos(-angleToTangent + slopeAngle) * circle3.radius + circle3.x, + y: Math.sin(-angleToTangent + slopeAngle) * circle3.radius + circle3.y + } + + const tangentPoint3 = { + x: Math.cos(angleToTangent + slopeAngle) * -circle2.radius + circle2.x, + y: Math.sin(angleToTangent + slopeAngle) * -circle2.radius + circle2.y + } + + distance = Math.sqrt((piston2.position.y - 175 - circle3.y) ** 2 + (piston2.position.x - 50 - circle3.x) ** 2); + slopeAngle = Math.atan((piston2.position.y - 175 - circle3.y) / (piston2.position.x - 50 - circle3.x)); + angleToTangent = Math.acos(circle3.radius / distance); + const tangentPoint4 = { + x: Math.cos(angleToTangent) * distance + circle3.x, + y: Math.sin(angleToTangent) * distance + circle3.y + } + + // draw + ctx.beginPath(); + ctx.moveTo(circle1.x, circle1.y); + ctx.lineTo(tangentPoint.x, tangentPoint.y); + const newAngle = Math.atan((tangentPoint.y - circle2.y) / (tangentPoint.x - circle2.x)); + const newAngle2 = Math.atan((tangentPoint3.y - circle2.y) / (tangentPoint3.x - circle2.x)); + ctx.arc(circle2.x, circle2.y, Math.abs(circle2.radius), newAngle, -newAngle2); + ctx.lineTo(invertedTangentPoint2.x, invertedTangentPoint2.y); + const newAngle3 = Math.atan((invertedTangentPoint2.y - circle3.y) / (invertedTangentPoint2.x - circle3.x)); + ctx.arc(circle3.x, circle3.y, circle3.radius, newAngle3, Math.PI / 2 + angleToTangent, true); + ctx.lineTo(tangentPoint4.x, tangentPoint4.y); + ctx.strokeStyle = '#777'; + ctx.lineWidth = 10; + ctx.stroke(); + + lastPistonDirection = Math.sin((simulation.cycle + 15) / 25) < 0; + + if (Matter.Query.ray([player], Matter.Vector.create(piston1.position.x - 50, piston1.position.y + 175), Matter.Vector.create(piston1.position.x + 50, piston1.position.y + 175), 5).length > 0 && !dealtPiston1Damage && Math.sin(-finalGearRot) - Math.sin(-lastFinalGearRot) > 0.01) { + m.damage(0.1); + dealtPiston1Damage = true; + } + + var piston1MobCollisions = Matter.Query.ray(mob, Matter.Vector.create(piston1.position.x - 50, piston1.position.y + 175), Matter.Vector.create(piston1.position.x + 50, piston1.position.y + 175), 5); + if (piston1MobCollisions.length > 0 && !dealtPiston1MobDamage && Math.sin(-finalGearRot) - Math.sin(-lastFinalGearRot) > 0.01) { + for (var mobHit of piston1MobCollisions) { + mobHit.body.damage(1); + } + dealtPiston1MobDamage = true; + } + + if (Matter.Query.ray([player], Matter.Vector.create(piston2.position.x - 50, piston2.position.y + 175), Matter.Vector.create(piston2.position.x + 50, piston2.position.y + 175), 5).length > 0 && !dealtPiston2Damage && Math.sin(-finalGearRot) - Math.sin(-lastFinalGearRot) < -0.01) { + m.damage(0.1); + dealtPiston2Damage = true; + } + + var piston2MobCollisions = Matter.Query.ray(mob, Matter.Vector.create(piston2.position.x - 50, piston2.position.y + 175), Matter.Vector.create(piston2.position.x + 50, piston2.position.y + 175), 5); + if (piston2MobCollisions.length > 0 && !dealtPiston2MobDamage && Math.sin(-finalGearRot) - Math.sin(-lastFinalGearRot) > 0.01) { + for (var mobHit of piston2MobCollisions) { + mobHit.body.damage(1); + } + dealtPiston2MobDamage = true; + } + + // clock + ctx.beginPath(); + ctx.arc(400, -3700, 600, 0, 2 * Math.PI); + ctx.fillStyle = "#e9e9e9"; + ctx.fill(); + ctx.strokeStyle = "#3a3f20"; + ctx.lineWidth = 2; + ctx.stroke(); + + ctx.lineCap = "butt"; + ctx.beginPath(); + ctx.moveTo(350, -4275); + ctx.lineTo(390, -4150); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 20; + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(390, -4275); + ctx.lineTo(350, -4150); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(420, -4275); + ctx.lineTo(420, -4150); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(450, -4275); + ctx.lineTo(450, -4150); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(-Math.PI / 3) * 510, + y: -3700 + Math.sin(-Math.PI / 3) * 510 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x, numberOffset.y - 62); + ctx.lineTo(numberOffset.x, numberOffset.y + 63); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(-Math.PI / 6) * 510, + y: -3700 + Math.sin(-Math.PI / 6) * 510 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 20, numberOffset.y - 62); + ctx.lineTo(numberOffset.x - 20, numberOffset.y + 63); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x + 20, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 20, numberOffset.y + 63); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(870, -3762); + ctx.lineTo(870, -3637); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(910, -3762); + ctx.lineTo(910, -3637); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(950, -3762); + ctx.lineTo(950, -3637); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(Math.PI / 6) * 535, + y: -3700 + Math.sin(Math.PI / 6) * 535 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 50, numberOffset.y - 62); + ctx.lineTo(numberOffset.x - 50, numberOffset.y + 63); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 20, numberOffset.y - 62); + ctx.lineTo(numberOffset.x, numberOffset.y + 53); + ctx.lineTo(numberOffset.x + 20, numberOffset.y - 62); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(Math.PI / 3) * 515, + y: -3700 + Math.sin(Math.PI / 3) * 515 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 20, numberOffset.y - 62); + ctx.lineTo(numberOffset.x, numberOffset.y + 53); + ctx.lineTo(numberOffset.x + 20, numberOffset.y - 62); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(Math.PI / 2) * 515, + y: -3700 + Math.sin(Math.PI / 2) * 515 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 35, numberOffset.y - 62); + ctx.lineTo(numberOffset.x - 15, numberOffset.y + 53); + ctx.lineTo(numberOffset.x + 5, numberOffset.y - 62); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x + 35, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 35, numberOffset.y + 63); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(Math.PI * 2 / 3) * 500, + y: -3700 + Math.sin(Math.PI * 2 / 3) * 500 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 65, numberOffset.y - 62); + ctx.lineTo(numberOffset.x - 45, numberOffset.y + 53); + ctx.lineTo(numberOffset.x - 25, numberOffset.y - 62); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x + 5, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 5, numberOffset.y + 63); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x + 35, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 35, numberOffset.y + 63); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(Math.PI * 5 / 6) * 500, + y: -3700 + Math.sin(Math.PI * 5 / 6) * 500 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 65, numberOffset.y - 62); + ctx.lineTo(numberOffset.x - 45, numberOffset.y + 53); + ctx.lineTo(numberOffset.x - 25, numberOffset.y - 62); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x + 5, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 5, numberOffset.y + 63); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x + 35, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 35, numberOffset.y + 63); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x + 65, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 65, numberOffset.y + 63); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(Math.PI) * 500, + y: -3700 + Math.sin(Math.PI) * 500 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 5, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 35, numberOffset.y + 63); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 5, numberOffset.y + 63); + ctx.lineTo(numberOffset.x + 35, numberOffset.y - 62); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 35, numberOffset.y - 62); + ctx.lineTo(numberOffset.x - 35, numberOffset.y + 63); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(-Math.PI * 5 / 6) * 500, + y: -3700 + Math.sin(-Math.PI * 5 / 6) * 500 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 25, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 25, numberOffset.y + 63); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 25, numberOffset.y + 63); + ctx.lineTo(numberOffset.x + 25, numberOffset.y - 62); + ctx.stroke(); + + var numberOffset = { + x: 400 + Math.cos(-Math.PI * 2 / 3) * 500, + y: -3700 + Math.sin(-Math.PI * 2 / 3) * 500 + } + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 10, numberOffset.y - 62); + ctx.lineTo(numberOffset.x + 40, numberOffset.y + 63); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 10, numberOffset.y + 63); + ctx.lineTo(numberOffset.x + 40, numberOffset.y - 62); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(numberOffset.x - 40, numberOffset.y + 63); + ctx.lineTo(numberOffset.x - 40, numberOffset.y - 62); + ctx.stroke(); + + ctx.lineCap = "round"; + + level.exit.drawAndCheck(); + level.enter.draw(); + } + + var lastBlock = Math.sin(simulation.cycle / 50) < 0; + + level.customTopLayer = () => { + if (!lightOn) lightButton.query(); + if (!lightButton.isUp) lightOn = true; + lightButton.draw(); + elevator1.move(); + + ctx.beginPath(); + ctx.moveTo(pendulum1.parts[2].vertices[0].x, pendulum1.parts[2].vertices[0].y); + for (var i = 0; i < pendulum1.parts[2].vertices.length; i++) { + ctx.lineTo(pendulum1.parts[2].vertices[i].x, pendulum1.parts[2].vertices[i].y); + } + ctx.lineTo(pendulum1.parts[2].vertices[0].x, pendulum1.parts[2].vertices[0].y); + ctx.fillStyle = "#999"; + ctx.fill(); + ctx.lineWidth = 2 + ctx.strokeStyle = color.blockS; + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(gear3.parts[1].vertices[0].x, gear3.parts[1].vertices[0].y); + for (var i = 0; i < gear3.parts[1].vertices.length; i++) { + ctx.lineTo(gear3.parts[1].vertices[i].x, gear3.parts[1].vertices[i].y); + } + ctx.lineTo(gear3.parts[1].vertices[0].x, gear3.parts[1].vertices[0].y); + ctx.fillStyle = "#999"; + ctx.fill(); + ctx.lineWidth = 2 + ctx.strokeStyle = color.blockS; + ctx.stroke(); + + ctx.fillStyle = "#444"; + ctx.fillRect(3275, -1750, 1, 1750); + + ctx.fillStyle = "#888"; + + if (Math.sin(simulation.cycle / 50) < 0 && !lastBlock) { + // remove old elements + for (var i = 0; i < map.length; i++) { + if (map[i].isRemove) { + Matter.Composite.remove(engine.world, map[i]); + map.splice(i, 1); + } + } + + // add new element + spawn.mapRect(-200, -600, 275, 50); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + } else if (Math.sin(simulation.cycle / 50) * 0.3 >= 0 && lastBlock) { + for (var i = 0; i < map.length; i++) { + if (map[i].isRemove) { + Matter.Composite.remove(engine.world, map[i]); + map.splice(i, 1); + } + } + + spawn.mapRect(825, -600, 275, 50); + addPartToMap(map.length - 1); + map[map.length - 1].isRemove = true; + } + + simulation.draw.setPaths(); + lastBlock = Math.sin(simulation.cycle / 50) * 0.3 < 0; + } + }, + buttonbutton() { + simulation.inGameConsole(`buttonbutton by ||Destabilized E||`); + const mover = level.mover(1425, -1949, 600, 25); //x,y,width.height,VxGoal,force + + let portal + portal = level.portal({ + x: -146, + y: 131 + }, 2 * Math.PI, { + x: 1805, + y: -2295 + }, 90) + + const button = level.button(-456, -1320) + spawn.bodyRect(-400, -1475, 75, 75); + const button2 = level.button(1781, -61) + spawn.bodyRect(1781, (-61) - 100, 75, 75); + const boost1 = level.boost(1366, -1942, 1300) + + button.isUp = true + button2.isUp = true + + const train = level.transport(-250, 1151, 400, 50, 8 + simulation.difficultyMode) + level.custom = () => { + if (train.position.x < -244) { + train.changeDirection(true) //go right + } else if (train.position.x > 1700) { + train.changeDirection(false) //go left + } + if (button.isUp && button2.isUp) train.move(); + mover.push(); + ctx.fillStyle = "rgba(0,255,255,0.1)"; + ctx.fillRect(6400, -550, 300, 350); + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + button.query(); + button.draw(); + button2.query(); + button2.draw(); + boost1.query(); + train.draw() + portal[2].query() + portal[3].query() + portal[0].draw(); + portal[1].draw(); + mover.draw(); + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(-150, -650, 900, 250) + }; + level.setPosToSpawn(0, -450); //normal spawn + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.exit.x = -525; + level.exit.y = 1128; + level.defaultZoom = 1500 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#ddd"; + spawn.mapRect(-725, -1325, 575, 1900); + spawn.mapRect(1425, -1925, 600, 1550); + spawn.mapRect(1450, -50, 500, 425); + spawn.mapRect(1950, 75, 325, 300); + spawn.mapRect(2275, 200, 200, 175); + spawn.mapRect(-150, -400, 900, 250); + spawn.mapRect(-150, 300, 900, 275); + spawn.mapRect(1700, 900, 450, 275); + spawn.mapRect(1800, 1600, 450, 250); + spawn.mapRect(1675, 1675, 275, 175); + spawn.mapRect(1575, 1675, 275, 175); + spawn.mapRect(-550, 1150, 150, 100); + spawn.bodyRect(-1475, -225, 50, 50); + spawn.bodyRect(2450, 1525, 925, 850); + spawn.mapRect(2275, 1400, 300, 150); + spawn.mapRect(2125, 1025, 125, 150); + spawn.mapRect(2250, 1175, 175, 75); + spawn.mapRect(2150, 1175, 175, 75); + spawn.mapRect(1725, 1150, 475, 100); + spawn.mapRect(2225, 675, 650, 50); + spawn.bodyRect(2400, 500, 150, 175); + spawn.nodeGroup(326, 85, "grenadier", 6) + spawn.mapRect(-225, -1325, 625, 225); + + spawn.randomMob(151, -1500) + spawn.randomMob(-88, -1829) + spawn.randomMob(2339, 896) + + + spawn.randomMob(1907, 1381) + spawn.randomMob(2398, 1301) + spawn.randomMob(1839, 811) + + + spawn.randomMob(2282, 1103) + spawn.randomMob(8, 124) + spawn.randomMob(629, 111) + + spawn.randomMob(43, 831) + spawn.randomMob(168, 1002) + spawn.randomMob(2956, 1006) + + spawn.randomMob(2713, 535) + spawn.randomMob(2396, 117) + spawn.randomMob(1498, -121) + + spawn.nodeGroup(2030, -16, "grower", 6) + spawn.randomLevelBoss(1840, 675) + }, + movers() { + simulation.inGameConsole(`movers by ryanbear`); + level.custom = () => { + level.exit.drawAndCheck(); + level.enter.draw(); + for (var i = 0; i < trains.length; i++) { + //oscillate back and forth + if (trains[i].position.x < 5075) { + trains[i].changeDirection(true) //go right + } else if (trains[i].position.x > 7875) { + trains[i].changeDirection(false) //go left + } + trains[i].draw(); + trains[i].move(); + } + for (var j = 0; j < zzz.length; j++) { + zzz[j][0].query(); + } + mvr.push(); + v3.query(); + ctx.fillStyle = "rgba(68,68,68,1)"; + ctx.fillRect(1725, -2400, 1000, 150); + ctx.fillRect(2175, -2775, 250, 450); + ctx.fillRect(2200, -2825, 225, 200); + ctx.fillRect(2075, -2575, 150, 200); + ctx.fillRect(2075, -2700, 150, 150); + ctx.fillRect(1875, -2525, 300, 125); + ctx.fillRect(1975, -2575, 150, 75); + ctx.fillRect(1800, -2475, 175, 100); + ctx.fillRect(2150, -2725, 350, 375); + ctx.fillRect(2475, -2575, 175, 200); + ctx.fillRect(2675, -2550, 25, 175); + ctx.fillRect(2625, -2550, 75, 200); + ctx.fillRect(2025, -2600, 200, 175); + ctx.fillRect(2025, -2675, 225, 225); + ctx.fillRect(2125, -2800, 250, 375); + ctx.fillRect(2400, -2625, 175, 175); + ctx.fillRect(2450, -2700, 100, 225); + ctx.fillRect(1950, -2600, 150, 200); + ctx.fillRect(1675, -2325, 250, 75); + ctx.fillRect(2700, -2525, 25, 150); + }; + // simulation.enableConstructMode() + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 23885; + level.exit.y = 800; + spawn.mapRect(-98, -8, 1000, 20); //bump for level entrance + spawn.mapRect(972, -287, 200, 20); //x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + var trains = []; + var zzz = []; + spawn.mapRect(9850, 475, 200, 75); + for (var i = 0; i < 6; i++) { + trains.push(level.transport(6275, -2100 + 525 * i, 600, 50, (2 * i % 2 - 1) * 4 * Math.min(simulation.difficulty / 2, 2) * (1 + Math.random()))) + zzz.push([level.boost(6275, -2100 + 525 * i, 100), 6275]); + } + document.body.style.backgroundColor = "#d8dadf"; + + const portal1 = level.portal({ + x: 3984, + y: 1293 + }, -2 * Math.PI, { //right + x: 23863, + y: 82 + }, 2 * Math.PI) //right + + spawn.mapRect(1825, -2250, 3300, 300); spawn.mapRect(3250, -2875, 150, 625); + spawn.mapRect(3250, -2875, 425, 125); + spawn.mapRect(3425, -2725, 150, 300); + spawn.mapRect(3400, -2750, 175, 350); + spawn.mapRect(3575, -2625, 150, 375); + spawn.mapRect(3175, -2750, 75, 300); + spawn.mapRect(3100, -2750, 275, 300); + spawn.mapRect(3675, -2875, 75, 125); + spawn.mapRect(3675, -2625, 75, 400); + spawn.mapRect(3350, -2425, 100, 175); + spawn.mapRect(8350, 825, 1825, 250); + spawn.mapRect(3950, 800, 800, 375); + var hzd = level.hazard(3750, -2625, 1375, 375); + // spawn.mapRect(3750, -2625, 1375, 375); + var v1 = level.vanish(3975, -2600, 225, 25); + var v2 = level.vanish(4275, -2975, 225, 25); + var mvr = level.mover(2585, 1928, 2375, 100); + //spawn.mapRect(4925, 1725, 300, 25); + var v3 = level.vanish(4925, 1725, 100, 25); + for (var i = 0; i < 16; i++) { + if (i < 10) { + level.boost(1600 + 62 * i, -2307 - 62 * i, 100); + } + else { + level.boost(1600 + 62 * i, -2307 - 62 * 20 + 62 * i, 100); + } + } + + + for (var i = -1; i < 10; i++) { + level.boost(3847 - 62 * i, 879 + 62 * i, 100); + } + spawn.mapRect(3050, 1500, 1600, 200); + spawn.mapRect(1850, -1950, 3275, 1275); spawn.mapRect(1850, -675, 3275, 1300); + + spawn.mapRect(2700, -2525, 25, 175); + spawn.mapRect(3825, 925, 125, 575); spawn.mapRect(3600, 1100, 350, 400); spawn.mapRect(3375, 1350, 275, 150); spawn.mapRect(3550, 1300, 100, 50); spawn.mapRect(3800, 1000, 100, 150); spawn.mapRect(3725, 1075, 150, 125); spawn.mapRect(3725, 1025, 150, 125); spawn.mapRect(3550, 1225, 150, 125); spawn.mapRect(3500, 1275, 175, 125); + // color.map = "#444" //custom map color + bosses = ["laserBoss", "blinkBoss", "shooterBoss", "launcherBoss", "pulsarBoss", "beetleBoss", "bladeBoss", "revolutionBoss", "dragonFlyBoss", "spiderBoss"]; + let randomBoss = Math.floor(Math.random() * bosses.length); + spawn[bosses[randomBoss]](2240, -2499, 100, false); + var btn = level.button(9889, 747); + btn.isUp = true; + spawn.randomMob(475, -725, 0.7); spawn.randomMob(825, -1825, 0.7); spawn.randomMob(3275, -3475, 0.7); spawn.randomMob(8550, 350, 0.7); spawn.randomMob(9350, -175, 0.7); spawn.randomMob(1575, 225, 0.7); spawn.randomMob(22825, 250, 0.7); + spawn.mapRect(-100, 0, 1000, 100); + var ddd = level.elevator(1326, -447, 200, 200, -2131, 0.003, { up: 0.1, down: 0.2 }); + /// transport(x, y, width, height, VxGoal = -6, force = VxGoal > 0 ? 0.0005 : -0.0005) { + spawn.mapRect(9500, 750, 675, 75); + spawn.mapRect(22350, 825, 3000, 150); + powerUps.spawn(4246, 1335, "tech") + powerUps.spawn(4246.8, 1335, "heal") + powerUps.spawn(4246.8, 1335.4, "ammo") + spawn.bodyRect(9200, 725, 50, 25); spawn.mapRect(12200, 675, 125, 50); spawn.mapRect(12925, 675, 100, 100); spawn.mapRect(13675, 650, 150, 150); spawn.mapRect(14200, 750, 25, 25); spawn.mapRect(14200, 675, 25, 75); spawn.mapRect(14550, 675, 125, 50); spawn.mapRect(15850, 675, 125, 100); spawn.mapRect(17175, 600, 25, 200); spawn.mapRect(17725, 700, 175, 50); spawn.mapRect(18775, 675, 175, 75); + spawn.bodyRect(8975, 700, 25, 25); spawn.bodyRect(8850, 575, 50, 50); spawn.bodyRect(9050, 650, 50, 50); spawn.bodyRect(8625, 575, 100, 75); spawn.bodyRect(8475, 675, 75, 25); + var train1 = level.transport(10250 - 700, 775, Math.max(1200 / simulation.difficulty, 200), 1350, 8); + level.customTopLayer = () => { + ddd.move(); + hzd.query(); + v1.query(); + v2.query(); + btn.draw(); + portal1[2].query(); + portal1[2].draw(); + portal1[3].query(); + portal1[3].draw(); + btn.query(); + if (!btn.isUp) { + spawn.mapRect(4050, 1175, 600, 325); + } + if (!btn.isUp && train1.position.x < 23785) { + train1.draw(); + train1.move(); + } + // if (trains[i].position.x < 5075) { + // trains[i].changeDirection(true) //go right + }; + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + // spawn.bodyRect(1540, -1110, 300, 25, 0.9); + // spawn.randomSmallMob(1300, -70); + // spawn.randomMob(2650, -975, 0.8); + // spawn.randomGroup(1700, -900, 0.4); + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + // spawn.secondaryBossChance(100, -1500) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + downpour() { + simulation.inGameConsole(`Downpour by DesBoot`); + + /* NEW CHANGES: + Added lights in the buildings + activate when lever is flicked + Changed lightning: + now has a chance to strike twice in a row + Small map changes + Slight rework of the start + Added sounds: + thunder + buzz from lights + */ + + + //BUILD EVERYTHING + const laser = level.hazard(7492, -2612, 10, 500, 0.3) //laserintro + spawn.mapRect(340, -2032.5, 20, 25); //laser nose //laserintro + const laserbutton = level.button(5485, -2510) + const doorbutton = level.button(7618, -3204) + const doortoggle = level.toggle(5088.4, 1226.7) + const mutetoggle = level.toggle(100, 0) + const door = level.door(6500, -1200, 100, 350, 100) + const bunkerdoor = level.door(10700, -2500, 100, 500, 200) + const boost1 = level.boost(7300, 1209, 2200) + const boost2 = level.boost(6232.6, -832.8, 1400) + const portal = level.portal({ x: 4886.4, y: 1050.7 }, 2 * Math.PI, { x: 7686, y: -2121 }, 2 * Math.PI) + const slime = level.hazard(-1800, 10, 4200, 400); + const slime2 = level.hazard(2400, -2100, 200, 2100); + const slime3 = level.hazard(2600, -2100, 3600, 200); + const slime4 = level.hazard(6400, -2100, 3600, 200); + const slime5 = level.hazard(-2000, 10, 200, 3000); + const drip1 = level.drip(1750, -700, 0, 70) + const oldOnLevel = level.levelsCleared; + + let whereToDrip = Math.random() * 2; + + const mainDropRange = (min, max) => Math.random() * (max - min) + min + const amount = Math.round(15 + 20 * Math.random()) + const drips = [] + for (let i = 0; i < amount; i++) { + if (whereToDrip < 1.25) { + const locX = mainDropRange(3800, 6000)//2200, 2300 + drips.push(level.drip(locX, -1700, -800, 200 + Math.random() * 500)) + } else { + const locX = mainDropRange(4900, 7100)//2200, 2300 + drips.push(level.drip(locX, 200, 1200, 200 + Math.random() * 500)) + } + whereToDrip = Math.random() * 2; + } + + + //ADD MORE + + + // simulation.enableConstructMode() + //LEVEL SETUP AND VARIABLES + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 13130.3; + level.exit.y = -370; + level.defaultZoom = 1800 + let rainCount = 1 + let hasDoubleFlashed = false; + let lightningTime = 0; + let canBePushed = false; + let rainXtemp1 = 0; + let rainXtemp2 = 0; + let stopcycle = 0 + let flashcycle = Math.round(Math.random() * 25 + 260) + let mobsspawned = 0 + let distanceToLight1 = 0; + let distanceToLight2 = 0; + let customExitTimer = 0; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#2e416e";//d8dadf + // color.map = "#444" //custom map color + + + + //SOUNDS + let thunder1 = new Audio('https://github.com/des-boot/n-gon-downpour-sound-effects/blob/main/thunder1.mp3?raw=true'); + let chemicalLove = new Audio('https://github.com/des-boot/n-gon-downpour-sound-effects/blob/main/Chemical%20Love%20thunder.mp3?raw=true'); + chemicalLove.play(); + let thunder2 = new Audio('https://github.com/des-boot/n-gon-downpour-sound-effects/blob/main/thunder2.mp3?raw=true'); + let thunder3 = new Audio('https://github.com/des-boot/n-gon-downpour-sound-effects/blob/main/thunder3.wav?raw=true'); + let thunder4 = new Audio('https://github.com/des-boot/n-gon-downpour-sound-effects/blob/main/thunder4.wav?raw=true'); + let ambiance1 = new Audio('https://github.com/des-boot/n-gon-downpour-sound-effects/blob/main/buzz%20(1).wav?raw=true'); + let rain1 = new Audio('https://github.com/des-boot/n-gon-downpour-sound-effects/blob/main/light-rain-109591.mp3?raw=true'); + let rain3 = new Audio('https://github.com/des-boot/n-gon-downpour-sound-effects/blob/main/8mb.video-ggm-Jd62jXAH.m4a?raw=true'); + rain1.volume = 0.125; + rain3.volume = 0.125; + thunder1.volume = 0.25; + thunder2.volume = 0.25; + thunder3.volume = 0.25; + thunder4.volume = 0.25; + + + + + //simulation.inGameConsole(stopcycle) + level.custom = () => { + for (const drip of drips) drip.draw() + drip1.draw(); + // drip1.x = Math.random() * 500 + 1630 + // if (false) { + // rain1.pause(); + // rain2.pause(); + // rain3.pause(); + // thunder1.pause(); + // thunder2.pause(); + // thunder3.pause(); + // thunder4.pause(); + // ambiance1.pause(); + // } + + ctx.fillStyle = "rgba(0,0,0,0.5)" + ctx.beginPath() + ctx.moveTo(10800, -2400)//slope of -1/3 + ctx.lineTo(10800, -340) + ctx.lineTo(12980, -340) + ctx.lineTo(12980, -700) + ctx.lineTo(13465, -700) + ctx.lineTo(13541, -1737) + ctx.lineTo(11864.6, -1967.0) + ctx.lineTo(11003, -2400) + ctx.fill() + ctx.fillRect(6100, -2000, 400, 50) + // do { + if (simulation.paused) { + rain1.pause(); + // rain2.pause(); + rain3.pause(); + thunder1.pause(); + thunder2.pause(); + thunder3.pause(); + thunder4.pause(); + } else { + // if (!mutetoggle.isOn) + rain3.play(); + if (player.position.x > 3100 && player.position.y > -1700) { + rain1.pause(); + // rain2.pause(); + rain3.volume = 0.025; + } else { + if (player.position.x > 2600 && player.position.x < 3200) { + rain1.volume = (3200 - player.position.x) / 4000 + // rain2.volume = (3100 - player.position.x) / 2000 + rain3.volume = (3200 - player.position.x) / 4000 + } + if (player.position.y > -2000 && player.position.y < -1700) { + // rain1.volume = -1 * (1700 + player.position.y) / 3000 + rain1.volume = (-3 * player.position.y) / 68000 - 0.05 + // rain2.volume = (3100 - player.position.x) / 2000 + rain3.volume = -1 * (1700 + player.position.y) / 3000 + } + // if (!mutetoggle.isOn) + rain1.play(); + // rain2.play(); + } + } + distanceToLight1 = Math.sqrt((player.position.x - 6300) * (player.position.x - 6300) + (player.position.y - 212) * (player.position.y - 212)) + distanceToLight2 = Math.sqrt((player.position.x - 4877) * (player.position.x - 4877) + (player.position.y + 1690) * (player.position.y + 1690)) + + if (doortoggle.isOn) { + if (simulation.paused) { //is it paused + ambiance1.pause(); + } else { + if (distanceToLight1 < 2000 || distanceToLight2 < 2000) { // is M close enough + // if (!mutetoggle.isOn) + ambiance1.play(); + if (distanceToLight2 < distanceToLight1) { // check for distance and set volume + ambiance1.volume = (1 - ((distanceToLight2) / 2000)) + } else { + ambiance1.volume = (1 - ((distanceToLight1) / 2000)) + + } + } else { + ambiance1.pause(); + } + } + + + } + + if (mutetoggle.isOn) { + // simulation.inGameConsole(isMuted) + muteAll(); + + } else { + // simulation.inGameConsole(isMuted) + rain1.muted = false + ambiance1.muted = false + rain3.muted = false + thunder1.muted = false + thunder2.muted = false + thunder3.muted = false + thunder4.muted = false + + } + + //mute volumes + // rain1.volume = rain1.volume * ismuted; + // // simulation.inGameConsole(ismuted) + // ambiance1.volume = ambiance1.volume * ismuted; + // rain3.volume = rain3.volume * ismuted; + // thunder1.volume = thunder1.volume * ismuted; + // thunder2.volume = thunder2.volume * ismuted; + // thunder3.volume = thunder3.volume * ismuted; + // thunder4.volume = thunder4.volume * ismuted; + do { + + + + ctx.fillStyle = "rgba(242, 255, 0, 0.3})" + ctx.fillStyle = `rgba(242,255,0,${(Math.round(Math.random + 0.3)) / 3})` + ctx.fillStyle = "rgba(242,255,0,0.3)" + + if (doortoggle.isOn) { + ctx.beginPath() + ctx.moveTo(6325, 212) + ctx.lineTo(6325 - 75, 212) + ctx.lineTo((6325 - 75) - 338, 212 + 338) + ctx.lineTo(6325 + 10, 212 + 338) + ctx.lineTo(6325 + 29.97, 212 + 1018) + ctx.lineTo(6325 + 597.4443, 212 + 1018) //at an angle to the right platform + ctx.lineTo((6325 + 75) + 375, 212 + 763) + ctx.lineTo((6325 + 75) + 375, 212 + 688) + ctx.lineTo((6325 + 75) + 688, 212 + 688) + ctx.lineTo((6325 + 75) + 100, 212 + 100) + ctx.lineTo(6325 + 75, 212) + ctx.fill() + //4875, -1688 + ctx.beginPath() + ctx.moveTo(4875, -1688)//middle + ctx.lineTo(4875 - 75, -1688)//right side + ctx.lineTo((4875 - 75) - 638, -1688 + 638)//middle of left platform + ctx.lineTo((4875 - 75) - 638 + 150, -1688 + 638) + ctx.lineTo((4875 - 75) - 315, -1688 + 448) + ctx.lineTo(4875 + 75 + 135, -1688 + 445)//right side of right platofrm + ctx.lineTo(4875 + 75 + 135 + 445, -1688 + 445 + 445) + ctx.lineTo(5460, -880) + ctx.lineTo(4875 + 75 + 538, -1688 + 538) + ctx.lineTo(4875 + 75, -1688)//left side + ctx.fill() + } + + //rain + // if (!mutetoggle.isOn) { + ctx.beginPath() + ctx.fillStyle = "rgba(30,150,117,255)" + ctx.rect(Math.random() * 4500 - 2000, -5000, 3 + 2.5, 5030) + ctx.rect(Math.random() * 4500 - 2000, -5000, 3 + 2.5, 5030) + ctx.rect(Math.random() * 4500 - 2000, -5000, 3 + 2.5, 5030) + ctx.rect(Math.random() * 2000 + 2500, -5000, 3 + 2.5, 3000) + ctx.rect(Math.random() * 2000 + 2500, -5000, 3 + 2.5, 3000) + ctx.rect(Math.random() * 1300 + 4500, -5000, 3 + 2.5, 2500) + ctx.rect(Math.random() * 1300 + 7500, -5000, 3 + 2.5, 1800) + ctx.rect(Math.random() * 1800 + 5700, -5000, 3 + 2.5, 3000) + ctx.rect(Math.random() * 1800 + 5700, -5000, 3 + 2.5, 3000) + ctx.rect(Math.random() * 1800 + 8400, -5000, 3 + 2.5, 3000) + ctx.rect(Math.random() * 1800 + 8400, -5000, 3 + 2.5, 3000) + ctx.rect(Math.random() * 4500 - 2000, -5000, 3 + 2.5, 5030) + ctx.fillStyle = "rgba(30,150,117,255)" + ctx.fill() + //rain on shed + rainXtemp1 = Math.random() * 900 + 11100 + rainXtemp2 = Math.random() * 900 + 10200 + if (rainXtemp2 < 10800) { + ctx.rect(rainXtemp2, -5000, Math.random() * 3 + 2.5, 3000) + } else { + ctx.rect(rainXtemp2, -5000, Math.random() * 3 + 2.5, 2600) + } + ctx.rect(rainXtemp1, -5000, Math.random() * 3 + 2.5, 5000 + 0.5468 * rainXtemp1 - 8507) + + // ctx.rect(Math.random() * 900 + 10200, -5000, Math.random() * 3 + 2.5, 3000) + // ctx.rect(Math.random() * 900 + 11100, -5000, Math.random() * 3 + 2.5, 5000 + 0.5468 * this.x - 8507) + ctx.rect(Math.random() * 1800 + 12000, -5000, Math.random() * 3 + 2.5, 3000) + ctx.rect(Math.random() * 1800 + 12000, -5000, Math.random() * 3 + 2.5, 3000) + ctx.rect(Math.random() * 1500 - 3500, -5000, Math.random() * 3 + 2.5, 10030) + ctx.fillStyle = "rgba(30,150,117,255)" + ctx.fill() + + + // } + + } while (Math.random() < 0.5); //this is really important, keep it + + + + //simulation.inGameConsole(stopcycle) + //simulation.inGameConsole(m.cycle) + // ctx.fillStyle = "rgba(228,255,0,0.8)" + // //simulation.inGameConsole(stopcycle) + // ctx.fillRect(50.4, -1210.0, 100, 100) + // stopcycle = m.cycle + Math.random * 600; + //stopcycle = m.cycles + Math.random * 600 + + + //LIGHTNING + //flash cycle gets set to a random number 260-295 + //stop cycle increases until it is bigger than flash cycle + //lightning effect starts + //stop cycle continues increasing until it reaches 300 + //repeat + // simulation.inGameConsole(stopcycle) + if (stopcycle > 300) { //reset + if (Math.random() > 0.8 && hasDoubleFlashed == false) { + flashcycle = Math.round(Math.random() * 10 + 275) + stopcycle = flashcycle - 20 + hasDoubleFlashed = true + } else { + flashcycle = Math.round(Math.random() * 25 + 260) + stopcycle = Math.random() * -100 + hasDoubleFlashed = false + } + document.body.style.backgroundColor = "#2e416e"; + playRandomThunder() + } else { + if (stopcycle > flashcycle) { + document.body.style.backgroundColor = "#7391ff"; + for (let i = 0; i < mob.length; i++) mobs.statusStun(mob[i], 300 - flashcycle)//Math.random() * 20 + 20 + lightningTime = flashcycle - 300 + + } + stopcycle = stopcycle + 1 + } + + + //mute button + ctx.textAlign = "start" + ctx.fillStyle = "#00ffff"; + // ctx.fillText("Waste Discharge Interruption:", 2910, -3870); + // ctx.fillText("Owner 'Scarlet' not found", 2910, -3830); + // ctx.fillText("Detected user: 'm'", 2910, -3790); + ctx.font = "27px monospace"; + ctx.fillText("Audio:", 150, -270); + ctx.font = "54px monospace"; + ctx.textAlign = "right"; + ctx.fillText(mutetoggle.isOn ? "Muted" : "Unmuted", 250, -210); + + //mute symbol + if (mutetoggle.isOn) { + ctx.strokeStyle = "#ff0400"; + } else { + ctx.strokeStyle = "#00ff00"; + } + + // ctx.beginPath(); + // ctx.rect(80 + 50, -187.5, 20, 25) + // ctx.stroke(); + ctx.lineWidth = 10; + + ctx.beginPath(); + ctx.moveTo(130, -167.5) //top left + ctx.lineTo(130 + 15 * 2, -167.5) //top mid + ctx.lineTo(130 + 30 * 2, -167.5 - 10 * 2) //top right + ctx.lineTo(130 + 30 * 2, -167.5 + 35 * 2) //bottom right + ctx.lineTo(130 + 15 * 2, -167.5 + 22 * 2) //bottom mid + ctx.lineTo(130, -167.5 + 22 * 2) // bottom left + ctx.lineTo(130, -167.5) //top left + ctx.stroke(); + + // canvas.width += 5 + // ctx.strokeSyle() + if (mutetoggle.isOn) { + ctx.lineWidth = 9; + ctx.moveTo(230, -185) + ctx.lineTo(140, -95) + ctx.stroke(); + ctx.lineWidth = 5; + ctx.stroke(); + ctx.beginPath(); + ctx.arc(170, -145, 45, 1.75 * Math.PI, 0.25 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(170, -145, 60, 1.75 * Math.PI, 0.25 * Math.PI); + ctx.stroke(); + } else { + ctx.stroke(); + ctx.beginPath(); + ctx.arc(170, -145, 45, 1.75 * Math.PI, 0.25 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(170, -145, 60, 1.75 * Math.PI, 0.25 * Math.PI); + ctx.stroke(); + } + + + // ctx.arc(130, -175, 8, 0, 2 * Math.PI); + ctx.lineWidth = 4; + ctx.stroke(); + ctx.textAlign = "center"; + ctx.fillStyle = "#00ffff"; + // if (isMuted = 0) { + // ctx.fillText("Muted", 360, -230); + // } else { + // ctx.fillText("Unmuted", 360, -190); + // } + + // ctx.strokeStyle = "#00ff00"; + // ctx.beginPath(); + // ctx.arc(3300, -3730, 60, 0, 2 * Math.PI); + // ctx.stroke(); + // ctx.arc(3330, -3730, 8, 0, 2 * Math.PI); + // ctx.lineWidth = 4; + // ctx.stroke(); + // ctx.textAlign = "center"; + // ctx.fillStyle = "#00ffff"; + // ctx.font = "30px monospace"; + // ctx.fillText("n-gon inc", 3300, -3630); + + ctx.font = "25px Arial"; + + + ctx.fillStyle = "#d4f4f4" + ctx.fillRect(12984, -704, 420, 450) + //windows + + //scrapped, but i might work on this again + // if (stopcycle > flashcycle) { + // ctx.fillStyle = "rgba(255, 255, 255, 1)" + // ctx.fillRect(4703, -2362, 100, 100) + // ctx.fillRect(5053, -2362, 100, 100) + // ctx.fillRect(5403, -2362, 100, 100) + // ctx.fillRect(4703, -2062, 100, 100) + // ctx.fillRect(5053, -2062, 100, 100) + // ctx.fillRect(5403, -2062, 100, 100) + // } else { + ctx.fillStyle = "rgba(0,0,0,0.5)" + ctx.fillRect(4703, -2362, 100, 100) + ctx.fillRect(5053, -2362, 100, 100) + ctx.fillRect(5403, -2362, 100, 100) + ctx.fillRect(4703, -2062, 100, 100) + ctx.fillRect(5053, -2062, 100, 100) + ctx.fillRect(5403, -2062, 100, 100) + // } + + ctx.fillStyle = "rgba(0,0,0,0.5)" + ctx.fillRect(4523, -2512, 1150, 800) + ctx.fillRect(4735, -1233, 100, 500)//tree + ctx.beginPath() + + ctx.moveTo(4487, -1195)//slope of -1/3 + ctx.lineTo(4736, -792) + ctx.lineTo(4736, -852) + ctx.lineTo(4527, -1195) + + ctx.moveTo(5087, -1195)//slope of -1/3 + ctx.lineTo(4836, -792) + ctx.lineTo(4836, -852) + ctx.lineTo(5047, -1195) + ctx.fill() + + ctx.moveTo(5252.4, -2483.5) + ctx.lineTo(5141.2, -2507.8) + ctx.lineTo(5209.2, -2625.2) + ctx.lineTo(5290.2, -2626.6) + ctx.lineTo(5361.2, -2697.9) + ctx.lineTo(5410.6, -2717.0) + ctx.lineTo(5680.2, -2648.7) + ctx.lineTo(5687.7, -2471.5) + ctx.fill() + + + + //building 2 spawn.mapRect(8473, -2513, 50, 50); + ctx.fillRect(8673, -2137, 50, 175) + ctx.fillRect(7630, -2540, 100, 100) + ctx.fillRect(7930, -2540, 100, 100) + ctx.fillRect(8230, -2540, 100, 100) + ctx.fillRect(8530, -2765, 100, 100) + ctx.fillRect(7630, -2990, 100, 100) + ctx.fillRect(7930, -2990, 100, 100) + ctx.fillRect(8230, -2990, 100, 100) + + + ctx.beginPath() + ctx.moveTo(7475, -3213) + ctx.lineTo(8100, -3213) + ctx.lineTo(8191.2, -3334.7) + ctx.lineTo(8318.0, -3388.3) + ctx.lineTo(8348.5, -3496.9) + ctx.lineTo(8480.0, -3512.6) + ctx.lineTo(8670, -3482) + ctx.lineTo(8725, -3213) + ctx.lineTo(8725, -1463) + ctx.lineTo(7475, -1463) + ctx.fill() + + + + //stairs + ctx.fillRect(8523, -2563, 50, 50) + ctx.fillRect(8473, -2613, 50, 50) + ctx.fillRect(8423, -2663, 50, 50) + ctx.fillRect(8373, -2713, 50, 50) + ctx.fillRect(8323, -2763, 50, 50) + + ctx.fillRect(8323, -2813, 50, 50) + ctx.fillRect(8373, -2863, 50, 50) + ctx.fillRect(8423, -2913, 50, 50) + ctx.fillRect(8473, -2963, 50, 50) + + ctx.fillRect(8523, -3013, 50, 50)//make block + ctx.fillRect(8473, -3063, 50, 50)//make block + ctx.fillRect(8423, -3113, 50, 50)//make block + ctx.fillRect(8373, -3163, 50, 50) + ctx.fillRect(8323, -3213, 50, 50) + + //caves + + ctx.fillStyle = "rgba(30,150,117,255)"//fake slime + //87,189,146,255 + ctx.fillRect(6100, -1900, 100, 1050) + ctx.fillRect(6400, -1900, 100, 1050) + ctx.fillRect(2600, -850, 4700, 200) + ctx.fillRect(7200, -650, 100, 1900) + ctx.fillRect(2399, -1, 200, 400) + + //bunker + ctx.fillStyle = "rgba(0,0,0,0.5)" + + // ctx.beginPath() + // ctx.moveTo(10800, -2400)//slope of -1/3 + // ctx.lineTo(10800, -340) + // ctx.lineTo(12980, -340) + // ctx.lineTo(12980, -700) + // ctx.lineTo(13465, -700) + // ctx.lineTo(13541, -1737) + // ctx.lineTo(11864.6, -1967.0) + // ctx.lineTo(11003, -2400) + // ctx.fill() + // ctx.fillRect(6100, -2000, 400, 50) + + // -2000 -> 2500 + // Math.random() * 5000 -2500 + ctx.fillStyle = "rgba(0,0,0,0.6)" + ctx.beginPath() + ctx.moveTo(6100, -1700) + ctx.lineTo(5799.5, -800) + ctx.lineTo(2600, -800) + ctx.lineTo(2600, -1700) + ctx.lineTo(5799.5, -1700) + + ctx.moveTo(6500, -1200) + ctx.lineTo(7600, -1200) + ctx.lineTo(8000, 1400) + ctx.lineTo(4600, 1500) + ctx.lineTo(4500.5, 0) + ctx.lineTo(6500, -200) + ctx.lineTo(6500, -1200) + ctx.fill() + + //rocks in river + ctx.fillStyle = "rgba(50,50,50,0.6)" + + ctx.beginPath() + ctx.moveTo(-2050, 0) + ctx.lineTo(1725, 0) + ctx.lineTo(1980, 88) + ctx.lineTo(2118, 257) + ctx.lineTo(2167, 491) + ctx.lineTo(-1800, 3000) + + ctx.lineTo(-2050, 3000) + + // ctx.moveTo(6500, -1200) + // ctx.lineTo(7600, -1200) + // ctx.lineTo(8000, 1400) + // ctx.lineTo(4600, 1500) + // ctx.lineTo(4500.5, 0) + // ctx.lineTo(6500, -200) + // ctx.lineTo(6500, -1200) + ctx.fill() + + + + portal[2].query() + portal[3].query() + if (laserbutton.isUp) { + laser.isOn = true; + } else { + laser.isOn = false; + } + + + ctx.fillStyle = "rgba(0,0,0,0.6)" + ctx.fillRect(2013, -791, 600, 75) + ctx.fillRect(1766, -1091, 250, 310) + ctx.beginPath() + ctx.moveTo(1816, -781) + ctx.lineTo(1816, 32) + ctx.lineTo(1966, 84) + ctx.lineTo(1966, -781) + ctx.fill() + // ctx.fillRect(1816, -781, 150, 2000) + + ctx.fillRect(4473, -2912, 50, 1000) + ctx.fillRect(5673, -2712, 50, 800) + ctx.fillStyle = "rgba(0,0,0,0.2)" + + ctx.fillRect(4523, -2512, 350, 75) + ctx.fillRect(5273, -2212, 400, 75) + + + // if (level.levelsCleared > oldOnLevel) { + // simulation.inGameConsole("muted bc next level"); + // console.log("muted bc next level"); + // rain1.muted = true + // ambiance1.muted = true + // rain3.muted = true + // thunder1.muted = true + // thunder2.muted = true + // thunder3.muted = true + // thunder4.muted = true + // } + if (player.position.x > level.exit.x && player.position.x < level.exit.x + 100 && player.position.y > level.exit.y - 150 && player.position.y < level.exit.y - 0 && player.velocity.y < 0.15) { + // level.exitCount += input.down ? 8 : 2 + customExitTimer += 3 + } else if (customExitTimer > 0) { + customExitTimer -= 3 + } + // simulation.inGameConsole(customExitTimer); + + if (customExitTimer > 80) { + // simulation.inGameConsole("muted bc next level"); + // console.log("muted bc next level"); + muteAll(); + } + level.exit.drawAndCheck(); + + addEventListener("keydown", function (event) { + if (event.key == "u") { + muteAll(); + } + }) + + // if (simulation.testing) { + // if (key.toLowerCase = "o") { + // rain1.muted = true + // ambiance1.muted = true + // rain3.muted = true + // thunder1.muted = true + // thunder2.muted = true + // thunder3.muted = true + // thunder4.muted = true + // } + // } + slime.query(); + slime2.query(); + slime3.query(); + slime4.query(); + slime5.query(); + + + // spawn.mapRect(4873, -2512, 800, 75); + // spawn.mapRect(4473, -2212, 800, 75); + //setTimeout(function(){/*YourCode*/},1000); + + + + + + //water falling/flowing effect + ctx.fillStyle = `hsla(160, 100%, 26%,${0.5 + 0.07 * Math.random()})`//lower river + ctx.fillRect(-1800 + Math.random() * 100, 10 + 400 * Math.random(), 3900, 5) + ctx.fillRect(-1800, 10 + 400 * Math.random(), 4400, 5) + + ctx.fillRect(2400 + 200 * Math.random(), Math.random() * - 100 - 2000, 5, 2000)//first waterfall + ctx.fillRect(6100 + 100 * Math.random(), Math.random() * - 100 - 1900, 5, 1050)//twin waterfalls + ctx.fillRect(6400 + 100 * Math.random(), Math.random() * - 100 - 1900, 5, 1050) + ctx.fillRect(-2000 + 200 * Math.random(), Math.random() * 100, 5, 2000)//far left waterfall + + ctx.fillRect(7200 + 100 * Math.random(), -800 - 50 * Math.random(), 5, 2032) + level.enter.draw(); + laserbutton.query(); + laserbutton.draw(); + doortoggle.query(); + mutetoggle.query(); + if (!doortoggle.isOn) { + door.isClosing = true + bunkerdoor.isClosing = true + + } else { + door.isClosing = false + bunkerdoor.isClosing = false + if (mobsspawned == 0) { + spawn.randomSmallMob(6128.0, 822.6); + spawn.randomSmallMob(6854.8, 560.2); + spawn.randomSmallMob(8320.7, -3402.4); + spawn.randomMob(6629.0, 711.3, 0.8); + spawn.randomMob(8199.2, -2545.5, 0.8); + spawn.randomMob(8067.7, -2957.2, 0.8); + spawn.randomMob(5149.6, -1444.1, 0.8); + + mobsspawned = 1 + + } + + } + door.openClose(); + bunkerdoor.openClose(); + + }; + level.customTopLayer = () => { + door.draw(); + bunkerdoor.draw(); + + //lights in basement + + // if (doortoggle.isOn) { + // ctx.beginPath() + // ctx.moveTo(6325, 212) + // ctx.lineTo(6325 - 75, 212) + // ctx.lineTo((6325 - 75) - 338, 212 + 338) + // ctx.lineTo(6325 + 10, 212 + 338) + // ctx.lineTo(6325 + 29.97, 212 + 1018) + // ctx.lineTo(6325 + 597.4443, 212 + 1018) //at an angle to the right platform + // ctx.lineTo((6325 + 75) + 375, 212 + 763) + // ctx.lineTo((6325 + 75) + 375, 212 + 688) + // ctx.lineTo((6325 + 75) + 688, 212 + 688) + // ctx.lineTo((6325 + 75) + 100, 212 + 100) + // ctx.lineTo(6325 + 75, 212) + // ctx.fillStyle = `rgba(242, 255, 0, 0.3})` + + // ctx.fill() + // } + spawn.mapRect(6250, 200, 150, 12); + + + laser.opticalQuery(); + if (checkForPush(m.pos.x, m.pos.y)) { + Matter.Body.setVelocity(player, { + x: player.velocity.x + checkForWaterXSpeed(m.pos.x, m.pos.y), + y: player.velocity.y + checkForWaterYSpeed(m.pos.x, m.pos.y) + }); + } + + + + //push stuff + for (let i = 0, len = body.length; i < len; ++i) { //push blocks away + if (checkForPush(body[i].position.x, body[i].position.y)) { + if (checkForWaterYSpeed(body[i].position.x, body[i].position.y) == 0) { + body[i].force.x += checkForWaterXSpeed(body[i].position.x, body[i].position.y) / 300; + body[i].force.y += checkForWaterYSpeed(body[i].position.x, body[i].position.y) / 1000 - 0.001; + } else { + body[i].force.x += checkForWaterXSpeed(body[i].position.x, body[i].position.y) / 300; + body[i].force.y += checkForWaterYSpeed(body[i].position.x, body[i].position.y) / 1000; + } + } + for (let i = 0, len = powerUp.length; i < len; ++i) { //push blocks away + if (checkForPush(powerUp[i].position.x, powerUp[i].position.y - 50)) { + powerUp[i].force.x += checkForWaterXSpeed(powerUp[i].position.x, powerUp[i].position.y) / 800; + powerUp[i].force.y += checkForWaterYSpeed(powerUp[i].position.x, powerUp[i].position.y) / 800; + powerUp[i].position.x -= 0.1; + } + } + } + // for (let i = 0, len = powerUp.length; i < len; ++i) { //push blocks away + // if (checkForPush(powerUp[i].position.x, powerUp[i].position.y)) { + // powerUp[i].force.x += checkForWaterXSpeed(powerUp[i].position.x, powerUp[i].position.y) / 1000; + // powerUp[i].force.y += checkForWaterYSpeed(powerUp[i].position.x, powerUp[i].position.y) / 1000; + // } + // } + for (let i = 0, len = mob.length; i < len; ++i) { //push blocks away + if (checkForPush(mob[i].position.x, mob[i].position.y)) { + mob[i].force.x += checkForWaterXSpeed(mob[i].position.x, mob[i].position.y) / 2000; + mob[i].force.y += checkForWaterYSpeed(mob[i].position.x, mob[i].position.y) / 2000; + } + } + for (let i = 0, len = bullet.length; i < len; ++i) { //push blocks away + if (checkForPush(bullet[i].position.x, bullet[i].position.y)) { + if (b.activeGun == 0 || b.activeGun == 1 || b.activeGun == 2 || b.activeGun == 4 || b.activeGun == 7) { + bullet[i].velocity.x += checkForWaterXSpeed(bullet[i].position.x, bullet[i].position.y) * 100; + bullet[i].velocity.y += checkForWaterYSpeed(bullet[i].position.x, bullet[i].position.y) * 100; + } + } + } + // for (let i = 0, len = bullet.length; i < len; ++i) { //push bullets away vertically + // if (bullet[i].position.x > -7625 && bullet[i].position.x < -7075 && bullet[i].position.y > -2975 - 100 && bullet[i].position.y < -625) { + // bullet[i].force.y -= simulation.g * bullet[i].mass; + // } + // } + // for (let i = 0, len = powerUp.length; i < len; ++i) { //push powerups away + // if (powerUp[i].position.x > -7625 && powerUp[i].position.x < -7075 && powerUp[i].position.y > -2975 - 100 && powerUp[i].position.y < -625) { + // powerUp[i].force.y -= simulation.g * powerUp[i].mass + 0.12; + // } + // } + + // for (let i = 0, len = mob.length; i < len; ++i) { //push mobs away + // if (mob[i].position.x > -7625 && mob[i].position.x < -7075 && mob[i].position.y > -2975 - 100 && mob[i].position.y < -625) { + // mob[i].force.y -= simulation.g * mob[i].mass + 0.0012; + // } + // } + + + + + + boost1.query(); + boost2.query(); + + // ctx.fillRect(7200, -650, 100, 1900) + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + }; + + //little block to stop push + spawn.mapRect(50, -10, 250, 20) + + spawn.mapRect(4800, -1700, 150, 12); + + + spawn.mapRect(-100, 0, 1000, 100); + spawn.mapRect(-1800, 400, 4400, 1300); + // spawn.mapRect(-1800, 0, 100, 400); + spawn.mapRect(2600, -2000, 3500, 300); + spawn.mapRect(2600, -2000, 500, 800); + spawn.mapRect(2955, -1779, 800, 300); + spawn.mapRect(2600, -800, 2300, 2500); + spawn.mapRect(-460, 100, 1570, 400); + spawn.mapVertex(965, 67, "0 -100 220 0 0 0"); + spawn.mapVertex(-185, 67, "0 -100 -420 0 0 0"); + spawn.mapVertex(1210, 365, "0 -400 300 0 0 0"); + spawn.mapRect(257.5, -358.5, 50, 360); + spawn.mapRect(-83, -358.5, 350, 50); + + //blocks in river/waterfall + spawn.mapRect(1275, 0, 450, 75); + spawn.mapRect(2027, -388, 600, 75); + spawn.mapRect(1726, -791, 330, 19); + spawn.mapRect(1696, -772, 390, 19); + spawn.mapRect(1666, -753, 450, 19); + spawn.mapRect(1636, -734, 510, 19); + + spawn.mapRect(1666, -1091, 450, 75); + + //buildings + spawn.mapRect(4873, -2512, 800, 75); + spawn.mapRect(4473, -2212, 800, 75); + spawn.mapRect(4473, -2912, 50, 800); + spawn.mapRect(5673, -2712, 50, 575); + spawn.mapRect(6671.5, -2401.4, 500, 50); + spawn.mapRect(6105.1, -2354.1, 400, 50); + spawn.mapRect(4473, -2952, 8, 75);//1,3,2 + spawn.mapRect(4493, -3032, 15, 150); + spawn.mapRect(4513, -2982, 7, 75); + spawn.mapRect(5673, -2742, 12, 50); + spawn.mapRect(5703, -2772, 8, 100); + + + //building 2 + spawn.mapRect(7473, -3412, 50, 800); + spawn.mapRect(7473, -2312, 50, 500); + spawn.mapRect(8673, -3212, 50, 1075); + spawn.mapRect(7523, -2313, 800, 75); + spawn.mapRect(7523, -2763, 800, 75); + spawn.mapRect(7523, -3213, 800, 75); + spawn.mapRect(8725, -2340, 400, 50); + spawn.mapRect(8925, -2640, 200, 50); + spawn.mapRect(8725, -2940, 200, 50); + + //stairs + spawn.mapRect(8323, -2363, 50, 50); + spawn.mapRect(8373, -2413, 50, 50); + spawn.mapRect(8423, -2463, 50, 50); + spawn.mapRect(8473, -2513, 250, 50); + + //stairs 2 + spawn.mapRect(8523, -3013, 50, 50)//make block + spawn.mapRect(8473, -3063, 50, 50)//make block + spawn.mapRect(8423, -3113, 50, 50)//make block + + //trees in tunnel + spawn.mapRect(4485, -1243, 600, 50) + spawn.mapRect(3967, -1056, 400, 50) + spawn.mapRect(5453, -1150, 50, 300) + spawn.mapRect(5453, -1700, 50, 300) + + + //tunnels and boss + spawn.mapRect(6500, -2000, 3100, 800); + spawn.mapRect(7500, -2000, 3300, 3700); + spawn.mapRect(4900, -800, 2300, 1000); + spawn.mapRect(4354, 1230, 4000, 470); + spawn.mapRect(5388, 863, 100, 500); + spawn.mapRect(5388, 63, 100, 500); + spawn.mapRect(5834, 549, 500, 80); + spawn.mapRect(6756, 897, 400, 80); + + //light + spawn.mapRect(6250, 200, 150, 12); + + + + //extra boss + spawn.mapRect(9196, -11492, 500, 100); + spawn.mapRect(9196, -11492, 500, 100); + + //bunker + spawn.mapRect(11500, -2000, 1900, 500); + spawn.mapRect(10800, -900, 800, 2600); + spawn.mapRect(11600, -340, 1800, 2600); + spawn.mapRect(13400, -2000, 1800, 3600); + spawn.mapRect(10800, -2500, 200, 100); + spawn.mapVertex(11400, -2233, "0 10 900 510 800 510 750 510 0 110"); + + spawn.mapVertex(10100, -2000, "0 0 0 -250 400 0"); + spawn.mapRect(12945.0, -741.9, 600, 50); + spawn.mapRect(12945.0, -741.9, 50, 250); + //stairs + spawn.mapRect(11600, -850, 50, 550); + spawn.mapRect(11650, -800, 50, 500); + spawn.mapRect(11700, -750, 50, 450); + spawn.mapRect(11750, -700, 50, 400); + spawn.mapRect(11800, -650, 50, 350); + spawn.mapRect(11850, -600, 50, 300); + spawn.mapRect(11900, -550, 50, 250); + spawn.mapRect(11950, -500, 50, 200); + spawn.mapRect(12000, -450, 50, 150); + spawn.mapRect(12050, -400, 50, 100); + spawn.mapRect(12100, -350, 50, 50); + + + //mobs + //spawn.tetherBoss(6480, 992, { x: 6480, y: 210 }) + + if (Math.random() < 0.15) { + spawn.tetherBoss(6480, 992, { x: 6480, y: 210 }) + } else { + spawn.randomLevelBoss(5977, 992) + } + + + //mobs for waterfall and first cavern + //spawn.randomSmallMob(1999.2, -487.4); + spawn.randomMob(1999.2, -487.4, 0.8); + //spawn.randomSmallMob(2080.0, -1206.4); + spawn.randomMob(2080.0, -1206.4, 0.8); + spawn.randomSmallMob(3287.5, -1021.1); + //spawn.randomSmallMob(3992.2, -1223.9); + spawn.randomSmallMob(5018.1, -1483.5); + spawn.randomGroup(6776.2, -3054.5, 0.4); + spawn.randomGroup(4217.4, -1403.6, 0.4); + + + //surface area mobs + spawn.randomSmallMob(5089.0, -2284.1); + spawn.randomSmallMob(6988.3, -2580.2); + spawn.randomSmallMob(7975.0, -2920.3); + spawn.randomMob(5132.0, -2646.2, 0.8); + spawn.randomMob(6365.2, -2459.2, 0.8); + spawn.randomMob(8129.0, -2406.7, 0.8); + spawn.randomMob(8129.0, -2406.7, 0.8); + spawn.randomGroup(2225.3, -1543.2, 0.4); + + + spawn.debris(4426.9, -1433.8, 700, 1); //16 debris per level + spawn.debris(4651.2, -2597.3, 700, 1); //16 debris per level + spawn.debris(9920.9, -2378.3, 700, 2); //16 debris per level + spawn.debris(8298.5, -2883.8, 700, 1); //16 debris per level + spawn.debris(6779.2, -2662.9, 700, 1); //16 debris per level + spawn.debris(6371.5, 442.3, 700, 2); //16 debris per level + spawn.debris(1873.5, -1297.5, 700, 1); //16 debris per level + + spawn.bodyRect(6457.9, -2541.5, 300, 25, 0.9); + //spawn.bodyRect(5685, -2140, 25, 140, 0.9); + spawn.bodyRect(4473, -2110, 50, 110, 1, 1); + //spawn.bodyRect(5292.1, -2617.2, 50, 50, 0.9); + spawn.bodyRect(6370.1, -2408.4, 50, 50, 0.9); + //spawn.bodyRect(5467, -1400, 25, 250, 0.9); + + spawn.bodyRect(4509.0, -1425.7, 30 + 45 * Math.random(), 30 + 45 * Math.random(), 0.9); + //spawn.bodyRect(8082.9, -2488.1, 30 + 45 * Math.random(), 30 + 45 * Math.random(), 0.9); + spawn.bodyRect(7859.6, -2883.6, 30 + 45 * Math.random(), 30 + 45 * Math.random(), 0.9); + //spawn.bodyRect(5609.5, 948.5, 30 + 45 * Math.random(), 30 + 45 * Math.random(), 0.9); + spawn.bodyRect(5803.7, 1125.5, 30 + 45 * Math.random(), 30 + 45 * Math.random(), 0.9); + //spawn.bodyRect(5492.1, 1061.7, 90, 169, 0.9); + spawn.bodyRect(5582.1, 1061.7, 110, 70, 0.9); + //spawn.bodyRect(5582.1, 961.7, 50, 30, 0.9); + + //button block + spawn.bodyRect(4900 + Math.random() * 400, -2600, 70, 70, 1); + + + + // spawn.randomSmallMob(1300, -70); + // spawn.randomSmallMob(1300, -70); + // spawn.randomSmallMob(1300, -70); + // spawn.randomSmallMob(1300, -70); + + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + // spawn.bodyRect(1540, -1110, 300, 25, 0.9); + // spawn.randomSmallMob(1300, -70); + // spawn.randomMob(2650, -975, 0.8); + // spawn.randomGroup(1700, -900, 0.4); + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + // spawn.secondaryBossChance(100, -1500) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + + function muteAll() { + rain1.muted = true + ambiance1.muted = true + rain3.muted = true + thunder1.muted = true + thunder2.muted = true + thunder3.muted = true + thunder4.muted = true + } + + + function checkForWaterXSpeed(objectX, objectY) { + let waterXForce = 0; + + if (objectY > -70 && objectX < 2785) { + waterXForce = -1 * (2 + objectY / 150) + } + if (objectX > 2600 && objectX < 4500 && objectY < -1900 && objectY > -2121.3) { + waterXForce = -2 + } + if (objectX > 4500 && objectX < 6000 && objectY < -1900 && objectY > -2121.3) { + waterXForce = 0.4 + } + if (objectX > 6500 && objectX < 10000 && objectY < -1900 && objectY > -2121.3) { + waterXForce = -1 + } + if (objectX > 2600 && objectX < 6100 && objectY < -650 && objectY > -920) { + waterXForce = -0.4 + } + if (objectX > 6500 && objectX < 7300 && objectY < -650 && objectY > -920 && m.onGround) { + waterXForce = 0.2 + } + return waterXForce; + } + + function checkForWaterYSpeed(objectX, objectY) { + let waterYForce = 0; + if (objectX > 2400 && objectX < 2600) { + waterYForce = 4 + } + if (player.position.x > 7200 && player.position.x < 7350 && player.position.y > -950 && player.position.y < 1250) { + waterYForce = 0.8 + } + if (player.position.x > 6100 && player.position.x < 6200 && player.position.y < -800 && player.position.y > -2000) { + waterYForce = 0.3 + } + if (player.position.x > 6400 && player.position.x < 6500 && player.position.y < -800 && player.position.y > -2000) { + waterYForce = 0.3 + } + return waterYForce; + } + + function checkForPush(objectX, objectY) { + return (objectY > -70 && objectX < 2785 || objectX > 2400 && objectX < 2600 || objectX > 2600 && objectX < 6000 && objectY < -1900 && objectY > -2121.3 || objectX > 6500 && objectX < 10000 && objectY < -1900 && objectY > -2121.3 || objectX > 2600 && objectX < 6100 && objectY < -650 && objectY > -920 || objectX > 6500 && objectX < 7300 && objectY < -650 && objectY > -920 || objectX > 7200 && objectX < 7350 && objectY > -950 && objectY < 1250 || objectX > 6100 && objectX < 6200 && objectY < -800 && objectY > -2000 || objectX > 6400 && objectX < 6500 && objectY < -800 && objectY > -2000); + } + + function playRandomThunder() { + let tempRandom = Math.floor(4 * Math.random()) + switch (tempRandom) { + case 1: + // simulation.inGameConsole(`thunder1`) + thunder1.play(); + break; + case 2: + // simulation.inGameConsole(`thunder2`) + thunder2.play(); + break; + case 3: + // simulation.inGameConsole(`thunder3`) + thunder3.play(); + break; + case 4: + // simulation.inGameConsole(`thunder4`) + thunder4.play(); + break; + default: + // simulation.inGameConsole(`thunder5`) + thunder4.play(); + break; + + } + } + }, + dungeon() { + let destroyed = false; + const door = level.door(2650, -825, 50, 250, 250, 10); + const elevator = level.elevator(-11050, -650, 450, 75, -2975, 0.003, { up: 0.1, down: 0.1 }) + const slimePit = level.hazard(-4775, -350, 1975, 175); + const boost = level.boost(137.5, -600, 75, 25); + let base = Matter.Bodies.rectangle(-4375, -1000, 100, 100, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let left = Matter.Bodies.rectangle(-4375 + 50, -1000 - 50, 50, 50, {//not actually left/right + density: 0.05, + isNotHoldable: true, + isStatic: false + }); + let right = Matter.Bodies.rectangle(-4375 - 50, -1000 - 50, 50, 50, { + density: 0.05, + isNotHoldable: true, + isStatic: false + }); + let left2 = Matter.Bodies.rectangle(-4375 - 50, -1000 + 50, 50, 50, { + density: 0.05, + isNotHoldable: true, + isStatic: false + }); + let right2 = Matter.Bodies.rectangle(-4375 + 50, -1000 + 50, 50, 50, { + density: 0.05, + isNotHoldable: true, + isStatic: false + }); + dong = Matter.Body.create({ + parts: [base, left, right, left2, right2] + }); + body[body.length] = base; + body[body.length] = left; + body[body.length] = right; + body[body.length] = left2; + body[body.length] = right2; + Matter.Composite.add(engine.world, dong) + Matter.Composite.add(engine.world, Constraint.create({ + pointA: { x: -3825, y: -975 }, + bodyB: dong, + stiffness: 0.2, + damping: 0.1 + })); + composite[composite.length] = dong; + setTimeout(function () { + dong.collisionFilter.category = cat.body; + dong.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mobBullet | cat.mob //| cat.map + }, 1000); + level.custom = () => { + ctx.save() + ctx.beginPath() + ctx.fillStyle = "#80808077"; + ctx.strokeStyle = "#80808022"; + ctx.fillRect(225, -1025, 2400, 450); + ctx.fillRect(-2950, -1025, 3100, 450); + ctx.fillRect(-7050, -1025, 2400, 450); + ctx.fillRect(-10575, -3975, 4525, 1025); + ctx.fillRect(-4650, -1700, 1700, 1100); + ctx.fillRect(-11150, -3575, 575, 3050); + ctx.fillRect(-11900, -1000, 750, 475); + ctx.fill() + ctx.stroke() + ctx.restore() + ctx.save() + ctx.beginPath() + ctx.fillStyle = "#d8dadf"; + ctx.strokeStyle = "#d8dadf"; + ctx.moveTo(-2950, -600); + ctx.lineTo(-3730, -1725); + ctx.lineTo(-3730, -600); + + ctx.moveTo(-4650, -600); + ctx.lineTo(-3925, -1725); + ctx.lineTo(-3925, -575); + + ctx.moveTo(-10575, -3425); //NE section + ctx.lineTo(-10100, -2975); + ctx.lineTo(-10575, -2975); + + // ctx.moveTo(-7625, -3800); + // ctx.lineTo(-6750, -2975); + // ctx.lineTo(-7625, -2975); + + ctx.moveTo(-7975, -2975); + ctx.lineTo(-7625, -3800); + ctx.lineTo(-7350, -2950); + + ctx.moveTo(-6750, -2975); + ctx.lineTo(-7075, -3800); + ctx.lineTo(-7350, -2950); + + // ctx.moveTo(-7975, -2975); + // ctx.lineTo(-7075, -3800); + // ctx.lineTo(-7075, -2975); + + ctx.moveTo(-11900, -950); + ctx.lineTo(-11900, -550); + ctx.lineTo(-11500, -550); + + ctx.fillRect(-3925, -1675, 200, 1075); + ctx.fillRect(-7625, -3800, 550, 875); + ctx.clearRect(-10600, -4000, 525, 475); + ctx.clearRect(-10100, -4000, 500, 300); + ctx.clearRect(-9625, -4000, 500, 175); + ctx.fillRect(-11125, -3600, 550, 50); + ctx.fillRect(-10600, -3400, 50, 425); + ctx.fillRect(-11925, -925, 45, 375); + ctx.fillRect(-3950, -1675, 75, 1100); + ctx.fillRect(-3925, -625, 950, 50); + ctx.fillRect(-4650, -600, 1700, 375); + ctx.fillRect(-14550, -2400, 2650, 2050); + //ctx.clearRect(-11050, -3000, 475, 50); + + ctx.moveTo(-11150, -3575); + ctx.lineTo(-10575, -2150); + ctx.lineTo(-10575, -3575); + + ctx.stroke() + ctx.fill() + ctx.restore() + boost.query() + slimePit.query() + if (Matter.Query.collides(dong, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + const dmg = 0.05 * Math.min(simulation.dmgScale, simulation.difficulty); + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: dong.position.x, + y: dong.position.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + } + for (let i = 0; i < mob.length; i++) { + if (Matter.Query.collides(dong, [mob[i]]).length > 0) { + const dmg = 1; + mob[i].damage(dmg, true); + simulation.drawList.push({ //add dmg to draw queue + x: dong.position.x, + y: dong.position.y, + radius: Math.sqrt(dmg) * 50, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + break + } + } + level.exit.drawAndCheck(); + ctx.beginPath() + ctx.fillStyle = '#68686822'; + ctx.fillRect(-25, -2175, 100, 200); + ctx.fill() + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + ctx.moveTo(-3825, -975) + ctx.lineTo(dong.position.x, dong.position.y) + ctx.stroke(); + ctx.setLineDash([]); + simulation.drawList.push({ //add dmg to draw queue + x: dong.position.x, + y: dong.position.y, + radius: 10, + color: color.block, + time: 20 + }); + ctx.beginPath() + ctx.fillStyle = `rgba(68,68,68, ${3 * Math.sin(simulation.cycle * 0.015)})` + ctx.fillRect(-3000, -2175, 175, 25); + ctx.fillRect(-2850, -2300, 25, 150); + ctx.fillRect(-3000, -2300, 175, 25); + ctx.fillRect(-3000, -2425, 25, 150); + ctx.fillRect(-3000, -2425, 175, 25); + ctx.fill() + ctx.fillStyle = `rgba(68,68,68, ${5 * Math.sin(simulation.cycle * 0.015)})` + ctx.fillRect(-2725, -2425, 25, 275); + ctx.fillRect(-2725, -2425, 175, 25); + ctx.fillRect(-2575, -2425, 25, 275); + ctx.fillRect(-2725, -2300, 175, 25); + ctx.fill() + ctx.fillStyle = `rgba(68,68,68, ${7 * Math.sin(simulation.cycle * 0.015)})` + ctx.fillRect(-2450, -2425, 25, 275); + ctx.fillRect(-2450, -2175, 175, 25); + ctx.fill() + ctx.stroke(); + ctx.fillStyle = `#00FFFF22`; + ctx.fillRect(-7650, -2975 - 100, 600, 2375 + 100) + ctx.fill() + ctx.fillStyle = `#00FFFF66` + ctx.fillRect(-7650 + Math.floor(Math.random() * 600), -2975 - 100, 5, 2375 + 100) + ctx.fillRect(-7650 + Math.floor(Math.random() * 600), -2975 - 100, 5, 2375 + 100) + ctx.fillStyle = `rgba(68, 68, 68)` + ctx.fillRect(-7675, -3075, 50, 125); + ctx.fillRect(-7075, -3075, 50, 125); + ctx.fillRect(-7725, -3025, 75, 75); + ctx.fillRect(-7050, -3025, 75, 75); + ctx.fill() + for (let i = 0, len = body.length; i < len; ++i) { //push blocks away vertically + if (body[i].position.x > -7625 && body[i].position.x < -7075 && body[i].position.y > -2975 - 100 && body[i].position.y < -625) { + body[i].force.y -= simulation.g * body[i].mass + 0.012; + } + } + for (let i = 0, len = bullet.length; i < len; ++i) { //push bullets away vertically + if (bullet[i].position.x > -7625 && bullet[i].position.x < -7075 && bullet[i].position.y > -2975 - 100 && bullet[i].position.y < -625) { + bullet[i].force.y -= simulation.g * bullet[i].mass; + } + } + for (let i = 0, len = powerUp.length; i < len; ++i) { //push powerups away vertically + if (powerUp[i].position.x > -7625 && powerUp[i].position.x < -7075 && powerUp[i].position.y > -2975 - 100 && powerUp[i].position.y < -625) { + powerUp[i].force.y -= simulation.g * powerUp[i].mass + 0.12; + } + } + for (let i = 0, len = mob.length; i < len; ++i) { //push mobs away vertically + if (mob[i].position.x > -7625 && mob[i].position.x < -7075 && mob[i].position.y > -2975 - 100 && mob[i].position.y < -625) { + mob[i].force.y -= simulation.g * mob[i].mass + 0.0012; + } + } + if (m.pos.x > -7625 && m.pos.x < -7075 && m.pos.y > -2975 - 100 && m.pos.y < -625) { + player.force.y -= m.mass * simulation.g + (input.down ? 0 : 0.012 * 2); + + } + elevator.move() + }; + level.setPosToSpawn(30, -2000); //normal spawn + level.exit.x = 2775; + level.exit.y = -650; + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom + 800) + document.body.style.backgroundColor = "#d8dadf"; + spawn.mapRect(-225, -1950, 350, 75); + spawn.mapRect(225, -1950, 50, 75); + spawn.mapRect(-250, -2025, 50, 150); + spawn.mapRect(250, -2025, 50, 150); + spawn.mapRect(-250, -2250, 50, 125); + spawn.mapRect(-225, -2325, 500, 100); + spawn.mapRect(250, -2250, 50, 125); + spawn.mapRect(-100, -2400, 250, 100); + spawn.mapRect(-25, -2475, 100, 100); + spawn.mapRect(125, -2350, 50, 50); + spawn.mapRect(-125, -2350, 50, 50); + spawn.mapRect(-50, -2425, 50, 50); + spawn.mapRect(50, -2425, 50, 50); + spawn.mapRect(-250, -2350, 50, 50); + spawn.mapRect(250, -2350, 50, 50); + spawn.mapRect(-75, -1975, 200, 50); + spawn.mapRect(-50, -2000, 150, 50); + spawn.mapRect(100, -1950, 50, 75); + spawn.mapRect(-75, -2250, 200, 50); + spawn.mapRect(-50, -2225, 150, 50); + spawn.mapRect(-2950, -1900, 3100, 900); + spawn.mapRect(225, -1900, 2875, 900); + spawn.mapRect(-2950, -600, 6050, 450); + spawn.mapRect(-3050, -500, 200, 350); + spawn.mapRect(-3150, -400, 200, 250); + spawn.mapRect(-3250, -300, 200, 150); + spawn.mapRect(2950, -1050, 150, 500); + spawn.mapRect(-4675, -1900, 1825, 200); + spawn.mapRect(-5325, -1900, 675, 900); + spawn.mapRect(-5325, -250, 2100, 100); + spawn.mapRect(-5325, -600, 675, 450); // - + spawn.mapRect(-4700, -500, 150, 350); + spawn.mapRect(-4650, -400, 200, 250); + spawn.mapRect(-4550, -300, 200, 150); + spawn.mapRect(-3875, -1025, 100, 100); + spawn.mapRect(-3800, -1050, 50, 50); + spawn.mapRect(-3900, -1050, 50, 50); + spawn.mapRect(-3800, -950, 50, 50); + spawn.mapRect(-3900, -950, 50, 50); + spawn.mapRect(-6925, -1175, 1700, 175); + spawn.mapRect(-6925, -600, 1725, 175); + spawn.mapRect(-7700, -600, 800, 425);// - + spawn.mapRect(-7800, -2950, 175, 2775); + spawn.mapRect(-7075, -2950, 175, 1950); + spawn.mapRect(-9150, -2975, 1525, 175); + spawn.mapRect(-7075, -2975, 1150, 175); + spawn.mapRect(-6100, -3900, 175, 1100); + spawn.mapRect(-9150, -3975, 3225, 175); + spawn.mapRect(-9175, -3850, 75, 75); + spawn.mapRect(-9625, -3825, 500, 150); + spawn.mapRect(-9650, -3725, 75, 75); + spawn.mapRect(-10100, -3700, 500, 150); + spawn.mapRect(-10100, -2975, 975, 175); + spawn.mapRect(-10125, -3600, 75, 75); + spawn.mapRect(-10575, -3575, 500, 150); + spawn.mapRect(-10575, -2975, 500, 175); + spawn.mapRect(-11325, -2975, 250, 175); + spawn.mapRect(-11325, -3575, 175, 775); + // spawn.mapRect(-11325, -3575, 800, 150); + spawn.mapRect(-11225, -2975, 150, 2000); + spawn.mapRect(-10575, -2975, 150, 2500); + spawn.mapRect(-11650, -550, 1225, 150); + spawn.mapRect(-11650, -1100, 575, 150); + spawn.mapRect(-14675, -2525, 2925, 150); + spawn.mapRect(-11900, -2525, 150, 1575); + spawn.mapRect(-11850, -1100, 250, 150); + spawn.mapRect(-11875, -550, 275, 150); + spawn.mapRect(-11900, -550, 150, 350); + spawn.mapRect(-14675, -2525, 150, 2300); + spawn.mapRect(-14675, -375, 2925, 175); + spawn.mapRect(2725, -625, 250, 50); + spawn.mapRect(2625, -1025, 100, 225); + spawn.mapRect(2700, -1025, 300, 125); + spawn.mapRect(2625, -612.5, 125, 50); + spawn.mapRect(-3950, -1725, 250, 50); + spawn.mapRect(-7650, -3825, 600, 50); + spawn.mapRect(-13900, -2400, 200, 50); + spawn.mapVertex(-11957, -430, '-175 175 0 175 0 0'); + spawn.mapVertex(-14470, -430, '175 175 0 175 0 0'); + spawn.mapVertex(-11957, -2319, '-175 -175 0 -175 0 0'); + spawn.mapVertex(-14470, -2319, '0 0 0 -175 175 -175'); + //spawn.mapRect(-13900, -2150, 1375, 125); + const sword = function () { //the ultimate blade of las destruction + mobs.spawn(player.position.x, player.position.y, 5, 30, "transparent"); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 1); + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + me.collisionFilter.category = cat.bullet; + me.collisionFilter.mask = cat.mob | cat.mobBullet; + me.isDropPowerUp = false; + me.isShielded = true; + me.showHealthBar = false; + me.isUnblockable = true; + me.leaveBody = false; + me.isBadTarget = true; + me.stroke = "transparent"; + me.isSword = true; + let index = 0; + let radius = 50; + me.do = function () { + this.health = Infinity;//just in case + for (let i = 0; i < mob.length; i++) { + if (Matter.Query.collides(this, [mob[i]]).length > 0 && !mob[i].isSword) { + const dmg = 0.25;//do not nerf + mob[i].damage(dmg, true); + simulation.drawList.push({ //add dmg to draw queue + x: mob[i].position.x, + y: mob[i].position.y, + radius: Math.sqrt(dmg) * 50, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + break + } + } + Matter.Body.setPosition(this, { + x: player.position.x + Math.cos(m.angle) * 100, + y: player.position.y - (input.down ? 0 : 30) + Math.sin(m.angle) * 100 + }) + Matter.Body.setAngle(this, m.angle + Math.PI * 2); + const setNoseShape = () => { + const mag = radius + radius * 10; + this.vertices[2].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[2].y = this.position.y + Math.sin(this.angle) * mag; + this.vertices[4].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[4].y = this.position.y + Math.sin(this.angle) * mag; + this.vertices[0].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[0].y = this.position.y + Math.sin(this.angle) * mag; + }; + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[2], this.position)), radius * 100) + const spike2 = Vector.mult(Vector.normalise(Vector.sub(this.vertices[4], this.position)), radius * 500) + const spike3 = Vector.mult(Vector.normalise(Vector.sub(this.vertices[0], this.position)), radius * 500) + this.vertices[2].x = this.position.x + spike.x / 100 + this.vertices[2].y = this.position.y + spike.y / 100 + this.vertices[4].x = this.position.x + spike2.x / 75 + this.vertices[4].y = this.position.y + spike2.y / 75 + this.vertices[0].x = this.position.x + spike3.x / 75 + this.vertices[0].y = this.position.y + spike3.y / 75 + if (index == 0) { + setNoseShape(); + index++; + } + ctx.save() + ctx.beginPath(); + const vertices = this.vertices; + ctx.lineWidth = 100; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + const gradient = ctx.createRadialGradient(this.position.x, this.position.y, 15, this.position.x, this.position.y, Math.abs(275 * Math.sin(simulation.cycle / 50)) + 15); + // Add three color stops + gradient.addColorStop(0, m.eyeFillColor); + gradient.addColorStop(0.9, "white"); + gradient.addColorStop(1, "darkgray"); + ctx.fillStyle = gradient; + ctx.strokeStyle = "transparent"; + ctx.shadowBlur = 10; + ctx.shadowColor = m.eyeFillColor; + ctx.fill(); + ctx.stroke(); + ctx.restore() + + const Dx = Math.cos(m.angle); + const Dy = Math.sin(m.angle); + let xElec = this.position.x + 10 * Dx; + let yElec = this.position.y + 10 * Dy; + ctx.beginPath(); + ctx.moveTo(xElec, yElec); + const step = 40 + for (let i = 0; i < 6; i++) { + xElec += step * (Dx + 1.5 * (Math.random() - 0.5)) + yElec += step * (Dy + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(xElec, yElec); + } + ctx.strokeStyle = m.eyeFillColor; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + if (this.alive && m.energy > 0) { + const gradient = ctx.createRadialGradient(this.position.x, this.position.y, 0, this.position.x, this.position.y, Math.abs(20 * Math.cos(simulation.cycle / 50))); + // Add three color stops + gradient.addColorStop(0, m.eyeFillColor); + gradient.addColorStop(0.9, "white"); + gradient.addColorStop(1, "gray"); + ctx.save() + ctx.beginPath() + ctx.moveTo(this.position.x, this.position.y) + ctx.arc(this.position.x, this.position.y, 20, 0, 2 * Math.PI) + ctx.fillStyle = gradient; + ctx.strokeStyle = "transparent"; + ctx.shadowBlur = 10; + ctx.shadowColor = m.eyeFillColor; + ctx.fill() + ctx.stroke() + ctx.restore() + m.energy -= 0.002; + + ctx.save() + ctx.translate(this.vertices[2].x, this.vertices[2].y) + ctx.rotate(m.angle + Math.PI / 2) + ctx.beginPath() + ctx.font = "16px Arial"; + ctx.fillStyle = "black"; + ctx.strokeStyle = "black"; + // ctx.fillText("Θ", 0,0 - 110) + // ctx.fillText("ά", 0,15 - 110) + // ctx.fillText("ν", 0,30 - 110) + // ctx.fillText("α", 0,45 - 110) + // ctx.fillText("τ", 0,60 - 110) + // ctx.fillText("ο", 0,75 - 110) + // ctx.fillText("ς", 0,90 - 110) + ctx.fillText("Ω", 0, 55) + ctx.fill() + ctx.stroke() + ctx.restore() + + simulation.drawList.push({ + x: this.position.x + Math.floor(Math.random() * 300 - Math.random() * 300), + y: this.position.y + Math.floor(Math.random() * 300 - Math.random() * 300), + radius: 2, + color: m.eyeFillColor, + time: simulation.drawTime + }); + } else { + this.death() + powerUps.activated = false + } + } + } + //setTimeout(function() {sword();}, 100); + const wire = function () { + const breakingPoint = -1600; + const spawnx = -13800 + Math.floor(Math.random() * 100 - Math.random() * 100); + mobs.spawn(spawnx, -2375, 0, 2, "transparent"); + let me = mob[mob.length - 1]; + let boss = mob[0]; + me.collisionFilter.category = cat.body; + me.collisionFilter.mask = cat.map; + me.g = 0.0003; //required for gravity + me.restitution = 0; + me.stroke = "transparent" + me.freeOfWires = false; + me.frictionAir = 0.01; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.isBadTarget = true; + me.isUnblockable = true; + const wireX = spawnx; + const wireY = -2375; + //const randomw = Math.floor(Math.random() * 100 - Math.random() * 100); + const width = Math.abs(10 + Math.floor(Math.random() * 10 - Math.random() * 10)); + const randomx = Math.floor(30 * Math.random() - 30 * Math.random()); + const randomy = Math.floor(10 * Math.random() - 10 * Math.random()) + me.do = function () { + if (this.freeOfWires) { + this.gravity(); + } else { + if (boss.position.y > breakingPoint) { + this.freeOfWires = true; + this.force.y -= -0.0006; + this.force.x += Math.random() * boss.velocity.x / 10000; + this.fill = "#111"; + } + //move mob to mob + Matter.Body.setPosition(this, { + x: boss.position.x + randomx, + y: boss.position.y + randomy + }) + } + //draw wire + ctx.beginPath(); + ctx.moveTo(wireX, wireY); + ctx.quadraticCurveTo(wireX, -100, this.position.x, this.position.y); + ctx.lineWidth = width; + ctx.lineCap = "butt"; + ctx.strokeStyle = "#111"; + ctx.stroke(); + ctx.lineCap = "round"; + }; + } + + const ball = function (x, y, radius = 11 * tech.bulletSize, sides = 70) {//superball //also, why is it called superballs? + mobs.spawn(x, y, sides, radius, "rgba(0,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 20, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + }; + Matter.Body.setDensity(me, 0.00001); //normal is 0.001 + me.timeLeft = 500; + me.friction = 0; + me.restitution = 1; + me.leaveBody = false; + me.isDropPowerUp = false; + //me.inertia = Infinity; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet | cat.player | cat.map | cat.body; + let index = 0; + me.do = function () { + this.timeLimit(); + this.alwaysSeePlayer() + this.force.y += this.mass * 0.0012; + } + } + const normalBullet = function (x, y, radius = 9, sides = 3) { + //bullets + mobs.spawn(x, y, sides, radius, "rgba(0,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + me.onHit = function () { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 20, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + }; + Matter.Body.setDensity(me, 0.00004); //normal is 0.001 + me.timeLeft = 220; + me.frictionAir = -0.01; + me.restitution = -1; + me.leaveBody = false; + me.isDropPowerUp = false; + //me.inertia = Infinity; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = null; + let index = 0; + me.do = function () { + this.timeLimit(); + this.alwaysSeePlayer() + const setNoseShape = () => { + const mag = this.radius + this.radius * 10; + this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag; + const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x); + Matter.Body.setAngle(this, angle); + }; + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[1], this.position)), radius * 1000) + this.vertices[1].x = this.position.x + spike.x / 100 + this.vertices[1].y = this.position.y + spike.y / 100 + if (index == 0) { + setNoseShape(); + index++; + } + if (Matter.Query.collides(this, map).length > 0 || Matter.Query.collides(this, body).length > 0) { + const slow = 0.69 //im sorry it looks cool though + Matter.Body.setVelocity(this, { + x: this.velocity.x * slow, + y: this.velocity.y * slow + }); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 10, + color: '#000000', + time: simulation.drawTime + }); + if (this.velocity.x == 0 && this.velocity.y == 0) { + this.death(); + } + this.frictionAir += 0.0001; + Matter.Body.setAngularVelocity(this, 0) + } + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles // I wasnt gonna add this but since ya'll would have killed me if I didn't I added this + const dmg = 0.013 * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.sqrt(dmg) * 200, + color: '#000000', + time: simulation.drawTime + }); + } + }; + } + const foamBullet = function (x, y, radius = 9, sides = 70) { //bullets + mobs.spawn(x, y, sides, radius, "rgb(0,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.00005); //normal is 0.001 + me.timeLeft = 120; + // me.g = 0.0005; //required if using this.gravity + me.accelMag = 0.00006; + me.isVerticesChange = true + me.delay = 360 * simulation.CDScale; + me.spikeVertex = 0; + me.spikeLength = 0; + me.isSpikeGrowing = false; + me.spikeGrowth = 0; + me.isSpikeReset = false; + me.frictionAir = 0; + me.restitution = 0; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.isUnblockable = true; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.body //| cat.bullet;// | cat.player; + me.do = function () { + if (this.distanceToPlayer2() < 40000) { + this.force = Vector.mult(Vector.normalise(Vector.sub(player.position, this.position)), this.mass * 0.004) + const slow = 0.99999999999999999; + Matter.Body.setVelocity(this, { + x: this.velocity.x * slow, + y: this.velocity.y * slow + }); + } + // this.gravity(); + this.timeLimit(); + // for (let i = 0, len = this.vertices.length; i < len; i++) { + // const dist = Vector.sub(this.seePlayer.position, this.vertices[i]); + // const distMag = Vector.magnitude(dist); + // const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[i], this.position)), radius * distMag) + // this.vertices[i].x = this.position.x + spike.x / 100 + // this.vertices[i].y = this.position.y + spike.y / 100 + // } + if (this.radius < 50) { + const scale = 1.05; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + } + if (Matter.Query.collides(this, map).length > 0 || Matter.Query.collides(this, body).length > 0 && this.speed < 10) { + const slow = 0.97 + Matter.Body.setVelocity(this, { + x: this.velocity.x * slow, + y: this.velocity.y * slow + }); + const SCALE = 0.9 + Matter.Body.scale(this, SCALE, SCALE); + this.radius *= SCALE; + if (this.radius < 1) { + this.death() + } + } else { + this.attach(); + } + + }; + me.attach = function () { + if (Matter.Query.collides(this, [player]).length > 0) { + Matter.Body.setPosition(this, player.position) + if (player.speed > 2.5) Matter.Body.setVelocity(player, Vector.mult(player.velocity, 0.94)) + Matter.Body.setAngularVelocity(player, player.angularVelocity * 0.9); + m.damage(0.00003); //balanced? not sure + } + } + }; + + const orbital = function (who, radius, phase, speed, radius2) {//basically orbitBot + mobs.spawn(who.position.x, who.position.y, 8, 12, "rgba(0,0,0, 1)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.01); //normal is 0.001 + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.showHealthBar = false; + me.isOrbital = true; + me.isShielded = true + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet; //cat.player | cat.map | cat.body + me.do = function () { + //if host is gone + if (!who || !who.alive) { + this.death(); + return + } + //set orbit + const time = simulation.cycle * speed + phase + const orbit = { + x: Math.cos(time), + y: Math.sin(time) + } + Matter.Body.setPosition(this, Vector.add(Vector.add(who.position, who.velocity), Vector.mult(orbit, radius + radius2))) + //damage player + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + const dmg = 0.013 * simulation.dmgScale + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + //this.death(); + } + }; + } + const sniper = function (x, y, radius = 30) { + mobs.spawn(x, y, 8, radius, '#00000000'); + let me = mob[mob.length - 1]; + me.accelMag = 0.0003 + me.stroke = 'transparent'; + //me.isBoss = true; + me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; + me.frictionStatic = 0; + me.friction = 0; + me.seeAtDistance2 = 20000000 //14000 vision range + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.showHealthBar = false + Matter.Body.setDensity(me, 0.01) + me.fireDir = { x: 0, y: 0 } + me.seePlayerFreq = 0 + me.repulsionRange = 400000 + radius * radius; + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob | cat.mobBullet + me.do = function () { + this.seePlayerCheck(); + this.attraction(); + this.repulsion(); + this.search() + if (this.seePlayer.recall) { + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(0,255,255,0.7)"; + ctx.fillRect(x, y, w * this.health, h); + } + if (this.health < 1) { + this.health += 0.0005; //regen + } + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + if (this.seePlayer.recall > 0 && this.distanceToPlayer2() > this.repulsionRange) { + var grd2 = ctx.createLinearGradient(0, 0, -150, 0); + // grd2.addColorStop(0, 'rgba(255, 255, 155, 0.8)'); + // grd2.addColorStop(1, 'rgba(255, 200, 0, 0.1)'); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(-18, -25); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(-18, 25); + ctx.lineTo(-50 - 100 * Math.random(), 0); + ctx.fill(); + } else if (this.distanceToPlayer2() < this.repulsionRange) { + var grd2 = ctx.createLinearGradient(0, 0, 80, 0); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(20, -16); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(20, 16); + ctx.lineTo(35 + 43 * Math.random(), 0); + ctx.fill(); + } + ctx.restore() + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.beginPath(); //eye + ctx.arc(15, 0, 3.5, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(255, 0, 0, ${this.health * this.health})`; + ctx.fill() + ctx.restore() + //set direction to turn to fire + if (this.seePlayer.recall && !(simulation.cycle % 30)) { + this.seePlayer.recall -= 10; + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + spawn.sniperBullet(this.position.x, this.position.y, 7 + Math.ceil(this.radius / 15), 5); + const v = 10 + 8 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + }; + } + const laserEM = function (x, y, radius = 30) { + mobs.spawn(x, y, 8, radius, '#00000000'); + let me = mob[mob.length - 1]; + me.accelMag = 0.0003 + me.stroke = 'transparent'; + //me.isBoss = true; + me.frictionStatic = 0; + me.friction = 0; + me.seeAtDistance2 = 20000000 //14000 vision range + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.showHealthBar = false + Matter.Body.setDensity(me, 0.01) + me.seePlayerFreq = 0 + me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; + me.swordDamage = 0.025 * simulation.dmgScale + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob | cat.mobBullet + me.repulsionRange = 50000; + me.do = function () { + this.repulsion(); + this.search() + if (this.seePlayer.recall) { + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(0,255,255,0.7)"; + ctx.fillRect(x, y, w * this.health, h); + } + if (this.health < 1) { + this.health += 0.0005; //regen + } + if (this.seePlayer.recall) { + this.laserSword(this.position, Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x), 500 * Math.random()); + } + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + if (this.seePlayer.recall > 0 && this.distanceToPlayer2() > this.repulsionRange) { + var grd2 = ctx.createLinearGradient(0, 0, -150, 0); + // grd2.addColorStop(0, 'rgba(255, 255, 155, 0.8)'); + // grd2.addColorStop(1, 'rgba(255, 200, 0, 0.1)'); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(-18, -25); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(-18, 25); + ctx.lineTo(-50 - 100 * Math.random(), 0); + ctx.fill(); + } else if (this.distanceToPlayer2() < this.repulsionRange) { + var grd2 = ctx.createLinearGradient(0, 0, 80, 0); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(20, -16); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(20, 16); + ctx.lineTo(35 + 43 * Math.random(), 0); + ctx.fill(); + } + ctx.restore() + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.beginPath(); //eye + ctx.arc(15, 0, 3.5, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(255, 0, 0, ${this.health * this.health})`; + ctx.fill() + ctx.restore() + this.seePlayerCheck(); + this.attraction(); + } + me.laserSword = function (where, angle, length) { + const sub = Vector.sub(this.seePlayer.position, this.position) + const unit = Vector.normalise(sub) + const path = [{ + x: this.position.x + 20 * Math.cos(this.angle), + y: this.position.y + 20 * Math.sin(this.angle) + }, + { + x: this.position.x + (120 + 400) * Math.sqrt(Math.random()) * Math.cos(this.angle), + y: this.position.y + (120 + 400) * Math.sqrt(Math.random()) * Math.sin(this.angle) + } + ]; + this.seePlayer.recall -= 3; + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: vertices[j], v2: vertices[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: vertices[0], v2: vertices[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + length * Math.cos(angle), y: where.y + length * Math.sin(angle) }; + // vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [player]); + if (best.who && (best.who === player) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "#50f"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(80,0,255,0.07)"; + ctx.stroke(); // Draw it + + const Dx = Math.cos(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)); + const Dy = Math.sin(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)); + let xElec = this.position.x + 40 * Dx; + let yElec = this.position.y + 40 * Dy; + ctx.beginPath(); + ctx.moveTo(xElec, yElec); + const step = 40 + for (let i = 0; i < 6; i++) { + xElec += step * (Dx + 1.5 * (Math.random() - 0.5)) + yElec += step * (Dy + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(xElec, yElec); + } + ctx.strokeStyle = "#50f"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }; + if (powerUps.pass == undefined) { + let pass = { pass: true, activated: false }; + Object.assign(powerUps, pass) + } + const loadOut = { + loadOut: { + name: "loadOut", + color: "#000000", //"hsl(248,100%,65%)", + size() { return 40 }, + effect() { + if (m.alive) { + // tech.damage *= 2; + let text = ""; + if (!tech.isSuperDeterminism) { text += `
${(tech.isCancelTech && tech.cancelTechCount === 0) ? "?" : "✕"}
`; }; + text += `

Blessing Of Sal

`; + text += `
  Speed Boost
Increase speed by 5%
`; + text += `
  Defense Boost
Reduce damage by 5%
`; + text += `
  Damage Boost
Increase damage by 10%
`; + if (powerUps.pass == true) { + text += `
  Blade of Sal
Press Shift to summon the Mythical Las Slayer
Drains Energy
`; + } + document.getElementById("choose-grid").innerHTML = text; + powerUps.showDraft();//no known bugs ig idk, im keep this as it is + } + }, + choose(index) { + if (index == 1) { + m.squirrelFx += 0.25; + m.squirrelJump += 0.1; + m.setMovement(); + powerUps.endDraft("buff"); + } else if (index == 2) { + simulation.dmgScale *= 0.95; + powerUps.endDraft("buff"); + } else if (index == 3) { + m.dmgScale *= 1.1; + powerUps.endDraft("buff"); + } else if (index == 4) { //sword! + powerUps.pass = false; + addEventListener("keydown", function (event) { + if (event.key == "Shift" && powerUps.activated == false) { + sword() + powerUps.activated = true; + } else if (event.key == "Shift" && powerUps.activated == true) { + for (let i = 0; i < mob.length; i++) { + if (mob[i].isSword) { + mob[i].death() + } + powerUps.activated = false; + } + } + }) + powerUps.endDraft("buff"); + } + } + } + } + Object.assign(powerUps, loadOut) + const restoreBoss = function (x, y, radius = 30) { + mobs.spawn(x, y, 8, radius, 'transparent'); + let me = mob[mob.length - 1]; + me.stroke = 'transparent'; + let aim = '#FFFFFF'; + me.accelMag = 0.0006 + me.isBoss = true; + me.restoreBoss = true; + me.frictionStatic = 0; + me.friction = 0; + me.seeAtDistance2 = 20000000 //14000 vision range + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.showHealthBar = false + Matter.Body.setDensity(me, m.maxHealth / (simulation.difficulty < 5 ? 0.5 : simulation.difficulty / simulation.difficultyMode)) + me.seePlayerFreq = 0 + me.swordDamage = 0.025 * simulation.dmgScale + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob | cat.mobBullet + me.repulsionRange = 500000; + me.isDropPowerUp = false; + //Matter.Body.setVelocity(me, { x: 10 * (Math.random() - 0.5), y: 10 * (Math.random() - 0.5) }); + let index = 0; + me.energy = 1; + me.maxEnergy = 1; + me.immuneCycle = 0; + me.cycle = 0; + me.onDeath = function () { + powerUps.spawn(this.position.x, this.position.y, "loadOut"); + } + for (let i = 0; i < b.totalBots(); i++) { //normal orbitals look too boring, so... + orbital(me, 190 + 130 * tech.isOrbitBotUpgrade, (index / b.totalBots()) * 2 * Math.PI, 0.05, Math.floor(Math.sin(simulation.cycle / 10) * 100)); //who, radius, phase, speed + index++; + } + me.do = function () { + this.cycle++; + if (this.seePlayer.recall) { //fields + if (m.fieldMode == 0 && this.distanceToPlayer2() < 200000) { + if (Vector.magnitude(Vector.sub(m.pos, this.position)) - this.radius < m.fieldRange && Matter.Query.ray(map, m.pos, this.position).length === 0) { + this.pushM(); + } + this.drawField(); + // this.repel(); + } + if (m.fieldMode == 2) { + if (this.distanceToPlayer2() < 200000) { + if (Vector.magnitude(Vector.sub(m.pos, this.position)) - this.radius < m.fieldRange && Matter.Query.ray(map, m.pos, this.position).length === 0) { + this.pushM(); + } + this.drawField() + } + if (tech.isPerfectBrake) { //cap player and bullet speed around restoreBoss //mobs basically can't hit you when you have this, so to make it fair... + const wave = Math.cos(m.cycle * 0.022); + const range = 200 + 140 * wave + 150 * m.energy + const distance = Vector.magnitude(Vector.sub(this.position, m.pos)) + const cap = this.immuneCycle > this.cycle ? 8 : 4 + if (distance < range) { + if (player.speed > cap && Vector.dot(player.velocity, Vector.sub(this.position, m.pos)) > 0) { // if velocity is directed towards player + Matter.Body.setVelocity(player, Vector.mult(Vector.normalise(player.velocity), cap)); //set velocity to cap, but keep the direction + } + } + for (let i = 0; i < bullet.length; i++) { + const distance2 = Vector.magnitude(Vector.sub(this.position, bullet[i].position)) + if (distance2 < range) { + if (bullet[i].speed > cap && Vector.dot(bullet[i].velocity, Vector.sub(this.position, bullet[i].position)) > 0) { // if velocity is directed towards player + Matter.Body.setVelocity(bullet[i], Vector.mult(Vector.normalise(bullet[i].velocity), cap)); //set velocity to cap, but keep the direction + } + } + } + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, range, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.08)"; + ctx.fill(); + } + } + if (m.fieldMode == 5 && this.distanceToPlayer2() < 200000) { + this.laserSword(this.position, Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x), 500 * Math.random()); + } + if (m.fieldMode == 6) { + this.timeAttack(); + } + if (m.fieldMode == 9) { + if (this.distanceToPlayer2() < 300000) { + this.teleportAway() //blink but reversed + } + } + } + if (m.immuneCycle > m.cycle) { + me.damageReduction = 0; + } else { + me.damageReduction = 1; + } + this.repulsion(); + this.seePlayerCheck(); + this.attraction(); + this.lostPlayer(); + if (this.seePlayer.recall) { + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(10, 10, 10, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(0,0,0,0.7)"; + ctx.fillRect(x, y, w * this.energy, h); + } + if (this.health < 1) { + this.health += 0.0001; //regen + } else if (this.health < 1) { + this.health += 0.00005; //reduced regen + } + if (this.energy < 0) {//energy thingy + this.energy = 0; + } else if (this.energy > this.maxEnergy) { + this.energy = this.maxEnergy; + } else if (this.energy < this.maxEnergy) { + this.energy += 0.001; + } + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + if (this.seePlayer.recall > 0 && this.distanceToPlayer2() > this.repulsionRange) { + ctx.globalAlpha = (this.immuneCycle < this.cycle) ? 1 : 0.5 + var grd2 = ctx.createLinearGradient(0, 0, -150, 0); + // grd2.addColorStop(0, 'rgba(255, 255, 155, 0.8)'); + // grd2.addColorStop(1, 'rgba(255, 200, 0, 0.1)'); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(-18, -25); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(-18, 25); + ctx.lineTo(-50 - 100 * Math.random(), 0); + ctx.fill(); + } else if (this.distanceToPlayer2() < this.repulsionRange) { + ctx.globalAlpha = (this.immuneCycle < this.cycle) ? 1 : 0.5 + var grd2 = ctx.createLinearGradient(0, 0, 80, 0); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(20, -16); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(20, 16); + ctx.lineTo(35 + 43 * Math.random(), 0); + ctx.fill(); + } + ctx.restore() + ctx.save() + ctx.globalAlpha = (this.immuneCycle < this.cycle) ? 1 : 0.5 + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + if (this.health > 0.5) { + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.beginPath(); //eye + ctx.arc(15, 0, 3.5, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(255, 0, 0, ${this.health * this.health})`; + ctx.fill() + ctx.restore() + } else { + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + if (!(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) > -Math.PI / 2 && Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) < Math.PI / 2)) ctx.scale(1, -1); //here is the flip + ctx.stroke(); + ctx.beginPath(); + ctx.arc(2, -6, 7, 0, 2 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(25, -6, 7, 0.25 * Math.PI, 1.6 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(2, -10, 9, 1.25 * Math.PI, 1.75 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(25, -10, 9, 1.25 * Math.PI, 1.4 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(18, 13, 10, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient; + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(18, 13, 6, 0, 2 * Math.PI); + ctx.fillStyle = "#555"; + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(3, -6, 3, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(26, -6, 3, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + } + if (m.fieldMode == 1) { //render over I think + if (this.energy > 0.1) { + this.harmonic3Phase(); + } + } + if (m.fieldMode == 3) { + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + me.damageReduction = 0.5; + me.accelMag = 0.0012; + if (!(simulation.cycle % Math.floor(100 + 90 * Math.random() * simulation.CDScale))) { + this.diveAttack() + } + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, 1000, 0, 2 * Math.PI); + ctx.fillStyle = "#f5f5ff"; + ctx.strokeStyle = "#f5f5ff55"; + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + ctx.globalCompositeOperation = "difference"; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + ctx.stroke() + ctx.setLineDash([]); + } else { + me.accelMag = 0.0006; + } + if (this.immuneCycle > this.cycle) { + this.damageReduction = 0; + } else { + if (m.fieldMode == 3) { + this.damageReduction = 0.5; + } else { + this.damageReduction = 1; + } + } + if (this.seePlayer.recall) { //fields + this.gun() + } + } + me.laserSword = function (where, angle, length) { + const sub = Vector.sub(this.seePlayer.position, this.position) + const unit = Vector.normalise(sub) + const path = [{ + x: this.position.x + 20 * Math.cos(this.angle), + y: this.position.y + 20 * Math.sin(this.angle) + }, + { + x: this.position.x + (120 + 400) * Math.sqrt(Math.random()) * Math.cos(this.angle), + y: this.position.y + (120 + 400) * Math.sqrt(Math.random()) * Math.sin(this.angle) + } + ]; + this.seePlayer.recall -= 3; + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: vertices[j], v2: vertices[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: vertices[0], v2: vertices[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + length * Math.cos(angle), y: where.y + length * Math.sin(angle) }; + // vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [player]); + if (best.who && (best.who === player) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(0,0,0,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(0,0,0,0.07)"; + ctx.stroke(); // Draw it + + const Dx = Math.cos(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)); + const Dy = Math.sin(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)); + let xElec = this.position.x + 40 * Dx; + let yElec = this.position.y + 40 * Dy; + ctx.beginPath(); + ctx.moveTo(xElec, yElec); + const step = 40 + for (let i = 0; i < 6; i++) { + xElec += step * (Dx + 1.5 * (Math.random() - 0.5)) + yElec += step * (Dy + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(xElec, yElec); + } + ctx.strokeStyle = "#000"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + me.drawField = function () { + if (m.fieldMode != 2) { + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) + const range = m.fieldRange; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, range, angle - Math.PI * m.fieldArc, angle + Math.PI * m.fieldArc, false); + ctx.lineWidth = 2; + ctx.stroke(); + let eye = 13; + if (m.fieldMode == 2) { + eye = 30 + } + let aMag = 0.75 * Math.PI * m.fieldArc + let a = angle + aMag + let cp1x = this.position.x + 0.6 * range * Math.cos(a) + let cp1y = this.position.y + 0.6 * range * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, this.position.x + eye * Math.cos(angle), this.position.y + eye * Math.sin(angle)) + a = angle - aMag + cp1x = this.position.x + 0.6 * range * Math.cos(a) + cp1y = this.position.y + 0.6 * range * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, this.position.x + 1 * range * Math.cos(angle - Math.PI * m.fieldArc), this.position.y + 1 * range * Math.sin(angle - Math.PI * m.fieldArc)) + ctx.fill(); + // ctx.lineTo(this.position.x + eye * Math.cos(angle), this.position.y + eye * Math.sin(angle)); + + //draw random lines in field for cool effect + let offAngle = angle + 1.7 * Math.PI * m.fieldArc * (Math.random() - 0.5); + ctx.beginPath(); + eye = 15; + ctx.moveTo(this.position.x + eye * Math.cos(angle), this.position.y + eye * Math.sin(angle)); + ctx.lineTo(this.position.x + range * Math.cos(offAngle), this.position.y + range * Math.sin(offAngle)); + ctx.strokeStyle = "rgba(0,0,0,0.6)"; + ctx.lineWidth = 1; + ctx.stroke(); + } else { + ctx.beginPath(); + const wave = Math.cos(m.cycle * 0.022); + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) + ctx.arc(this.position.x, this.position.y, m.fieldRange, angle - Math.PI * m.fieldArc, angle + Math.PI * m.fieldArc, false); + ctx.lineWidth = 2.5 - 1.5 * wave; + ctx.stroke(); + const curve = 0.57 + 0.04 * wave + const aMag = (1 - curve * 1.2) * Math.PI * m.fieldArc + let a = angle + aMag + let cp1x = this.position.x + curve * m.fieldRange * Math.cos(a) + let cp1y = this.position.y + curve * m.fieldRange * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, this.position.x + 30 * Math.cos(angle), this.position.y + 30 * Math.sin(angle)) + a = angle - aMag + cp1x = this.position.x + curve * m.fieldRange * Math.cos(a) + cp1y = this.position.y + curve * m.fieldRange * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, this.position.x + 1 * m.fieldRange * Math.cos(angle - Math.PI * m.fieldArc), this.position.y + 1 * m.fieldRange * Math.sin(angle - Math.PI * m.fieldArc)) + ctx.fill(); + } + } + me.pushM = function () { + const unit = Vector.normalise(Vector.sub(this.position, player.position)) + if (tech.blockDmg) { + Matter.Body.setVelocity(player, { x: 0.5 * player.velocity.x, y: 0.5 * player.velocity.y }); + //draw electricity + const step = 40 + ctx.beginPath(); + for (let i = 0, len = 0.8 * tech.blockDmg; i < len; i++) { + let x = this.position.x - 20 * unit.x; + let y = this.position.y - 20 * unit.y; + ctx.moveTo(x, y); + for (let i = 0; i < 8; i++) { + x += step * (-unit.x + 1.5 * (Math.random() - 0.5)) + y += step * (-unit.y + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + } + if (m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + m.damage(0.025 * simulation.dmgScale) + } + ctx.lineWidth = 3; + ctx.strokeStyle = "#000"; + ctx.stroke(); + } + const massRoot = Math.sqrt(Math.min(12, Math.max(0.15, player.mass))); // masses above 12 can start to overcome the push back //idk + Matter.Body.setVelocity(player, { + x: this.velocity.x - (15 * unit.x) / massRoot, + y: this.velocity.y - (15 * unit.y) / massRoot + }); + } + me.diveAttack = function () { + const forceMag = this.accelMag * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x += 150 * forceMag * Math.cos(angle); + this.force.y += 150 * forceMag * Math.sin(angle); + ctx.beginPath() + ctx.moveTo(this.position.x + Math.sin(angle), this.position.y + Math.cos(angle)) + ctx.lineTo(this.seePlayer.position.x, this.seePlayer.position.y) + aim = '#000000'; + ctx.stroke() + } + me.teleportAway = function () {//hehe + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + if (this.seePlayer.recall && !(simulation.cycle % 17)) { + const dist = Vector.sub(this.position, this.seePlayer.position); + const distMag = Vector.magnitude(dist); + const unitVector = Vector.normalise(dist); + const rando = (Math.random() - 0.5) * 50; + if (distMag < 20000) { + Matter.Body.translate(this, Vector.mult(unitVector, distMag + rando)); + } else { + Matter.Body.translate(this, Vector.mult(unitVector, 20000 + rando)); + } + } + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = radius * 2; + ctx.strokeStyle = "rgba(0,0,0,0.08)"; + ctx.stroke(); + if (!this.seePlayer.yes) { + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + if (this.seePlayer.recall && !(simulation.cycle % 17)) { + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + const unitVector = Vector.normalise(dist); + const rando = (Math.random() - 0.5) * 50; + if (distMag < 200000) { + Matter.Body.translate(this, Vector.mult(unitVector, distMag + rando)); + } else { + Matter.Body.translate(this, Vector.mult(unitVector, 200000 + rando)); + } + } + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = radius * 2; + ctx.strokeStyle = "rgba(0,0,0,0.08)"; + ctx.stroke(); + } + } + me.timeAttack = function () { + if (!simulation.isTimeSkipping || input.field) { + requestAnimationFrame(() => { + simulation.timePlayerSkip(5) + m.walk_cycle += m.flipLegs * m.Vx * 5 + }); //just doing what lilgreenland did + } + } + me.harmonic3Phase = function () { //normal standard 3 different 2-d circles + if (tech.harmonics === 2) { + const fieldRange1 = (0.75 + 0.3 * Math.cos(m.cycle / 23)) * m.fieldRange * m.harmonicRadius + const fieldRange2 = (0.68 + 0.37 * Math.cos(m.cycle / 37)) * m.fieldRange * m.harmonicRadius + const fieldRange3 = (0.7 + 0.35 * Math.cos(m.cycle / 47)) * m.fieldRange * m.harmonicRadius + const netfieldRange = Math.max(fieldRange1, fieldRange2, fieldRange3) + ctx.fillStyle = "rgba(0,0,0," + Math.min(0.6, (0.04 + m.energy * (0.1 + 0.11 * Math.random()))) + ")"; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, fieldRange1, 0, 2 * Math.PI); + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, fieldRange2, 0, 2 * Math.PI); + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, fieldRange3, 0, 2 * Math.PI); + ctx.fill(); + //360 block + if (Vector.magnitude(Vector.sub(player.position, this.position)) - this.radius < netfieldRange) { + me.pushM(); + } + for (let i = 0; i < bullet.length; i++) { + if (Vector.magnitude(Vector.sub(bullet[i].position, this.position)) - this.radius < netfieldRange) { + const dx = bullet[i].position.x - this.position.x; + const dy = bullet[i].position.y - this.position.y; + const dist = Math.sqrt(dx * dx + dy * dy); + if (dist < m.fieldRange) { + const angle = Math.atan2(dy, dx); + const mag = (1500 * bullet[i].mass * simulation.g) / dist; + bullet[i].force.x += mag * Math.cos(angle); + bullet[i].force.y += mag * Math.sin(angle); + } + this.energy -= 0.0012; + } + } + } else { + const rotation = simulation.cycle * 0.0031 + const phase = simulation.cycle * 0.023 + const radius = m.fieldRange * m.harmonicRadius + ctx.lineWidth = 1; + ctx.strokeStyle = "rgba(0,0,0,0.5)" + ctx.fillStyle = `rgba(0,0,0,${Math.min(0.6, m.energy * (0.11 + 0.1 * Math.random()) * (3 / tech.harmonics))})`; + // ctx.fillStyle = "rgba(0,0,0," + Math.min(0.7, m.energy * (0.22 - 0.01 * tech.harmonics) * (0.5 + 0.5 * Math.random())) + ")"; + for (let i = 0; i < tech.harmonics; i++) { + ctx.beginPath(); + ctx.ellipse(this.position.x, this.position.y, radius * Math.abs(Math.sin(phase + i / tech.harmonics * Math.PI)), radius, rotation + i / tech.harmonics * Math.PI, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + } + //360 block + if (Vector.magnitude(Vector.sub(player.position, this.position)) - this.radius < radius) { + me.pushM(); + } + for (let i = 0; i < bullet.length; i++) { + if (Vector.magnitude(Vector.sub(bullet[i].position, this.position)) - this.radius < radius) { + const dx = bullet[i].position.x - this.position.x; + const dy = bullet[i].position.y - this.position.y; + const dist = Math.sqrt(dx * dx + dy * dy); + if (dist < m.fieldRange) { + const angle = Math.atan2(dy, dx); + const mag = (1500 * bullet[i].mass * simulation.g) / dist; + bullet[i].force.x += mag * Math.cos(angle); + bullet[i].force.y += mag * Math.sin(angle); + } + this.energy -= 0.0012; + } + } + } + } + me.railGun = function () { + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + const X = this.position.x + const Y = this.position.y + const unitVector = { x: Math.cos(angle), y: Math.sin(angle) } + const unitVectorPerp = Vector.perp(unitVector) + + function magField(mag, arc) { + ctx.moveTo(X, Y); + ctx.bezierCurveTo( + X + unitVector.x * mag, Y + unitVector.y * mag, + X + unitVector.x * mag + unitVectorPerp.x * arc, Y + unitVector.y * mag + unitVectorPerp.y * arc, + X + unitVectorPerp.x * arc, Y + unitVectorPerp.y * arc) + ctx.bezierCurveTo( + X - unitVector.x * mag + unitVectorPerp.x * arc, Y - unitVector.y * mag + unitVectorPerp.y * arc, + X - unitVector.x * mag, Y - unitVector.y * mag, + X, Y) + } + ctx.fillStyle = `rgba(50,0,100,0.05)`; + const magSize = 8 * c * tech.railChargeRate ** 3 + const arcSize = 6 * c * tech.railChargeRate ** 3 + for (let i = 3; i < 7; i++) { + const MAG = magSize * i * i * (0.93 + 0.07 * Math.random()) + const ARC = arcSize * i * i * (0.93 + 0.07 * Math.random()) + ctx.beginPath(); + magField(MAG, ARC) + magField(MAG, -ARC) + ctx.fill(); + } + } + me.waves = []; + me.doLongitudinal = function () { + if (!m.isTimeDilated) { + ctx.strokeStyle = "rgba(0,0,0,0.6)" //"000"; + ctx.lineWidth = 2 * tech.wavePacketDamage + ctx.beginPath(); + // const end = 1100 * tech.bulletsLastLonger / Math.sqrt(tech.waveReflections * 0.5) //should equal about 1767 + const end = 1100 * tech.bulletsLastLonger * Math.pow(0.93, tech.waveReflections) //should equal about 1767 + const damage = 0.0005 * simulation.dmgScale//normal damage for m basically shreds m, so had to nerf this + for (let i = this.waves.length - 1; i > -1; i--) { + const v1 = Vector.add(this.waves[i].position, Vector.mult(this.waves[i].unit1, this.waves[i].radius)) + const v2 = Vector.add(this.waves[i].position, Vector.mult(this.waves[i].unit2, this.waves[i].radius)) + //draw wave + ctx.moveTo(v1.x, v1.y) + ctx.arc(this.waves[i].position.x, this.waves[i].position.y, this.waves[i].radius, this.waves[i].angle, this.waves[i].angle + this.waves[i].arc); + //using small angle linear approximation of circle arc, this will not work if the arc gets large // https://stackoverflow.com/questions/13652518/efficiently-find-points-inside-a-circle-sector + let hits = Matter.Query.ray([player], v1, v2, 50) //Matter.Query.ray(bodies, startPoint, endPoint, [rayWidth]) + for (let j = 0, len = Math.min(30, hits.length); j < len; j++) { + player.force.x += 0.01 * (Math.random() - 0.5) * player.mass + player.force.y += (0.01 * (Math.random() - 0.5) - simulation.g * 0.25) * player.mass //remove force of gravity + Matter.Body.setVelocity(player, { //friction + x: player.velocity.x * 0.95, + y: player.velocity.y * 0.95 + }); + m.damage(damage) + } + hits = Matter.Query.ray(body, v1, v2, 50) + for (let j = 0, len = Math.min(30, hits.length); j < len; j++) { + const who = hits[j].body + //make them shake around + who.force.x += 0.01 * (Math.random() - 0.5) * who.mass + who.force.y += (0.01 * (Math.random() - 0.5) - simulation.g * 0.25) * who.mass //remove force of gravity + + let vertices = who.vertices; + const vibe = 25 + ctx.moveTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x + vibe * (Math.random() - 0.5), vertices[j].y + vibe * (Math.random() - 0.5)); + } + ctx.lineTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + + if (tech.isPhononBlock && !who.isNotHoldable && who.speed < 5 && who.angularSpeed < 0.1) { + if (Math.random() < 0.5) b.targetedBlock(who, 50 - Math.min(25, who.mass * 3)) // targetedBlock(who, speed = 50 - Math.min(20, who.mass * 2), range = 1600) { + // Matter.Body.setAngularVelocity(who, (0.25 + 0.12 * Math.random()) * (Math.random() < 0.5 ? -1 : 1)); + who.torque += who.inertia * 0.001 * (Math.random() - 0.5) + } + } + // ctx.stroke(); //draw vibes + this.waves[i].radius += tech.waveBeamSpeed * 1.8 * this.waves[i].expanding //expand / move + if (this.waves[i].radius > end - 30) { + this.waves[i].expanding = -1 + if (this.waves[i].reflection < 1) this.waves.splice(i, 1) //end + } else if (this.waves[i].radius < 25) { + this.waves[i].expanding = 1 + if (this.waves[i].reflection < 1) this.waves.splice(i, 1) //end + } + } + ctx.stroke(); + } + } + me.lasers = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[j], + v2: vertices[j + 1] + }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[0], + v2: vertices[len] + }; + } + } + }; + + const seeRange = 7000; + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { + x: where.x + seeRange * Math.cos(angle), + y: where.y + seeRange * Math.sin(angle) + }; + // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + vertexCollision(where, look, body); + if (!m.isCloak) vertexCollision(where, look, [player]); + if (best.who && (best.who === player) && m.immuneCycle < m.cycle) { + const dmg = 0.0011 * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + //draw beam + if (best.dist2 === Infinity) best = look; + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.lineWidth = 10; + ctx.stroke(); + } + me.pulse = function (charge, angle, where = this.position) { + let best; + angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) + let explosionRadius = 5.5 * charge + let range = 5000 + const path = [{ + x: where.x + 20 * Math.cos(angle), + y: where.y + 20 * Math.sin(angle) + }, + { + x: where.x + range * Math.cos(angle), + y: where.y + range * Math.sin(angle) + } + ]; + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[j], + v2: vertices[j + 1] + }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[0], + v2: vertices[len] + }; + } + } + }; + //check for collisions + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + if (!best.who) { + vertexCollision(path[0], path[1], body); + vertexCollision(path[0], path[1], [player]); + vertexCollision(path[0], path[1], map); + if (best.dist2 != Infinity) { //if hitting something + path[path.length - 1] = { + x: best.x, + y: best.y + }; + } + } + if (best.who) { + b.explosion(path[1], explosionRadius, "rgba(0,0,0,0)") + const off = explosionRadius * 1.2 + b.explosion({ x: path[1].x + off * (Math.random() - 0.5), y: path[1].y + off * (Math.random() - 0.5) }, explosionRadius, "rgba(0,0,0,0.7)") + b.explosion({ x: path[1].x + off * (Math.random() - 0.5), y: path[1].y + off * (Math.random() - 0.5) }, explosionRadius, "rgba(0,0,0,0.7)") + } + //draw laser beam + ctx.beginPath(); + ctx.moveTo(path[0].x, path[0].y); + ctx.lineTo(path[1].x, path[1].y); + if (charge > 50) { + ctx.strokeStyle = "rgba(0,0,0,0.10)" + ctx.lineWidth = 70 + ctx.stroke(); + } + ctx.strokeStyle = "rgba(0,0,0,0.25)" + ctx.lineWidth = 20 + ctx.stroke(); + ctx.strokeStyle = "#f00"; + ctx.lineWidth = 4 + ctx.stroke(); + + //draw little dots along the laser path + const sub = Vector.sub(path[1], path[0]) + const mag = Vector.magnitude(sub) + for (let i = 0, len = Math.floor(mag * 0.0005 * charge); i < len; i++) { + const dist = Math.random() + simulation.drawList.push({ + x: path[0].x + sub.x * dist + 10 * (Math.random() - 0.5), + y: path[0].y + sub.y * dist + 10 * (Math.random() - 0.5), + radius: 1.5 + 5 * Math.random(), + color: "rgba(0,0,0,0.5)", + time: Math.floor(9 + 25 * Math.random() * Math.random()) + }); + } + } + let c = 0 + me.gun = function () { + if (b.activeGun == 0) {// nailgun + if (this.seePlayer.recall && !(simulation.cycle % 20)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + normalBullet(this.position.x, this.position.y); + const v = 10 + 8 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } + if (b.activeGun == 1) {// shotgun + if (this.seePlayer.recall && !(simulation.cycle % 90)) { + const side = 22 + for (let i = 0; i < 12; i++) { + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + const dir = angle + (Math.random() - 0.5) * 1 + const SPEED = 52 + Math.random() * 8 + normalBullet(this.position.x + 35 * Math.cos(angle) + 15 * (Math.random() - 0.5), this.position.y + 35 * Math.sin(angle) + 15 * (Math.random() - 0.5)) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: SPEED * Math.cos(dir), + y: SPEED * Math.sin(dir) + }); + } + } + } else if (b.activeGun == 2) { // super balls + if (this.seePlayer.recall && !(simulation.cycle % 20)) { + const num = 3; + const SPREAD = 0.13; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + let dir = angle - SPREAD * (num - 1) / 2; + const SPEED = 33 + for (let i = 0; i < num; i++) { + ball(this.position.x + 30 * Math.cos(angle), this.position.y + 30 * Math.sin(angle)) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: SPEED * Math.cos(dir), + y: SPEED * Math.sin(dir) + }); + dir += SPREAD + } + } + } else if (b.activeGun == 3) { // wave + this.doLongitudinal() + const halfArc = 0.275 + const anglex = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + const angle = anglex + 0.3 * (Math.random() - 0.5) + this.waves.push({ + position: { + x: this.position.x + 25 * Math.cos(anglex), + y: this.position.y + 25 * Math.sin(anglex), + }, + angle: angle - halfArc, //used in drawing ctx.arc + unit1: { x: Math.cos(angle - halfArc), y: Math.sin(angle - halfArc) }, //used for collision + unit2: { x: Math.cos(angle + halfArc), y: Math.sin(angle + halfArc) }, //used for collision + arc: halfArc * 2, + radius: 25, + reflection: 0, + expanding: 1, + resonanceCount: 0 + }) + } else if (b.activeGun == 4) { // missiles + + } else if (b.activeGun == 5) { // grenades + + } else if (b.activeGun == 6) { // spores + if (this.seePlayer.recall && !(simulation.cycle % 30)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + me.drop(this.position.x, this.position.y) + const v = 10 + 8 * simulation.accelScale + (Math.random() * 20 - Math.random() * 20); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } else if (b.activeGun == 7) { // drones + + } else if (b.activeGun == 8) { // foam + if (this.seePlayer.recall && !(simulation.cycle % 1)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + foamBullet(this.position.x, this.position.y, 7 + Math.ceil(this.radius / 15), 69); + const v = 10 + 8 * simulation.accelScale + (Math.random() * 20 - Math.random() * 20); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } else if (b.activeGun == 9) { // harpoon - railgun + if (c > 1) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + this.railBullet(this.position.x, this.position.y); + const v = 10 + 80 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + c = 0; + } else { + c += 0.02; + this.railGun(); + } + } else if (b.activeGun == 10) { // laserMines + if (this.seePlayer.recall && !(simulation.cycle % 100)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + me.laserMine(this.position.x, this.position.y) + const v = 10 + 8 * simulation.accelScale + (Math.random() * 20 - Math.random() * 20); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } else if (b.activeGun == 11) { // laser - pulse + //this.lasers(this.position, Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + //if (this.seePlayer.recall && !(simulation.cycle % 20)) { + if (c > 1) { + this.pulse(c * 100) + c = 0; + } else { + if (this.energy < 1 || this.energy > 0.5) { + c += 0.01; + ctx.beginPath(); + const mag = Math.sqrt(c) + ctx.arc(this.position.x, this.position.y, c * 30, 0, 2 * Math.PI) + ctx.fillStyle = '#000000' + ctx.strokeStyle = 'transparent' + ctx.fill(); + ctx.stroke(); + this.energy -= 0.01; + ctx.strokeStyle = "#000000"; + ctx.lineWidth = 1.5 + // ctx.globalAlpha = 1; + } else { + c = 0; + this.energy += 0.1 + } + } + //} + } + } + me.railBullet = function (x, y) { + mobs.spawn(x, y, 5, 20, "black"); + let xy = mob[mob.length - 1]; + xy.stroke = "black"; + xy.vertices = Matter.Vertices.rotate(xy.vertices, Math.PI, xy.position); + xy.onHit = function () { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 20, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + }; + Matter.Body.setDensity(xy, 0.00004); //normal is 0.001 + xy.timeLeft = 220; + xy.frictionAir = -0.01; + xy.restitution = -1; + xy.leaveBody = false; + xy.isDropPowerUp = false; + //xy.inertia = Infinity; + xy.isBadTarget = true; + xy.isMobBullet = true; + xy.showHealthBar = false; + xy.collisionFilter.category = cat.mobBullet; + xy.collisionFilter.mask = cat.player; + let index = 0; + xy.do = function () { + this.timeLimit(); + this.alwaysSeePlayer() + const setNoseShape = () => { + const mag = this.radius + this.radius * 10; + const angle = Math.atan2(me.seePlayer.position.y - this.position.y, me.seePlayer.position.x - this.position.x); + this.vertices[2].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[2].y = this.position.y + Math.sin(this.angle) * mag; + this.vertices[4].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[4].y = this.position.y + Math.sin(this.angle) * mag; + this.vertices[0].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[0].y = this.position.y + Math.sin(this.angle) * mag; + Matter.Body.setAngle(this, angle); + }; + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[2], this.position)), radius * 1000) + const spike2 = Vector.mult(Vector.normalise(Vector.sub(this.vertices[4], this.position)), radius * 1000) + const spike3 = Vector.mult(Vector.normalise(Vector.sub(this.vertices[0], this.position)), radius * 1000) + this.vertices[2].x = this.position.x + spike.x / 100 + this.vertices[2].y = this.position.y + spike.y / 100 + this.vertices[4].x = this.position.x + spike2.x / 75 + this.vertices[4].y = this.position.y + spike2.y / 75 + this.vertices[0].x = this.position.x + spike3.x / 75 + this.vertices[0].y = this.position.y + spike3.y / 75 + if (index == 0) { + setNoseShape(); + index++; + } + if (Matter.Query.collides(this, map).length > 0 || Matter.Query.collides(this, body).length > 0) { + const slow = 0.69 //im sorry it looks cool though + Matter.Body.setVelocity(this, { + x: this.velocity.x * slow, + y: this.velocity.y * slow + }); + // simulation.drawList.push({ //add dmg to draw queue + // x: this.position.x, + // y: this.position.y, + // radius: 10, + // color: '#000000', + // time: simulation.drawTime + // }); + if (this.velocity.x == 0 && this.velocity.y == 0) { + this.death(); + } + this.frictionAir += 0.0001; + Matter.Body.setAngularVelocity(this, 0) + } + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles // I wasnt gonna add this but since ya'll would have killed me if I didn't I added this + const dmg = 0.013 * simulation.dmgScale; + m.damage(dmg); + // simulation.drawList.push({ //add dmg to draw queue + // x: this.position.x, + // y: this.position.y, + // radius: Math.sqrt(dmg) * 200, + // color: '#000000', + // time: simulation.drawTime + // }); + } + }; + } + me.laserMine = function (x, y) { + mobs.spawn(x, y, 3, 20, "#000000"); + let xx = mob[mob.length - 1]; + xx.stroke = "#00000000"; + Matter.Body.setDensity(xx, 0.000005) //one tap + xx.isUnstable = true; + xx.timeLeft = 40 + Math.floor(180 * Math.random()) + xx.leaveBody = false; + xx.isDropPowerUp = false; + xx.collisionFilter.mask = cat.bullet | cat.player + xx.showHealthBar = false; + //xx.vertices = Matter.Vertices.rotate(xx.vertices, Math.PI, xx.position); + me.onHit = function () { + this.death(); + }; + xx.do = function () { + this.timeLimit(); + Matter.Body.setAngularVelocity(this, 0.01) + ctx.beginPath(); + ctx.lineWidth = 1; + ctx.strokeStyle = "#00000000" + for (let i = 0; i < this.vertices.length; i++) { + const where = this.vertices[i] + const endPoint = Vector.add(where, Vector.mult(Vector.normalise(Vector.sub(where, this.position)), 2500)) + me.lasers(this.vertices[0], this.angle + Math.PI / 3); + me.lasers(this.vertices[1], this.angle + Math.PI); + me.lasers(this.vertices[2], this.angle - Math.PI / 3); + } + ctx.strokeStyle = randomColor({ + hue: "#FF00FF" + }); + ctx.stroke(); + ctx.save() + ctx.beginPath(); + ctx.moveTo(this.vertices[0].x, this.vertices[0].y); + ctx.lineTo(this.vertices[1].x, this.vertices[1].y); + ctx.lineTo(this.vertices[2].x, this.vertices[2].y); + ctx.fillStyle = "#000000"; + ctx.strokeStyle = "transparent"; + ctx.fill(); + ctx.closePath(); + ctx.stroke(); + ctx.restore() + } + } + me.seeker = function (x, y) { + mobs.spawn(x, y, sides = 5, radius = 5, "rgb(0,0,0)"); + let yy = mob[mob.length - 1]; + yy.stroke = "transparent"; + yy.onHit = function () { + this.explode(this.mass * 20); + }; + Matter.Body.setDensity(yy, 0.000015); //normal is 0.001 + yy.timeLeft = 420 //* (0.8 + 0.4 * Math.random()); + yy.accelMag = 0.00017 * simulation.accelScale; //* (0.8 + 0.4 * Math.random()) + yy.frictionAir = 0.01 //* (0.8 + 0.4 * Math.random()); + yy.restitution = 0.5; + yy.leaveBody = false; + yy.isDropPowerUp = false; + yy.isBadTarget = true; + yy.isMobBullet = true; + yy.showHealthBar = false; + yy.collisionFilter.category = cat.mobBullet; + yy.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet; + let index = 0; + yy.do = function () { + this.alwaysSeePlayer() + this.timeLimit(); + this.attraction(); + }; + } + me.drop = function (x, y) { + mobs.spawn(x, y, sides = 90, radius = 30, "rgb(0,255,100,0.7)"); + let yyy = mob[mob.length - 1]; + yyy.stroke = "transparent"; + yyy.onDeath = function () { + for (let i = 0, len = 5; i < len; i++) { + me.seeker(this.position.x, this.position.y) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: Math.random() * 30 - Math.random() * 30, + y: Math.random() * 30 - Math.random() * 30 + }); + } + }; + Matter.Body.setDensity(yyy, 0.000015); //normal is 0.001 + yyy.timeLeft = 60 //* (0.8 + 0.4 * Math.random()); + yyy.frictionAir = 0.01 //* (0.8 + 0.4 * Math.random()); + yyy.restitution = 0.5; + yyy.leaveBody = false; + yyy.isDropPowerUp = false; + yyy.isBadTarget = true; + yyy.isMobBullet = true; + yyy.showHealthBar = false; + yyy.collisionFilter.category = cat.mobBullet; + yyy.collisionFilter.mask = null; + yyy.maxRadius = 30; + let index = 0; + yyy.do = function () { + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + Matter.Body.setPosition(this, player.position) + if (player.speed > 2.5) Matter.Body.setVelocity(player, Vector.mult(player.velocity, 0.94)) + } + this.alwaysSeePlayer() + this.timeLimit(); + ctx.save() + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y) + ctx.fillStyle = "black"; + ctx.arc(this.position.x, this.position.y, this.maxRadius, 0, 2 * Math.PI) + ctx.stroke() + ctx.fill() + ctx.restore() + if (this.maxRadius > 0) { + this.maxRadius -= 0.5; + } + }; + } + }; + restoreBoss(-13350, -1800); + laserEM(-6500 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -3400 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + sniper(-9275 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -3325 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + laserEM(-5750 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -850 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + sniper(-3600 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -1325 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + laserEM(1425 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -800 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + //restoreBoss(-350, -3225); + wire(); + wire(); + wire(); + wire(); + wire(); + color.map = '#00000000'; + level.customTopLayer = () => { + if (dong.position.x > -3825) { + dong.force.y -= dong.mass * simulation.g; + } else { + dong.force.y += dong.mass * simulation.g; + } + Matter.Body.setAngularVelocity(dong, -0.5) + if (destroyed == false) { + door.isClosing = false; + } else { + door.isClosing = true; + } + door.openClose(); + door.draw() + for (let i = 0, len = map.length; i < len; i++) { //so boss bar renders over the map + // ctx.beginPath() + // //ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + // ctx.fillRect(map[i].vertices[0].x , map[i].vertices[0].y, Math.abs(map[i].vertices[0].x - map[i].vertices[1].x), Math.abs(map[i].vertices[1].y - map[i].vertices[2].y)) + // //ctx.strokeRect(map[i].vertices[0].x , map[i].vertices[0].y, Math.abs(map[i].vertices[0].x - map[i].vertices[1].x), Math.abs(map[i].vertices[1].y - map[i].vertices[2].y)) + // ctx.fillStyle = "rgba(68,68,68)" + // //ctx.strokeStyle = "transparent" + // ctx.stroke() + // ctx.fill() + ctx.beginPath(); + ctx.moveTo(map[i].vertices[0].x, map[i].vertices[0].y); + for (let j = 0, length = map[i].vertices.length; j < length; j++) { + ctx.lineTo(map[i].vertices[j].x, map[i].vertices[j].y); + } + ctx.lineTo(map[i].vertices[0].x, map[i].vertices[0].y); + ctx.fillStyle = "rgba(68,68,68)"; + ctx.strokeStyle = "transparent"; + ctx.fill(); + ctx.stroke(); + // ctx.setLineDash([]); + } + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].restoreBoss) { + ctx.save(); + ctx.setTransform(1, 0, 0.5, 1, 0, 0); //slanted + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(canvas.width2 / 2, canvas.height2 / 10, canvas.width2, 30); + ctx.fillStyle = "rgba(0,0,0,0.7)"; + ctx.fillRect(canvas.width2 / 2, canvas.height2 / 10, canvas.width2 * mob[i].health, 30); + ctx.restore(); + } + } + }; + // simulation.enableConstructMode() //landgreen if you see this can you remove im probably gonna forget + for (let i = 0; i < spawn.bossTypeSpawnOrder.length * Math.random(); i++) { + spawn.bossTypeSpawnOrder.splice(i * Math.floor(Math.random() * spawn.bossTypeSpawnOrder.length), 1, "restoreBoss") //meh good enough + } + const obj = { restoreBoss }; + Object.assign(spawn, obj); //ez + }, + superNgonBros() { + simulation.inGameConsole(`Super N-gon Bros by DesBoot`); + + let bowserKilled = 0 + let flagY = -750 + let flagReached = 0 + const elevator1 = level.elevator(3975, -11650, 450, 50, -13100, 0.003) + const elevator2 = level.elevator(5575, -11650, 450, 50, -13100, 0.003) + let firstElevatorY = -11650 + + const portal = level.portal({ x: 3990, y: 100 }, 1.5 * Math.PI, { x: 100, y: -13500 }, -1.5 * Math.PI) + const portal2 = level.portal({ x: 7135, y: -12270 }, -1 * Math.PI, { x: 12325, y: -2000 }, -1.5 * Math.PI) + + const bowser = function (x, y, radius = 150) { //define the mob the same as spawn mob code + mobs.spawn(x, y, 5, radius, "rgb(0,200,180)"); + let me = mob[mob.length - 1]; + me.accelMag = 0.05; + me.g = 0.002; //required if using this.gravity + me.frictionAir = 0.01; + me.friction = 1 + me.frictionStatic = 1 + me.restitution = 0; + me.delay = 80 * simulation.CDScale; + me.randomHopFrequency = 200 + Math.floor(Math.random() * 150); + me.randomHopCD = simulation.cycle + me.randomHopFrequency; + Matter.Body.rotate(me, Math.random() * Math.PI); + spawn.shield(me, x, y); + me.do = function () { + //spawn.grenade(me.position.x, me.position.y); + // //const v = 5 * simulation.accelScale; + // Matter.Body.setVelocity(mob[mob.length - 1], { + // x: this.velocity.x + this.fireDir.x * v + Math.random(), + // y: this.velocity.y + this.fireDir.y * v + Math.random() + // }); + this.gravity(); + this.seePlayerCheck(); + this.checkStatus(); + if (this.seePlayer.recall) { + if (this.cd < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + this.cd = simulation.cycle + this.delay; + const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x += forceMag * Math.cos(angle) * 0.5; + this.force.y += (forceMag * Math.sin(angle) - (Math.random() * 0.07 + 0.1) * this.mass) * 0.7; //antigravity + if (Math.random() < 0.5) { + spawn.grenade(me.position.x, me.position.y - 250 * Math.random(), 500); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: -5, + y: 0 + }); + } else { + spawn.bullet(this.position.x, this.position.y, 25); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: -25, + y: -25 + }); + } + } + } else { + //randomly hob if not aware of player + if (this.randomHopCD < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + this.randomHopCD = simulation.cycle + this.randomHopFrequency; + //slowly change randomHopFrequency after each hop + this.randomHopFrequency = Math.max(100, this.randomHopFrequency + (0.5 - Math.random()) * 200); + const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass * (0.1 + Math.random() * 0.3); + const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI; + this.force.x += forceMag * Math.cos(angle); + this.force.y += forceMag * Math.sin(angle) - 0.07 * this.mass; //antigravity + spawn.grenade(me.position.x, me.position.y - 250 * Math.random(), 500); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: -5, + y: 0 + }); + } + } + }; + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + bowserKilled = 1 + } + + } + + bowser(20500, -400) //call the mob + //fire(15300, -200) + const brick = function (x, y, angle = Math.PI * 0.5, radius = 53) {//credit to Richard0820 for the code + mobs.spawn(x, y, 4, radius, "#ab6101"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.isDropPowerUp = false; + me.showHealthBar = false; + Matter.Body.setDensity(me, 999999) + me.collisionFilter.mask = cat.player | cat.mob | cat.bullet; + me.constraint = Constraint.create({ + pointA: { + x: me.position.x, + y: me.position.y + }, + bodyB: me, + stiffness: 0, + damping: 0 + }); + me.do = function () { + this.isStunned = true; + if (this.health < 1) { + this.health += 0.001; //regen + } + this.checkStatus(); + Matter.Body.setAngle(me, angle); + if ((player.velocity.y < 0 && player.position.y > me.position.y || player.velocity.y > 30 && player.position.y < me.position.y) && Math.abs(player.position.x - me.position.x) < 50 && Math.abs(player.position.y - me.position.y) < 150) { + me.death() + } + }; + + me.onHit = function () { + + if (player.velocity.y < 0 && player.position.y > me.position.y || player.velocity.y > 30 && player.position.y < me.position.y) { + + me.death() + + } + } + me.onDeath = function () { + if (Math.random() < 0.1) { + spawn.randomSmallMob(me.position.x, me.position.y - 75); + simulation.inGameConsole('mob') + } else { + if (Math.random() < 0.07) { + powerUps.spawn(me.position.x, me.position.y + (75 * (player.velocity.y / Math.abs(player.velocity.y))), "tech", true); + simulation.inGameConsole('tech') + } else { + if (Math.random() < 0.4) { + powerUps.spawn(me.position.x, me.position.y + (75 * (player.velocity.y / Math.abs(player.velocity.y))), "heal", true); + simulation.inGameConsole('heal') + } else { + //if (Math.random() < 0.8){ + powerUps.spawn(me.position.x, me.position.y + (75 * (player.velocity.y / Math.abs(player.velocity.y))), "ammo", true); + simulation.inGameConsole('ammo') + //} + } + } + } + } + Composite.add(engine.world, me.constraint); + } + // simulation.enableConstructMode() + let firstMobsSpawned = 1 + let secondMobsSpawned = 0 + let thirdMobsSpawned = 0 + let fourthMobsSpawned = 0 + let firstMobsReached = 0 + let secondMobsReached = 0 + let thirdMobsReached = 0 + let fourthMobsReached = 0 + let finalRoomReached = 0 + let undergroundMobsSpawned = 0 + let undergroundMobsReached = 0 + + + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 22100; + level.exit.y = -40; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#a2a5ff"; + // color.map = "#444" //custom map color + + level.custom = () => { + if (player.position.x > 14950 && flagReached == 0) { + flagReached = 1 + } + if (flagReached == 1 && flagY < -150) { + flagY += 5 + } + ctx.fillStyle = "rgba(64,64,64,0.97)" + ctx.fillRect(4200, -13100, 2, 1450) + ctx.fillRect(5800, -13100, 2, 1450) + if (firstElevatorY < -12099) { + firstElevatorY = -11650 + } else { + firstElevatorY -= 5 + } + + //simulation.inGameConsole(firstElevatorY) + elevator1.move(); + elevator2.move(); + if (player.position.x > 0 && player.position.y < -9000 && player.position.y > -10000) { + //m.death() + m.damage(0.05 * simulation.difficultyMode) + Matter.Body.setPosition(player, { + x: 275, + y: -12175 + }); + } + + portal[2].query() + portal[3].query() + portal2[2].query() + portal2[3].query() + //simulation.inGameConsole(firstBlockBroken) + level.exit.drawAndCheck(); + if (player.position.x > 4100 && secondMobsReached == 0) { + secondMobsSpawned = 1 + } + if (player.position.x > 7000 && thirdMobsReached == 0) { + thirdMobsSpawned = 1 + } + if (player.position.x > 14300 && fourthMobsReached == 0) { + fourthMobsSpawned = 1 + } + if (player.position.y < -11000 && undergroundMobsReached == 0) { + undergroundMobsSpawned = 1 + }//player.position.x > 14300 && + if (m.onGround) { + if (Math.abs(player.velocity.x) > 0.3) { + Matter.Body.setVelocity(player, { + x: player.velocity.x + (0.1 * (Math.abs(player.velocity.x) / player.velocity.x)), + y: player.velocity.y + 0.2 + }); + } else { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y + 0.2 + }); + } + } else { + if (input.down) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y + 2 + }); + } else { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y + 0.2 + }); + } + } + + level.enter.draw(); + if (finalRoomReached == 0 && player.position.x > 21150) { + finalRoomReached = 1 + simulation.inGameConsole('Thank you M, but our techs are in another castle!') + } + //mobs + if (firstMobsSpawned == 1 && firstMobsReached == 0) { + spawn.randomSmallMob(1260, -75); + spawn.randomMob(2100, -75, 0.4); + spawn.randomSmallMob(2400, -75); + spawn.randomSmallMob(2500, -75); + spawn.randomMob(2900, -75, 0.2); + spawn.randomMob(3400, -75, 0.4); + spawn.randomMob(3400, -75, 0.4); + firstMobsReached = 1 + } + if (secondMobsSpawned == 1 && secondMobsReached == 0) { + spawn.randomSmallMob(4400, -75); + spawn.randomSmallMob(5500, -75); + spawn.randomSmallMob(5835.6, -402.4); + spawn.randomSmallMob(5835.6, -402.4); + spawn.randomSmallMob(6543.2, -730.0); + spawn.randomMob(6795.4, -162.4, 0.1); + spawn.randomMob(6795.4, -162.4, 0.1); + secondMobsReached = 1 + } + if (thirdMobsSpawned == 1 && thirdMobsReached == 0) { + spawn.randomMob(8465.6, -469.9, 0.1); + spawn.randomMob(9839.6, -444.5, 0.4); + spawn.randomSmallMob(11033.2, -155.3); + spawn.randomMob(12161.3, -85.1, 0.3); + spawn.randomMob(12161.3, -85.1, 0.3); + spawn.randomMob(13399.8, -93.4, 0.4); + thirdMobsReached = 1 + + } + if (fourthMobsSpawned == 1 && fourthMobsReached == 0) { + spawn.randomSmallMob(16500, -400); + spawn.randomSmallMob(19278.9, -211.1); + spawn.randomMob(18839.0, -463.2, 0.3); + spawn.randomMob(18036.9, -205.9, 0.3); + spawn.randomMob(16950.4, -365.2, 0.4); + spawn.randomMob(16355.6, -390.8, 0.1); + + fourthMobsReached = 1 + + } + if (undergroundMobsSpawned == 1 && undergroundMobsReached == 0) { + spawn.randomSmallMob(1140.0, -12228.0); + spawn.randomSmallMob(2429.9, -12371.2); + spawn.randomSmallMob(4899.4, -12139.6); + spawn.randomMob(18839.0, -463.2, 0.3); + spawn.randomMob(2844.5, -12281.0, 0.2); + spawn.randomMob(4967.5, -12550.8, 0.4); + spawn.randomMob(6696.9, -12437.9, 0.1); + + undergroundMobsReached = 1 + + } + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + }; + level.customTopLayer = () => { + //spawn.mapRect(886, firstElevatorY + 10000, 75, 5); + + ctx.fillStyle = "rgba(64,64,64,0.97)" + ctx.fillRect(3928, -300, 120, 500) + //6940, -12360, 200, 5 + ctx.fillRect(6940, -12350, 170, 120) + ctx.fillRect(7090, -12380, 120, 200) + ctx.fillRect(14980, -750, 10, 750)//flagpole + ctx.beginPath() + ctx.moveTo(14980, flagY) + ctx.lineTo(14905, flagY) + ctx.lineTo(14980, flagY + 75) + ctx.fill() + + }; + + + + brick(923.5, -262); + spawn.mapRect(886, -304, 75, 5); + spawn.mapRect(886, -229, 75, 5); + spawn.mapRect(883, -304, 5, 80); + spawn.mapRect(958, -304, 5, 80); + brick(1250.5, -262); + spawn.mapRect(1138, -304, 375, 5); + spawn.mapRect(1138, -229, 375, 5); + brick(1400.5, -262); + brick(1325.5, -562); + spawn.mapRect(1288, -604, 75, 5); + spawn.mapRect(1288, -529, 75, 5); + spawn.mapRect(1285, -604, 5, 80); + spawn.mapRect(1360, -604, 5, 80); + brick(5787.5, -262); + spawn.mapRect(5675, -304, 225, 5); + spawn.mapRect(5675, -229, 225, 5); + brick(6987.5, -562); + spawn.mapRect(6725, -604, 300, 5); + spawn.mapRect(6725, -529, 300, 5); + spawn.mapRect(7025, -604, 5, 80); + brick(7887.5, -262);//4 separated blocks in the middle + spawn.mapRect(7850, -304, 75, 5); + spawn.mapRect(7850, -225, 75, 5); + spawn.mapRect(7850, -304, 5, 80); + spawn.mapRect(7925, -304, 5, 84); + brick(8112.5, -262); + spawn.mapRect(8075, -304, 75, 5); + spawn.mapRect(8075, -225, 75, 5); + spawn.mapRect(8075, -304, 5, 80); + spawn.mapRect(8150, -304, 5, 84); + brick(8337.5, -262); + spawn.mapRect(8300, -304, 75, 5); + spawn.mapRect(8300, -225, 75, 5); + spawn.mapRect(8300, -304, 5, 80); + spawn.mapRect(8375, -304, 5, 84); + brick(8112.5, -562); + spawn.mapRect(8075, -604, 75, 5); + spawn.mapRect(8075, -525, 75, 5); + spawn.mapRect(8075, -604, 5, 80); + spawn.mapRect(8150, -604, 5, 84); + brick(9612.5, -562); + spawn.mapRect(9500, -604, 300, 5); + spawn.mapRect(9500, -525, 300, 5); + spawn.mapRect(9647.5, -600, 5, 75); + brick(9687.5, -562); + brick(12887.5, -262); + spawn.mapRect(12700, -304, 300, 5); + spawn.mapRect(12700, -225, 300, 5); + brick(5212.5, -12337.5); + spawn.mapRect(4725, -12377, 525, 5); + spawn.mapRect(4725, -12303, 525, 5); + spawn.mapRect(5250, -12377, 5, 79); + + + + + + spawn.mapRect(-100, 0, 4033, 2000); + spawn.mapRect(4043, 0, 882, 2000); + spawn.mapRect(3909.5, 203.6, 150, 2000); + spawn.mapRect(1138, -300, 75, 75); + spawn.mapRect(1288, -300, 75, 75); + spawn.mapRect(1438, -300, 75, 75); + spawn.mapRect(1738, -150, 150, 75);//pipe 1 + spawn.mapRect(1753, -150, 120, 150); + spawn.mapRect(2488, -225, 150, 75);//pipe 2 + spawn.mapRect(2503, -225, 120, 225); + spawn.mapRect(3088, -300, 150, 75);//pipe 3 + spawn.mapRect(3103, -300, 120, 300); + spawn.mapRect(3913, -300, 20, 75);//pipe 4 + spawn.mapRect(3928, -300, 5, 300); + spawn.mapRect(4043, -300, 20, 75); + spawn.mapRect(4043, -300, 5, 300); + + spawn.mapRect(5225, 0, 1125, 2000); + spawn.mapRect(6575, 0, 4900, 2000); + spawn.mapRect(5675, -300, 75, 75); + spawn.mapRect(5825, -300, 75, 75); + spawn.mapRect(5900, -600, 600, 75); + spawn.mapRect(6725, -600, 225, 75); + spawn.mapRect(6950, -300, 75, 75); + spawn.mapRect(7400, -300, 150, 75); + + spawn.mapRect(8750, -300, 75, 75); + spawn.mapRect(8975, -600, 225, 75);//raised platform + spawn.mapRect(9575, -300, 150, 75); + spawn.mapRect(9500, -600, 75, 75);//upper block with double bricks + spawn.mapRect(9725, -600, 75, 75); + spawn.mapRect(9950, -75, 300, 75);//staircase + spawn.mapRect(10025, -150, 225, 75); + spawn.mapRect(10100, -225, 150, 75); + spawn.mapRect(10175, -300, 75, 75); + + spawn.mapRect(10475, -75, 300, 75); + spawn.mapRect(10475, -150, 225, 75); + spawn.mapRect(10475, -225, 150, 75); + spawn.mapRect(10475, -300, 75, 75); + + spawn.mapRect(11100, -75, 375, 75);//staircase 2 + spawn.mapRect(11175, -150, 300, 75); + spawn.mapRect(11250, -225, 225, 75); + spawn.mapRect(11325, -300, 150, 75); + + spawn.mapRect(11725, -75, 300, 75); + spawn.mapRect(11725, -150, 225, 75); + spawn.mapRect(11725, -225, 150, 75); + spawn.mapRect(11725, -300, 75, 75); + + spawn.mapRect(11725, 0, 5975, 2000);//platform after the staircase + spawn.mapRect(12325, -150, 150, 75);//exit pipe + spawn.mapRect(12340, -150, 120, 300); + spawn.mapRect(12700, -300, 150, 75); + spawn.mapRect(12925, -300, 75, 75); + spawn.mapRect(13525, -150, 150, 72);//final pipe + spawn.mapRect(13540, -150, 120, 150); + spawn.mapRect(13675, -75, 675, 75);//final staircase + spawn.mapRect(13750, -150, 600, 75); + spawn.mapRect(13825, -225, 525, 75); + spawn.mapRect(13900, -300, 450, 75); + spawn.mapRect(13975, -375, 375, 75); + spawn.mapRect(14050, -450, 300, 75); + spawn.mapRect(14125, -525, 225, 75); + spawn.mapRect(14200, -600, 150, 75); + + //flag + spawn.mapRect(14950, -75, 75, 75); + + + + spawn.mapRect(1750, -4600, 500, 25);//loss + spawn.mapRect(2000, -4850, 25, 500); + spawn.mapRect(1800, -4800, 25, 150); + spawn.mapRect(2075, -4800, 25, 150); + spawn.mapRect(2150, -4775, 25, 125); + spawn.mapRect(1875, -4550, 25, 150); + spawn.mapRect(1800, -4550, 25, 150); + spawn.mapRect(2075, -4550, 25, 150); + spawn.mapRect(2123, -4430, 100, 25); + // spawn.mapRect(-250, -600, 500, 25); + // spawn.mapRect(-250, -600, 500, 25); + + //underground area + spawn.mapRect(0, -12000, 2025, 2000); + spawn.mapRect(2325, -12225, 150, 2000); + spawn.mapRect(2775, -12000, 900, 2000); + spawn.mapRect(3525, -12300, 150, 300); + spawn.mapRect(3450, -12225, 75, 300); + spawn.mapRect(3375, -12150, 75, 300); + spawn.mapRect(3300, -12075, 75, 300); + spawn.mapRect(4725, -12375, 450, 75); + spawn.mapRect(4725, -12000, 600, 2000); + spawn.mapRect(-100, -13500, 100, 3500); + spawn.mapRect(-100, -13500, 100, 3500); + spawn.mapRect(6375, -12225, 1650, 2000); + spawn.mapRect(7225, -13225, 2850, 3000); + spawn.mapRect(-100, -13700, 100, 200);//roof + spawn.mapRect(-100, -13700, 3775, 100); + spawn.mapRect(6450, -13225, 1000, 100); + spawn.mapRect(7090, -13225, 120, 885);//pipe + //spawn.mapRect(6940, -12360, 200, 120); + spawn.mapRect(6940, -12350, 200, 5); + spawn.mapRect(6950, -12240, 140, 5); + spawn.mapRect(6940, -12365, 75, 15); + spawn.mapRect(6940, -12235, 75, 15); + + //castle + spawn.mapRect(17700, 0, 4975, 2000); + spawn.mapRect(18600, -225, 375, 2225); + spawn.mapRect(19500, -225, 450, 2225); + spawn.mapRect(19500, -825, 450, 225); + spawn.mapRect(15924, -1575, 6751, 750); + spawn.mapRect(19950, -225, 975, 75); + spawn.mapRect(20925, -300, 225, 300); + spawn.mapRect(21000, -825, 150, 300); + spawn.mapRect(15924, -225, 1776, 2225); + spawn.mapRect(17175, -825, 525, 225); + spawn.mapRect(22600, -825, 75, 825); + + + + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + // spawn.bodyRect(1540, -1110, 300, 25, 0.9); + // spawn.randomSmallMob(1300, -70); + // spawn.randomMob(2650, -975, 0.8); + // spawn.randomGroup(1700, -900, 0.4); + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + // spawn.secondaryBossChance(100, -1500) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + underpass() { + simulation.inGameConsole(`underpass by Richard0820`); + + let key = false; + const door = level.door(2650, -825, 50, 250, 250, 10); + const elevator = level.elevator(-11050, -650, 450, 75, -2975, 0.003, { up: 0.1, down: 0.1 }) + const slimePit = level.hazard(-4775, -350, 1975, 175); + const boost = level.boost(137.5, -600, 75); + + let base = Matter.Bodies.rectangle(-4375, -1000, 100, 100, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let left = Matter.Bodies.rectangle(-4375 + 50, -1000 - 50, 50, 50, {//not actually left/right + density: 0.05, + isNotHoldable: true, + isStatic: false + }); + let right = Matter.Bodies.rectangle(-4375 - 50, -1000 - 50, 50, 50, { + density: 0.05, + isNotHoldable: true, + isStatic: false + }); + let left2 = Matter.Bodies.rectangle(-4375 - 50, -1000 + 50, 50, 50, { + density: 0.05, + isNotHoldable: true, + isStatic: false + }); + let right2 = Matter.Bodies.rectangle(-4375 + 50, -1000 + 50, 50, 50, { + density: 0.05, + isNotHoldable: true, + isStatic: false + }); + dong = Matter.Body.create({ + parts: [base, left, right, left2, right2] + }); + body[body.length] = base; + body[body.length] = left; + body[body.length] = right; + body[body.length] = left2; + body[body.length] = right2; + Matter.Composite.add(engine.world, dong) + Matter.Composite.add(engine.world, Constraint.create({ + pointA: { x: -3825, y: -975 }, + bodyB: dong, + stiffness: 0.2, + damping: 0.1 + })); + composite[composite.length] = dong; + setTimeout(function () { + dong.collisionFilter.category = cat.body; + dong.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mobBullet | cat.mob //| cat.map + }, 1000); + level.custom = () => { + ctx.save() + ctx.beginPath() + ctx.fillStyle = "#80808077"; + ctx.strokeStyle = "#80808022"; + ctx.fillRect(225, -1025, 2400, 450); + ctx.fillRect(-2950, -1025, 3100, 450); + ctx.fillRect(-7050, -1025, 2400, 450); + ctx.fillRect(-10575, -3975, 4525, 1025); + ctx.fillRect(-4650, -1700, 1700, 1100); + ctx.fillRect(-11150, -3575, 575, 3050); + ctx.fillRect(-11900, -1000, 750, 475); + ctx.fill() + ctx.stroke() + ctx.restore() + ctx.save() + ctx.beginPath() + ctx.fillStyle = "#d8dadf"; + ctx.strokeStyle = "#d8dadf"; + ctx.moveTo(-2950, -600); + ctx.lineTo(-3730, -1725); + ctx.lineTo(-3730, -600); + + ctx.moveTo(-4650, -600); + ctx.lineTo(-3925, -1725); + ctx.lineTo(-3925, -575); + + ctx.moveTo(-10575, -3425); //NE section + ctx.lineTo(-10100, -2975); + ctx.lineTo(-10575, -2975); + + // ctx.moveTo(-7625, -3800); + // ctx.lineTo(-6750, -2975); + // ctx.lineTo(-7625, -2975); + + ctx.moveTo(-7975, -2975); + ctx.lineTo(-7625, -3800); + ctx.lineTo(-7350, -2950); + + ctx.moveTo(-6750, -2975); + ctx.lineTo(-7075, -3800); + ctx.lineTo(-7350, -2950); + + // ctx.moveTo(-7975, -2975); + // ctx.lineTo(-7075, -3800); + // ctx.lineTo(-7075, -2975); + + ctx.moveTo(-11900, -950); + ctx.lineTo(-11900, -550); + ctx.lineTo(-11500, -550); + + ctx.fillRect(-3925, -1675, 200, 1075); + ctx.fillRect(-7625, -3800, 550, 875); + ctx.clearRect(-10600, -4000, 525, 475); + ctx.clearRect(-10100, -4000, 500, 300); + ctx.clearRect(-9625, -4000, 500, 175); + ctx.fillRect(-11125, -3600, 550, 50); + ctx.fillRect(-10600, -3400, 50, 425); + ctx.fillRect(-11925, -925, 45, 375); + ctx.fillRect(-3950, -1675, 75, 1100); + ctx.fillRect(-3925, -625, 950, 50); + ctx.fillRect(-4650, -600, 1700, 375); + ctx.fillRect(-14550, -2400, 2650, 2050); + //ctx.clearRect(-11050, -3000, 475, 50); + + ctx.moveTo(-11150, -3575); + ctx.lineTo(-10575, -2150); + ctx.lineTo(-10575, -3575); + + ctx.stroke() + ctx.fill() + ctx.restore() + boost.query() + slimePit.query() + if (Matter.Query.collides(dong, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + const dmg = 0.05 * Math.min(simulation.dmgScale, simulation.difficulty); + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: dong.position.x, + y: dong.position.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + } + for (let i = 0; i < mob.length; i++) { + if (Matter.Query.collides(dong, [mob[i]]).length > 0) { + const dmg = 1; + mob[i].damage(dmg, true); + simulation.drawList.push({ //add dmg to draw queue + x: dong.position.x, + y: dong.position.y, + radius: Math.sqrt(dmg) * 50, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + break + } + } + level.exit.drawAndCheck(); + ctx.beginPath() + ctx.fillStyle = '#68686822'; + ctx.fillRect(-25, -2175, 100, 200); + ctx.fill() + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + ctx.moveTo(-3825, -975) + ctx.lineTo(dong.position.x, dong.position.y) + ctx.stroke(); + ctx.setLineDash([]); + simulation.drawList.push({ //add dmg to draw queue + x: dong.position.x, + y: dong.position.y, + radius: 10, + color: color.block, + time: 20 + }); + ctx.beginPath() + ctx.fillStyle = `rgba(68,68,68, ${3 * Math.sin(simulation.cycle * 0.015)})` + ctx.fillRect(-3000, -2175, 175, 25); + ctx.fillRect(-2850, -2300, 25, 150); + ctx.fillRect(-3000, -2300, 175, 25); + ctx.fillRect(-3000, -2425, 25, 150); + ctx.fillRect(-3000, -2425, 175, 25); + ctx.fill() + ctx.fillStyle = `rgba(68,68,68, ${5 * Math.sin(simulation.cycle * 0.015)})` + ctx.fillRect(-2725, -2425, 25, 275); + ctx.fillRect(-2725, -2425, 175, 25); + ctx.fillRect(-2575, -2425, 25, 275); + ctx.fillRect(-2725, -2300, 175, 25); + ctx.fill() + ctx.fillStyle = `rgba(68,68,68, ${7 * Math.sin(simulation.cycle * 0.015)})` + ctx.fillRect(-2450, -2425, 25, 275); + ctx.fillRect(-2450, -2175, 175, 25); + ctx.fill() + ctx.stroke(); + ctx.fillStyle = `#00FFFF22`; + ctx.fillRect(-7650, -2975 - 100, 600, 2375 + 100) + ctx.fill() + ctx.fillStyle = `#00FFFF66` + ctx.fillRect(-7650 + Math.floor(Math.random() * 600), -2975 - 100, 5, 2375 + 100) + ctx.fillRect(-7650 + Math.floor(Math.random() * 600), -2975 - 100, 5, 2375 + 100) + ctx.fillStyle = `rgba(68, 68, 68)` + ctx.fillRect(-7675, -3075, 50, 125); + ctx.fillRect(-7075, -3075, 50, 125); + ctx.fillRect(-7725, -3025, 75, 75); + ctx.fillRect(-7050, -3025, 75, 75); + ctx.fill() + for (let i = 0, len = body.length; i < len; ++i) { //push blocks away vertically + if (body[i].position.x > -7625 && body[i].position.x < -7075 && body[i].position.y > -2975 - 100 && body[i].position.y < -625) { + body[i].force.y -= simulation.g * body[i].mass + 0.012; + } + } + for (let i = 0, len = bullet.length; i < len; ++i) { //push bullets away vertically + if (bullet[i].position.x > -7625 && bullet[i].position.x < -7075 && bullet[i].position.y > -2975 - 100 && bullet[i].position.y < -625) { + bullet[i].force.y -= simulation.g * bullet[i].mass; + } + } + for (let i = 0, len = powerUp.length; i < len; ++i) { //push powerups away vertically + if (powerUp[i].position.x > -7625 && powerUp[i].position.x < -7075 && powerUp[i].position.y > -2975 - 100 && powerUp[i].position.y < -625) { + powerUp[i].force.y -= simulation.g * powerUp[i].mass + 0.12; + } + } + for (let i = 0, len = mob.length; i < len; ++i) { //push mobs away vertically + if (mob[i].position.x > -7625 && mob[i].position.x < -7075 && mob[i].position.y > -2975 - 100 && mob[i].position.y < -625) { + mob[i].force.y -= simulation.g * mob[i].mass + 0.0012; + } + } + if (m.pos.x > -7625 && m.pos.x < -7075 && m.pos.y > -2975 - 100 && m.pos.y < -625) { + player.force.y -= m.mass * simulation.g + (input.down ? 0 : 0.012 * 2); + + } + ctx.save() + ctx.beginPath(); + ctx.fillStyle = `rgba(0,250,250, 0.05)`; + ctx.fillRect(2625, -1000, 350, 450); + ctx.fill() + ctx.restore() + elevator.move() + if (mob.length <= 5) { + key = true; + } + if (key) { + level.exit.x = 2775; + level.exit.y = -650; + } else { + + ctx.save() + ctx.beginPath(); + ctx.moveTo(2775, -650 + 30); + ctx.lineTo(2775, -650 - 80); + ctx.bezierCurveTo(2775, -650 - 170, 2775 + 100, -650 - 170, 2775 + 100, -650 - 80); + ctx.lineTo(2775 + 100, -650 + 30); + ctx.lineTo(2775, -650 + 30); + ctx.fillStyle = "#00ffff"; + ctx.fill(); + ctx.restore() + + const omega = new Image(); //the seal hehe + let width = Math.random() * 40; //Math.max(Math.sin(m.cycle * 0.05), Math.cos(m.cycle * 0.05)) * + let length = Math.random() * 40; //Math.max(Math.sin(m.cycle * 0.05), Math.cos(m.cycle * 0.05)) * + omega.src = "https://raw.githubusercontent.com/Whyisthisnotavalable/image-yy/main/MOSHED-2023-4-20-12-55-58-removebg-preview.png"; //"https://raw.githubusercontent.com/Whyisthisnotavalable/image-yy/main/omegafr.png"; + ctx.drawImage(omega, 2775 + 50 - width, -650 - 50 - length, width * 2, length * 2) + ctx.save() + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.beginPath() + // ctx.font = "80px monospace"; + // ctx.fillText("Ω", 2775 + 50, -650 - 50); + ctx.strokeStyle = "gray"; + ctx.arc(2775 + 50, -650 - 50, 100 * Math.abs(Math.sin(m.cycle * 0.07)) + 10, 0 + Math.sin(m.cycle * 0.1 * Math.PI), 0 + Math.cos(m.cycle * 0.1 + Math.PI)) + ctx.shadowBlur = 10; + ctx.shadowColor = "black"; + ctx.stroke() + //ctx.fill() + ctx.restore() + ctx.save() + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.beginPath() + // ctx.font = "80px monospace"; + // ctx.fillText("Ω", 2775 + 50, -650 - 50); + ctx.strokeStyle = "gray"; + ctx.arc(2775 + 50, -650 - 50, 90 * Math.abs(Math.sin(m.cycle * 0.08)) + 10, 0 + Math.cos(m.cycle * 0.1 * Math.PI), 0 + Math.sin(m.cycle * 0.1 + Math.PI)) + ctx.shadowBlur = 10; + ctx.shadowColor = "black"; + ctx.stroke() + //ctx.fill() + ctx.restore() + ctx.save() + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.beginPath() + // ctx.font = "80px monospace"; + // ctx.fillText("Ω", 2775 + 50, -650 - 50); + ctx.strokeStyle = "gray"; + ctx.arc(2775 + 50, -650 - 50, 80 * Math.abs(Math.sin(m.cycle * 0.09)) + 10, 0 + Math.tan(m.cycle * 0.1 * Math.PI), 0 + Math.tan(m.cycle * 0.1 + Math.PI)) + ctx.shadowBlur = 10; + ctx.shadowColor = "black"; + ctx.stroke() + //ctx.fill() + ctx.setLineDash([]); + ctx.restore() + } + }; + level.setPosToSpawn(30, -2000); //normal spawn + level.exit.x = 1375; + level.exit.y = -1500; + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom + 800) + document.body.style.backgroundColor = "#d8dadf"; + spawn.mapRect(-225, -1950, 350, 75); + spawn.mapRect(225, -1950, 50, 75); + spawn.mapRect(-250, -2025, 50, 150); + spawn.mapRect(250, -2025, 50, 150); + spawn.mapRect(-250, -2250, 50, 125); + spawn.mapRect(-225, -2325, 500, 100); + spawn.mapRect(250, -2250, 50, 125); + spawn.mapRect(-100, -2400, 250, 100); + spawn.mapRect(-25, -2475, 100, 100); + spawn.mapRect(125, -2350, 50, 50); + spawn.mapRect(-125, -2350, 50, 50); + spawn.mapRect(-50, -2425, 50, 50); + spawn.mapRect(50, -2425, 50, 50); + spawn.mapRect(-250, -2350, 50, 50); + spawn.mapRect(250, -2350, 50, 50); + spawn.mapRect(-75, -1975, 200, 50); + spawn.mapRect(-50, -2000, 150, 50); + spawn.mapRect(100, -1950, 50, 75); + spawn.mapRect(-75, -2250, 200, 50); + spawn.mapRect(-50, -2225, 150, 50); + spawn.mapRect(-2950, -1900, 3100, 900); + spawn.mapRect(225, -1900, 2875, 900); + spawn.mapRect(-2950, -600, 6050, 450); + spawn.mapRect(-3050, -500, 200, 350); + spawn.mapRect(-3150, -400, 200, 250); + spawn.mapRect(-3250, -300, 200, 150); + spawn.mapRect(2950, -1050, 150, 500); + spawn.mapRect(-4675, -1900, 1825, 200); + spawn.mapRect(-5325, -1900, 675, 900); + spawn.mapRect(-5325, -250, 2100, 100); + spawn.mapRect(-5325, -600, 675, 450); // - + spawn.mapRect(-4700, -500, 150, 350); + spawn.mapRect(-4650, -400, 200, 250); + spawn.mapRect(-4550, -300, 200, 150); + spawn.mapRect(-3875, -1025, 100, 100); + spawn.mapRect(-3800, -1050, 50, 50); + spawn.mapRect(-3900, -1050, 50, 50); + spawn.mapRect(-3800, -950, 50, 50); + spawn.mapRect(-3900, -950, 50, 50); + spawn.mapRect(-6925, -1175, 1700, 175); + spawn.mapRect(-6925, -600, 1725, 175); + spawn.mapRect(-7700, -600, 800, 425);// - + spawn.mapRect(-7800, -2950, 175, 2775); + spawn.mapRect(-7075, -2950, 175, 1950); + spawn.mapRect(-9150, -2975, 1525, 175); + spawn.mapRect(-7075, -2975, 1150, 175); + spawn.mapRect(-6100, -3900, 175, 1100); + spawn.mapRect(-9150, -3975, 3225, 175); + spawn.mapRect(-9175, -3850, 75, 75); + spawn.mapRect(-9625, -3825, 500, 150); + spawn.mapRect(-9650, -3725, 75, 75); + spawn.mapRect(-10100, -3700, 500, 150); + spawn.mapRect(-10100, -2975, 975, 175); + spawn.mapRect(-10125, -3600, 75, 75); + spawn.mapRect(-10575, -3575, 500, 150); + spawn.mapRect(-10575, -2975, 500, 175); + spawn.mapRect(-11325, -2975, 250, 175); + spawn.mapRect(-11325, -3575, 175, 775); + // spawn.mapRect(-11325, -3575, 800, 150); + spawn.mapRect(-11225, -2975, 150, 2000); + spawn.mapRect(-10575, -2975, 150, 2500); + spawn.mapRect(-11650, -550, 1225, 150); + spawn.mapRect(-11650, -1100, 575, 150); + spawn.mapRect(-14675, -2525, 2925, 150); + spawn.mapRect(-11900, -2525, 150, 1575); + spawn.mapRect(-11850, -1100, 250, 150); + spawn.mapRect(-11875, -550, 275, 150); + spawn.mapRect(-11900, -550, 150, 350); + spawn.mapRect(-14675, -2525, 150, 2300); + spawn.mapRect(-14675, -375, 2925, 175); + spawn.mapRect(2725, -625, 250, 50); + spawn.mapRect(2625, -1025, 100, 225); + spawn.mapRect(2700, -1025, 300, 125); + spawn.mapRect(2625, -612.5, 125, 50); + spawn.mapRect(-3950, -1725, 250, 50); + spawn.mapRect(-7650, -3825, 600, 50); + spawn.mapRect(-13900, -2400, 200, 50); + spawn.mapVertex(-11957, -430, '-175 175 0 175 0 0'); + spawn.mapVertex(-14470, -430, '175 175 0 175 0 0'); + spawn.mapVertex(-11957, -2319, '-175 -175 0 -175 0 0'); + spawn.mapVertex(-14470, -2319, '0 0 0 -175 175 -175'); + //spawn.mapRect(-13900, -2150, 1375, 125); + // const sword = function() { //the ultimate blade of las destruction // NO SWORD NO DROPS >:( + // mobs.spawn(player.position.x, player.position.y, 5, 30, "transparent"); + // let me = mob[mob.length - 1]; + // Matter.Body.setDensity(me, 1); + // me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + // me.collisionFilter.category = cat.bullet; + // me.collisionFilter.mask = cat.mob | cat.mobBullet; + // me.isDropPowerUp = false; + // me.isShielded = true; + // me.showHealthBar = false; + // me.isUnblockable = true; + // me.leaveBody = false; + // me.isBadTarget = true; + // me.stroke = "transparent"; + // me.isSword = true; + // let index = 0; + // let radius = 50; + // // const len = cons.length; + // // cons[len] = Constraint.create({ + // // pointA: player.position, + // // bodyB: me, + // // stiffness: 0.14, + // // damping: 0.5 + // // }); + // // setTimeout(function(){ + // // Composite.add(engine.world, cons[cons.length - 1]); + // // }, 1) + // // cons[len].length = 100 + 1.5 * radius; + // me.do = function() { + // // this.health = Infinity;//just in case + // // for(let i = 0; i < mob.length; i++) { + // // if(Matter.Query.collides(this, [mob[i]]).length > 0 && !mob[i].isSword) { + // // const dmg = 0.25;//do not nerf + // // mob[i].damage(dmg, true); + // // simulation.drawList.push({ //add dmg to draw queue + // // x: mob[i].position.x, + // // y: mob[i].position.y, + // // radius: Math.sqrt(dmg) * 50, + // // color: simulation.mobDmgColor, + // // time: simulation.drawTime + // // }); + // // break + // // } + // // } + // Matter.Body.setPosition(this, { + // x: player.position.x + Math.cos(m.angle) * 100, + // y: player.position.y - (input.down ? 0 : 30) + Math.sin(m.angle) * 100 + // }) + // // this.force.x = Math.cos(m.angle) * 350; + // // this.force.y = Math.sin(m.angle) * 350; + // Matter.Body.setAngle(this, m.angle + Math.PI * 2); + // const setNoseShape = () => { + // const mag = radius + radius * 10; + // this.vertices[2].x = this.position.x + Math.cos(this.angle) * mag; + // this.vertices[2].y = this.position.y + Math.sin(this.angle) * mag; + // this.vertices[4].x = this.position.x + Math.cos(this.angle) * mag; + // this.vertices[4].y = this.position.y + Math.sin(this.angle) * mag; + // this.vertices[0].x = this.position.x + Math.cos(this.angle) * mag; + // this.vertices[0].y = this.position.y + Math.sin(this.angle) * mag; + // }; + // const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[2], this.position)), radius * 100) + // const spike2 = Vector.mult(Vector.normalise(Vector.sub(this.vertices[4], this.position)), radius * 500) + // const spike3 = Vector.mult(Vector.normalise(Vector.sub(this.vertices[0], this.position)), radius * 500) + // this.vertices[2].x = this.position.x + spike.x / 100 + // this.vertices[2].y = this.position.y + spike.y / 100 + // this.vertices[4].x = this.position.x + spike2.x / 75 + // this.vertices[4].y = this.position.y + spike2.y / 75 + // this.vertices[0].x = this.position.x + spike3.x / 75 + // this.vertices[0].y = this.position.y + spike3.y / 75 + // if(index == 0) { + // setNoseShape(); + // index++; + // } + // ctx.save() + // ctx.beginPath(); + // const vertices = this.vertices; + // ctx.lineWidth = 100; + // ctx.moveTo(vertices[0].x, vertices[0].y); + // for (let j = 1, len = vertices.length; j < len; ++j) ctx.lineTo(vertices[j].x, vertices[j].y); + // ctx.lineTo(vertices[0].x, vertices[0].y); + // const gradient = ctx.createRadialGradient(this.position.x, this.position.y, 15, this.position.x, this.position.y, Math.abs(275 * Math.sin(simulation.cycle / 50)) + 15); + // // Add three color stops + // gradient.addColorStop(0, m.eyeFillColor); + // gradient.addColorStop(0.9, "white"); + // gradient.addColorStop(1, "darkgray"); + // ctx.fillStyle = gradient; + // ctx.strokeStyle = "transparent"; + // ctx.shadowBlur = 10; + // ctx.shadowColor = m.eyeFillColor; + // ctx.fill(); + // ctx.stroke(); + // ctx.restore() + + // const Dx = Math.cos(m.angle); + // const Dy = Math.sin(m.angle); + // let xElec = this.position.x + 10 * Dx; + // let yElec = this.position.y + 10 * Dy; + // ctx.beginPath(); + // ctx.moveTo(xElec, yElec); + // const step = 40 + // for (let i = 0; i < 6; i++) { + // xElec += step * (Dx + 1.5 * (Math.random() - 0.5)) + // yElec += step * (Dy + 1.5 * (Math.random() - 0.5)) + // ctx.lineTo(xElec, yElec); + // } + // ctx.strokeStyle = m.eyeFillColor; + // ctx.lineWidth = 1.5; + // ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + // ctx.stroke(); // Draw it + // ctx.setLineDash([]); + // if(this.alive && m.energy > 0) { + // const gradient = ctx.createRadialGradient(this.position.x, this.position.y, 0, this.position.x, this.position.y, Math.abs(20 * Math.cos(simulation.cycle / 50))); + // // Add three color stops + // gradient.addColorStop(0, m.eyeFillColor); + // gradient.addColorStop(0.9, "white"); + // gradient.addColorStop(1, "gray"); + // ctx.save() + // ctx.beginPath() + // ctx.moveTo(this.position.x, this.position.y) + // ctx.arc(this.position.x, this.position.y, 20, 0, 2 * Math.PI) + // ctx.fillStyle = gradient; + // ctx.strokeStyle = "transparent"; + // ctx.shadowBlur = 10; + // ctx.shadowColor = m.eyeFillColor; + // ctx.fill() + // ctx.stroke() + // ctx.restore() + // m.energy -= 0.002; + + // ctx.save() + // ctx.translate(this.vertices[2].x, this.vertices[2].y) + // ctx.rotate(m.angle + Math.PI / 2) + // ctx.beginPath() + // ctx.font = "16px Arial"; + // ctx.fillStyle = "black"; + // ctx.strokeStyle = "black"; + // // ctx.fillText("Θ", 0,0 - 110) + // // ctx.fillText("ά", 0,15 - 110) + // // ctx.fillText("ν", 0,30 - 110) + // // ctx.fillText("α", 0,45 - 110) + // // ctx.fillText("τ", 0,60 - 110) + // // ctx.fillText("ο", 0,75 - 110) + // // ctx.fillText("ς", 0,90 - 110) + // ctx.fillText("Ω", 0,55) + // ctx.fill() + // ctx.stroke() + // ctx.restore() + + // simulation.drawList.push({ + // x: this.position.x + Math.floor(Math.random() * 300 - Math.random() * 300), + // y: this.position.y + Math.floor(Math.random() * 300 - Math.random() * 300), + // radius: 2, + // color: m.eyeFillColor, + // time: simulation.drawTime + // }); + // } else { + // this.death() + // powerUps.activated = false + // } + // // me.onDeath = function() { + // // this.removeCons(); + // // }; + // } + // } + //setTimeout(function() {sword();}, 100); + const wire = function () { + const breakingPoint = -1600; + const spawnx = -13800 + Math.floor(Math.random() * 100 - Math.random() * 100); + mobs.spawn(spawnx, -2375, 0, 2, "transparent"); + let me = mob[mob.length - 1]; + let boss = mob[0]; + me.collisionFilter.category = cat.body; + me.collisionFilter.mask = cat.map; + me.g = 0.0003; //required for gravity + me.restitution = 0; + me.stroke = "transparent" + me.freeOfWires = false; + me.frictionAir = 0.01; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.isBadTarget = true; + me.isUnblockable = true; + const wireX = spawnx; + const wireY = -2375; + //const randomw = Math.floor(Math.random() * 100 - Math.random() * 100); + const width = Math.abs(10 + Math.floor(Math.random() * 10 - Math.random() * 10)); + const randomx = Math.floor(30 * Math.random() - 30 * Math.random()); + const randomy = Math.floor(10 * Math.random() - 10 * Math.random()) + me.do = function () { + if (this.freeOfWires) { + this.gravity(); + } else { + if (boss.position.y > breakingPoint) { + this.freeOfWires = true; + this.force.y -= -0.0006; + this.force.x += Math.random() * boss.velocity.x / 10000; + this.fill = "#111"; + } + //move mob to mob + Matter.Body.setPosition(this, { + x: boss.position.x + randomx, + y: boss.position.y + randomy + }) + } + //draw wire + ctx.beginPath(); + ctx.moveTo(wireX, wireY); + ctx.quadraticCurveTo(wireX, -100, this.position.x, this.position.y); + ctx.lineWidth = width; + ctx.lineCap = "butt"; + ctx.strokeStyle = "#111"; + ctx.stroke(); + ctx.lineCap = "round"; + }; + } + + const ball = function (x, y, radius = 11 * tech.bulletSize, sides = 70) {//superball //also, why is it called superballs? + mobs.spawn(x, y, sides, radius, "rgba(0,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 20, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + }; + Matter.Body.setDensity(me, 0.00001); //normal is 0.001 + me.timeLeft = 500; + me.friction = 0; + me.restitution = 1; + me.leaveBody = false; + me.isDropPowerUp = false; + //me.inertia = Infinity; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet | cat.player | cat.map | cat.body; + let index = 0; + me.do = function () { + this.timeLimit(); + this.alwaysSeePlayer() + this.force.y += this.mass * 0.0012; + } + } + const normalBullet = function (x, y, radius = 9, sides = 3) { + //bullets + mobs.spawn(x, y, sides, radius, "rgba(0,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + me.onHit = function () { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 20, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + }; + Matter.Body.setDensity(me, 0.00004); //normal is 0.001 + me.timeLeft = 220; + me.frictionAir = -0.01; + me.restitution = -1; + me.leaveBody = false; + me.isDropPowerUp = false; + //me.inertia = Infinity; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = null; + me.boss = null; + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].restoreBoss) { + me.boss = mob[i]; + } + } + let index = 0; + me.do = function () { + this.timeLimit(); + this.alwaysSeePlayer() + const setNoseShape = () => { + const mag = this.radius + this.radius * 10; + this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag; + const angle = Math.atan2(this.position.y - me.boss.position.y, this.position.x - me.boss.position.x); + Matter.Body.setAngle(this, angle); + }; + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[1], this.position)), radius * 1000) + this.vertices[1].x = this.position.x + spike.x / 100 + this.vertices[1].y = this.position.y + spike.y / 100 + if (index == 0) { + setNoseShape(); + index++; + } + if (Matter.Query.collides(this, map).length > 0 || Matter.Query.collides(this, body).length > 0) { + const slow = 0.69 //im sorry it looks cool though + Matter.Body.setVelocity(this, { + x: this.velocity.x * slow, + y: this.velocity.y * slow + }); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 10, + color: '#000000', + time: simulation.drawTime + }); + if (this.velocity.x == 0 && this.velocity.y == 0) { + this.death(); + } + this.frictionAir += 0.0001; + Matter.Body.setAngularVelocity(this, 0) + } + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles // I wasnt gonna add this but since ya'll would have killed me if I didn't I added this + const dmg = 0.013 * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.sqrt(dmg) * 200, + color: '#000000', + time: simulation.drawTime + }); + } + }; + } + const foamBullet = function (x, y, radius = 9, sides = 70) { //bullets + mobs.spawn(x, y, sides, radius, "rgb(0,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.00005); //normal is 0.001 + me.timeLeft = 120; + // me.g = 0.0005; //required if using this.gravity + me.accelMag = 0.00006; + me.isVerticesChange = true + me.delay = 360 * simulation.CDScale; + me.spikeVertex = 0; + me.spikeLength = 0; + me.isSpikeGrowing = false; + me.spikeGrowth = 0; + me.isSpikeReset = false; + me.frictionAir = 0; + me.restitution = 0; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.isUnblockable = true; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.body //| cat.bullet;// | cat.player; + me.do = function () { + if (this.distanceToPlayer2() < 40000) { + this.force = Vector.mult(Vector.normalise(Vector.sub(player.position, this.position)), this.mass * 0.004) + const slow = 0.99999999999999999; + Matter.Body.setVelocity(this, { + x: this.velocity.x * slow, + y: this.velocity.y * slow + }); + } + // this.gravity(); + this.timeLimit(); + // for (let i = 0, len = this.vertices.length; i < len; i++) { + // const dist = Vector.sub(this.seePlayer.position, this.vertices[i]); + // const distMag = Vector.magnitude(dist); + // const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[i], this.position)), radius * distMag) + // this.vertices[i].x = this.position.x + spike.x / 100 + // this.vertices[i].y = this.position.y + spike.y / 100 + // } + if (this.radius < 50) { + const scale = 1.05; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + } + if (Matter.Query.collides(this, map).length > 0 || Matter.Query.collides(this, body).length > 0 && this.speed < 10) { + const slow = 0.97 + Matter.Body.setVelocity(this, { + x: this.velocity.x * slow, + y: this.velocity.y * slow + }); + const SCALE = 0.9 + Matter.Body.scale(this, SCALE, SCALE); + this.radius *= SCALE; + if (this.radius < 1) { + this.death() + } + } else { + this.attach(); + } + + }; + me.attach = function () { + if (Matter.Query.collides(this, [player]).length > 0) { + Matter.Body.setPosition(this, player.position) + if (player.speed > 2.5) Matter.Body.setVelocity(player, Vector.mult(player.velocity, 0.94)) + Matter.Body.setAngularVelocity(player, player.angularVelocity * 0.9); + m.damage(0.00003); //balanced? not sure + } + } + }; + + const orbital = function (who, radius, phase, speed, radius2) {//basically orbitBot + mobs.spawn(who.position.x, who.position.y, 8, 12, "rgba(0,0,0, 1)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.01); //normal is 0.001 + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.showHealthBar = false; + me.isOrbital = true; + me.isShielded = true + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet; //cat.player | cat.map | cat.body + me.do = function () { + //if host is gone + if (!who || !who.alive) { + this.death(); + return + } + //set orbit + const time = simulation.cycle * speed + phase + const orbit = { + x: Math.cos(time), + y: Math.sin(time) + } + Matter.Body.setPosition(this, Vector.add(Vector.add(who.position, who.velocity), Vector.mult(orbit, radius + radius2))) + //damage player + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + const dmg = 0.013 * simulation.dmgScale + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + //this.death(); + } + }; + } + const missile = function (where, speed = 0.007, size = 1) { + mobs.spawn(where.x, where.y, 3, 20, '#000000'); + let me = mob[mob.length - 1]; + me.accelMag = speed; + Matter.Body.setDensity(me, 0.0000000000001); + me.stroke = 'transparent'; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet | cat.player | cat.map | cat.body; + me.leaveBody = false; + me.isDropPowerUp = false; + me.onHit = function () { + b.explosion(this.position, (tech.isMissileBig ? 230 : 180) + 60 * Math.random()) + this.death() + } + me.do = function () { + this.seePlayerByHistory(); + this.alwaysSeePlayer(); + this.attraction(); + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + Matter.Body.setAngle(this, angle); + // ctx.beginPath() + // ctx.strokeStyle = "rgba(255,155,0,0.5)"; + // ctx.lineWidth = 15; + // ctx.arc(this.vertices[0].x, this.vertices[0].x, 15, 0, 2 * Math.PI); + // ctx.stroke() + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 10, + color: `rgba(255,155,0,${Math.random()})`, + time: simulation.drawTime + }); + } + } + const railBullet = function (x, y) { + mobs.spawn(x, y, 5, 20, "black"); + let me = mob[mob.length - 1]; + me.stroke = "black"; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + me.onHit = function () { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: 20, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + }; + Matter.Body.setDensity(me, 0.00004); //normal is 0.001 + me.timeLeft = 220; + me.frictionAir = -0.01; + me.restitution = -1; + me.leaveBody = false; + me.isDropPowerUp = false; + //me.inertia = Infinity; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.player; + const radius = 30; + let index = 0; + me.do = function () { + this.timeLimit(); + this.alwaysSeePlayer() + const setNoseShape = () => { + const mag = me.radius + me.radius * 10; + const angle = Math.atan2(me.seePlayer.position.y - this.position.y, me.seePlayer.position.x - this.position.x); + me.vertices[2].x = this.position.x + Math.cos(this.angle) * mag; + me.vertices[2].y = this.position.y + Math.sin(this.angle) * mag; + me.vertices[4].x = this.position.x + Math.cos(this.angle) * mag; + me.vertices[4].y = this.position.y + Math.sin(this.angle) * mag; + me.vertices[0].x = this.position.x + Math.cos(this.angle) * mag; + me.vertices[0].y = this.position.y + Math.sin(this.angle) * mag; + Matter.Body.setAngle(this, angle); + }; + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[2], me.position)), radius * 1000) + const spike2 = Vector.mult(Vector.normalise(Vector.sub(this.vertices[4], me.position)), radius * 1000) + const spike3 = Vector.mult(Vector.normalise(Vector.sub(this.vertices[0], me.position)), radius * 1000) + me.vertices[2].x = this.position.x + spike.x / 100 + me.vertices[2].y = this.position.y + spike.y / 100 + me.vertices[4].x = this.position.x + spike2.x / 75 + me.vertices[4].y = this.position.y + spike2.y / 75 + me.vertices[0].x = this.position.x + spike3.x / 75 + me.vertices[0].y = this.position.y + spike3.y / 75 + if (index == 0) { + setNoseShape(); + index++; + } + if (Matter.Query.collides(this, map).length > 0 || Matter.Query.collides(this, body).length > 0) { + const slow = 0.69 //im sorry it looks cool though + Matter.Body.setVelocity(this, { + x: this.velocity.x * slow, + y: this.velocity.y * slow + }); + // simulation.drawList.push({ //add dmg to draw queue + // x: this.position.x, + // y: this.position.y, + // radius: 10, + // color: '#000000', + // time: simulation.drawTime + // }); + if (this.velocity.x == 0 && this.velocity.y == 0) { + this.death(); + } + this.frictionAir += 0.0001; + Matter.Body.setAngularVelocity(this, 0) + } + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles // I wasnt gonna add this but since ya'll would have killed me if I didn't I added this + const dmg = 0.013 * simulation.dmgScale; + m.damage(dmg); + // simulation.drawList.push({ //add dmg to draw queue + // x: this.position.x, + // y: this.position.y, + // radius: Math.sqrt(dmg) * 200, + // color: '#000000', + // time: simulation.drawTime + // }); + } + }; + } + const grenade = function (x, y, lifeSpan = 90 + Math.ceil(60 / simulation.accelScale), pulseRadius = Math.min(550, 250 + simulation.difficulty * 3), size = 3) { + mobs.spawn(x, y, 4, size, "rgb(0,0,0)"); //rgb(215,80,190) + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + this.explode(this.mass); + }; + Matter.Body.setDensity(me, 0.00004); //normal is 0.001 + + me.lifeSpan = lifeSpan; + me.timeLeft = me.lifeSpan; + // me.g = 0.0002; //required if using this.gravity + me.frictionAir = 0; + me.restitution = 0.8; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.onDeath = function () { + //damage player if in range + if (Vector.magnitude(Vector.sub(player.position, this.position)) < pulseRadius && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage + m.damage(0.015 * simulation.dmgScale); + } + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: pulseRadius, + color: "rgba(0,0,0,0.3)", + time: simulation.drawTime + }); + }; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.map | cat.body | cat.player + // me.collisionFilter.mask = 0 + me.do = function () { + this.timeLimit(); + ctx.save() + ctx.beginPath(); //draw explosion outline + ctx.arc(this.position.x, this.position.y, pulseRadius * (1.01 - this.timeLeft / this.lifeSpan), 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = "rgba(0,0,0,0.05)"; + ctx.fill(); + ctx.restore() + }; + } + const sniper = function (x, y, radius = 30) { + mobs.spawn(x, y, 8, radius, '#00000000'); + let me = mob[mob.length - 1]; + me.accelMag = 0.0003 + me.stroke = 'transparent'; + //me.isBoss = true; + me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; + me.frictionStatic = 0; + me.friction = 0; + me.seeAtDistance2 = 20000000 //14000 vision range + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.showHealthBar = false + Matter.Body.setDensity(me, 0.01) + me.fireDir = { x: 0, y: 0 } + me.seePlayerFreq = 0 + me.repulsionRange = 400000 + radius * radius; + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob | cat.mobBullet + me.do = function () { + this.seePlayerCheck(); + this.attraction(); + this.repulsion(); + this.search() + if (this.seePlayer.recall) { + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(0,255,255,0.7)"; + ctx.fillRect(x, y, w * this.health, h); + } + if (this.health < 1) { + this.health += 0.0005; //regen + } + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + if (this.seePlayer.recall > 0 && this.distanceToPlayer2() > this.repulsionRange) { + var grd2 = ctx.createLinearGradient(0, 0, -150, 0); + // grd2.addColorStop(0, 'rgba(255, 255, 155, 0.8)'); + // grd2.addColorStop(1, 'rgba(255, 200, 0, 0.1)'); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(-18, -25); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(-18, 25); + ctx.lineTo(-50 - 100 * Math.random(), 0); + ctx.fill(); + } else if (this.distanceToPlayer2() < this.repulsionRange) { + var grd2 = ctx.createLinearGradient(0, 0, 80, 0); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(20, -16); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(20, 16); + ctx.lineTo(35 + 43 * Math.random(), 0); + ctx.fill(); + } + ctx.restore() + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.beginPath(); //eye + ctx.arc(15, 0, 3.5, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(255, 0, 0, ${this.health * this.health})`; + ctx.fill() + ctx.restore() + //set direction to turn to fire + if (this.seePlayer.recall && !(simulation.cycle % 30)) { + this.seePlayer.recall -= 10; + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + spawn.sniperBullet(this.position.x, this.position.y, 7 + Math.ceil(this.radius / 15), 5); + const v = 10 + 8 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + }; + } + const laserEM = function (x, y, radius = 30) { + mobs.spawn(x, y, 8, radius, '#00000000'); + let me = mob[mob.length - 1]; + me.accelMag = 0.0003 + me.stroke = 'transparent'; + //me.isBoss = true; + me.frictionStatic = 0; + me.friction = 0; + me.seeAtDistance2 = 20000000 //14000 vision range + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.showHealthBar = false + Matter.Body.setDensity(me, 0.01) + me.seePlayerFreq = 0 + me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; + me.swordDamage = 0.025 * simulation.dmgScale + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob | cat.mobBullet + me.repulsionRange = 50000; + me.do = function () { + this.repulsion(); + this.search() + if (this.seePlayer.recall) { + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(0,255,255,0.7)"; + ctx.fillRect(x, y, w * this.health, h); + } + if (this.health < 1) { + this.health += 0.0005; //regen + } + if (this.seePlayer.recall) { + this.laserSword(this.position, Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x), 500 * Math.random()); + } + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + if (this.seePlayer.recall > 0 && this.distanceToPlayer2() > this.repulsionRange) { + var grd2 = ctx.createLinearGradient(0, 0, -150, 0); + // grd2.addColorStop(0, 'rgba(255, 255, 155, 0.8)'); + // grd2.addColorStop(1, 'rgba(255, 200, 0, 0.1)'); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(-18, -25); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(-18, 25); + ctx.lineTo(-50 - 100 * Math.random(), 0); + ctx.fill(); + } else if (this.distanceToPlayer2() < this.repulsionRange) { + var grd2 = ctx.createLinearGradient(0, 0, 80, 0); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(20, -16); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(20, 16); + ctx.lineTo(35 + 43 * Math.random(), 0); + ctx.fill(); + } + ctx.restore() + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.beginPath(); //eye + ctx.arc(15, 0, 3.5, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(255, 0, 0, ${this.health * this.health})`; + ctx.fill() + ctx.restore() + this.seePlayerCheck(); + this.attraction(); + } + me.laserSword = function (where, angle, length) { + const sub = Vector.sub(this.seePlayer.position, this.position) + const unit = Vector.normalise(sub) + const path = [{ + x: this.position.x + 20 * Math.cos(this.angle), + y: this.position.y + 20 * Math.sin(this.angle) + }, + { + x: this.position.x + (120 + 400) * Math.sqrt(Math.random()) * Math.cos(this.angle), + y: this.position.y + (120 + 400) * Math.sqrt(Math.random()) * Math.sin(this.angle) + } + ]; + this.seePlayer.recall -= 3; + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: vertices[j], v2: vertices[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: vertices[0], v2: vertices[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + length * Math.cos(angle), y: where.y + length * Math.sin(angle) }; + // vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [player]); + if (best.who && (best.who === player) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "#50f"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(80,0,255,0.07)"; + ctx.stroke(); // Draw it + + const Dx = Math.cos(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)); + const Dy = Math.sin(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)); + let xElec = this.position.x + 40 * Dx; + let yElec = this.position.y + 40 * Dy; + ctx.beginPath(); + ctx.moveTo(xElec, yElec); + const step = 40 + for (let i = 0; i < 6; i++) { + xElec += step * (Dx + 1.5 * (Math.random() - 0.5)) + yElec += step * (Dy + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(xElec, yElec); + } + ctx.strokeStyle = "#50f"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }; + const restoreBoss = function (x, y, radius = 30) { //ATTENTION LANDGREEN: RESTOREBOSS WILL NOT DROP ANY TECH, NOR WILL THERE BE ANY IN THE MAP. DO NOT ADD ANY TECH TO MY MAP + mobs.spawn(x, y, 8, radius, 'transparent'); + let me = mob[mob.length - 1]; + me.stroke = 'transparent'; + let aim = '#FFFFFF'; + me.accelMag = 0.0006 + me.isBoss = true; + me.restoreBoss = true; + me.frictionStatic = 0; + me.friction = 0; + me.seeAtDistance2 = 20000000 //14000 vision range + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.showHealthBar = false + Matter.Body.setDensity(me, m.maxHealth / (simulation.difficulty < 5 ? 0.5 : simulation.difficulty / simulation.difficultyMode)) + me.seePlayerFreq = 0 + me.swordDamage = 0.025 * simulation.dmgScale + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob | cat.mobBullet + me.repulsionRange = 500000; + me.isDropPowerUp = false; + //Matter.Body.setVelocity(me, { x: 10 * (Math.random() - 0.5), y: 10 * (Math.random() - 0.5) }); + let index = 0; + me.curlRange = 10000; //xd + me.fieldPhase = 0; + me.energy = 1; + me.maxEnergy = 1; + me.immuneCycle = 0; + me.cycle = 0; + // me.onDeath = function() { + // powerUps.spawn(this.position.x, this.position.y, "loadOut"); + // } + for (let i = 0; i < b.totalBots(); i++) { //normal orbitals look too boring, so... + orbital(me, 190 + 130 * tech.isOrbitBotUpgrade, (index / b.totalBots()) * 2 * Math.PI, 0.05, Math.floor(Math.sin(simulation.cycle / 10) * 100)); //who, radius, phase, speed + index++; + } + me.do = function () { + if (this.position.x > -11500 && this.position.x < 10510) {// doesn't get one tapped by the elevator + me.collisionFilter.mask = cat.bullet | cat.player | cat.map | cat.mob | cat.mobBullet; + } else { + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob | cat.mobBullet; + } + this.cycle++; + if ((Matter.Query.ray(map, player.position, this.position).length === 0) == false) { + this.seePlayer.recall = null; + } + if (this.seePlayer.recall) { //fields + if (m.fieldMode == 0 && this.distanceToPlayer2() < 200000) { + if (Vector.magnitude(Vector.sub(m.pos, this.position)) - this.radius < m.fieldRange) { + this.pushM(); + } + this.drawField(); + // this.repel(); + } + if (m.fieldMode == 2) { + if (this.distanceToPlayer2() < 200000) { + if (Vector.magnitude(Vector.sub(m.pos, this.position)) - this.radius < m.fieldRange) { + this.pushM(); + } + this.drawField() + } + if (tech.isPerfectBrake) { //cap player and bullet speed around restoreBoss //mobs basically can't hit you when you have this, so to make it fair... + const wave = Math.cos(m.cycle * 0.022); + const range = 200 + 140 * wave + 150 * m.energy + const distance = Vector.magnitude(Vector.sub(this.position, m.pos)) + const cap = this.immuneCycle > this.cycle ? 8 : 4 + if (distance < range) { + if (player.speed > cap && Vector.dot(player.velocity, Vector.sub(this.position, m.pos)) > 0) { // if velocity is directed towards player + Matter.Body.setVelocity(player, Vector.mult(Vector.normalise(player.velocity), cap)); //set velocity to cap, but keep the direction + } + } + for (let i = 0; i < bullet.length; i++) { + const distance2 = Vector.magnitude(Vector.sub(this.position, bullet[i].position)) + if (distance2 < range) { + if (bullet[i].speed > cap && Vector.dot(bullet[i].velocity, Vector.sub(this.position, bullet[i].position)) > 0) { // if velocity is directed towards player + Matter.Body.setVelocity(bullet[i], Vector.mult(Vector.normalise(bullet[i].velocity), cap)); //set velocity to cap, but keep the direction + } + } + } + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, range, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.08)"; + ctx.fill(); + } + } + if (m.fieldMode == 5 && this.distanceToPlayer2() < 200000) { + this.laserSword(this.position, Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x), 500 * Math.random()); + } + if (m.fieldMode == 9) { + if (this.distanceToPlayer2() < 300000) { + this.teleportAway() //blink but reversed + } + } + } + if (m.immuneCycle > m.cycle) { + me.damageReduction = 0; + } else { + me.damageReduction = 1; + } + this.repulsion(); + this.seePlayerCheck(); + this.attraction(); + this.lostPlayer(); + if (this.speed > 10) { // speed cap + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.99, + y: this.velocity.y * 0.99 + }); + } + if (this.seePlayer.recall) { + const angle = Math.atan2(this.position.y - player.position.y, this.position.x - player.position.x); + let positionR = { x: 500 * Math.cos(angle) + mob[0].position.x, y: 500 * Math.sin(angle) + mob[0].position.y }; + let isWall = (Matter.Query.ray(map, mob[0].position, positionR).length === 0); + let isBlock = (Matter.Query.ray(body, mob[0].position, positionR).length === 0); + if (isWall == false || isBlock == false) { + this.force.x -= Math.cos(angle) * 10; + this.force.y -= Math.sin(angle) * 10; + } + } + if (this.seePlayer.recall) { + const angle = Math.atan2(this.position.y - player.position.y, this.position.x - player.position.x) - Math.PI * 1.5; + let positionR = { x: 5000 * Math.cos(angle) + mob[0].position.x, y: 5000 * Math.sin(angle) + mob[0].position.y }; + let isBullet = (Matter.Query.ray(bullet, mob[0].position, positionR).length === 0); + if (isBullet == false) { + this.force.x -= Math.cos(angle) * 30; + this.force.y -= Math.sin(angle) * 30; + } + } + if (this.seePlayer.recall) { + const angle = Math.atan2(this.position.y - player.position.y, this.position.x - player.position.x) - Math.PI * 2.5; + let positionR = { x: 5000 * Math.cos(angle) + mob[0].position.x, y: 5000 * Math.sin(angle) + mob[0].position.y }; + let isBullet = (Matter.Query.ray(bullet, mob[0].position, positionR).length === 0); + if (isBullet == false) { + this.force.x -= Math.cos(angle) * 30; + this.force.y -= Math.sin(angle) * 30; + } + } + if (this.seePlayer.recall) { + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(10, 10, 10, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(0,0,0,0.7)"; + ctx.fillRect(x, y, w * this.energy, h); + } + if (this.health < 1) { + this.health += 0.0001; //regen + } else if (this.health < 1) { + this.health += 0.00005; //reduced regen + } + if (this.energy < 0) {//energy thingy + this.energy = 0; + } else if (this.energy > this.maxEnergy) { + this.energy = this.maxEnergy; + } else if (this.energy < this.maxEnergy) { + this.energy += 0.001; + } + ctx.save() + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + if (this.seePlayer.recall > 0 && this.distanceToPlayer2() > this.repulsionRange) { + ctx.globalAlpha = (this.immuneCycle < this.cycle) ? 1 : 0.5 + var grd2 = ctx.createLinearGradient(0, 0, -150, 0); + // grd2.addColorStop(0, 'rgba(255, 255, 155, 0.8)'); + // grd2.addColorStop(1, 'rgba(255, 200, 0, 0.1)'); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(-18, -25); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(-18, 25); + ctx.lineTo(-50 - 100 * Math.random(), 0); + ctx.fill(); + } else if (this.distanceToPlayer2() < this.repulsionRange) { + ctx.globalAlpha = (this.immuneCycle < this.cycle) ? 1 : 0.5 + var grd2 = ctx.createLinearGradient(0, 0, 80, 0); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(20, -16); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(20, 16); + ctx.lineTo(35 + 43 * Math.random(), 0); + ctx.fill(); + } + ctx.restore() + ctx.save() + ctx.globalAlpha = (this.immuneCycle < this.cycle) ? 1 : 0.5 + ctx.translate(this.position.x, this.position.y) + ctx.rotate(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + if (this.health > 0.5) { + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.beginPath(); //eye + ctx.arc(15, 0, 3.5, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(255, 0, 0, ${this.health * this.health})`; + ctx.fill() + ctx.restore() + } else { + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + if (!(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) > -Math.PI / 2 && Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) < Math.PI / 2)) ctx.scale(1, -1); //here is the flip + ctx.stroke(); + ctx.beginPath(); + ctx.arc(2, -6, 7, 0, 2 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(25, -6, 7, 0.25 * Math.PI, 1.6 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(2, -10, 9, 1.25 * Math.PI, 1.75 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(25, -10, 9, 1.25 * Math.PI, 1.4 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(18, 13, 10, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient; + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(18, 13, 6, 0, 2 * Math.PI); + ctx.fillStyle = "#555"; + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(3, -6, 3, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(26, -6, 3, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + } + if (m.fieldMode == 1) { //render over I think + if (this.energy > 0.1) { + this.harmonic3Phase(); + } + } + if (m.fieldMode == 7) { + this.locatePlayer(); + } + if (m.fieldMode == 8) { + me.pilotWave() + } + if (m.fieldMode == 3) { + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + me.damageReduction = 0.5; + me.accelMag = 0.0012; + if (!(simulation.cycle % Math.floor(100 + 90 * Math.random() * simulation.CDScale))) { + this.diveAttack() + } + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, 1000, 0, 2 * Math.PI); + ctx.fillStyle = "#f5f5ff"; + ctx.strokeStyle = "#f5f5ff55"; + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + ctx.globalCompositeOperation = "difference"; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + ctx.stroke() + ctx.setLineDash([]); + } else { + me.accelMag = 0.0006; + } + if (this.immuneCycle > this.cycle) { + this.damageReduction = 0; + } else { + if (m.fieldMode == 3) { + this.damageReduction = 0.5; + } else { + this.damageReduction = 1; + } + } + if (m.fieldMode == 6) { + this.timeAttack(); + ctx.globalCompositeOperation = "saturation" + ctx.fillStyle = "#ccc"; + ctx.fillRect(-50000, -50000, 100000, 100000) + ctx.globalCompositeOperation = "source-over" + // stop time + // m.isTimeDilated = true; + // function sleep(who) { + // for (let i = 0, len = who.length; i < len; ++i) { + // if (!who[i].isSleeping) { + // who[i].storeVelocity = who[i].velocity + // who[i].storeAngularVelocity = who[i].angularVelocity + // } + // Matter.Sleeping.set(who[i], true) + // } + // } + // sleep(mob); + // sleep(body); + // sleep(bullet); + // sleep([player]); + // simulation.cycle--; + } + if (this.seePlayer.recall) { //fields + this.gun() + } + } + me.laserSword = function (where, angle, length) { + const sub = Vector.sub(this.seePlayer.position, this.position) + const unit = Vector.normalise(sub) + const path = [{ + x: this.position.x + 20 * Math.cos(this.angle), + y: this.position.y + 20 * Math.sin(this.angle) + }, + { + x: this.position.x + (120 + 400) * Math.sqrt(Math.random()) * Math.cos(this.angle), + y: this.position.y + (120 + 400) * Math.sqrt(Math.random()) * Math.sin(this.angle) + } + ]; + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: vertices[j], v2: vertices[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: vertices[0], v2: vertices[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + length * Math.cos(angle), y: where.y + length * Math.sin(angle) }; + // vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [player]); + if (best.who && (best.who === player) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(0,0,0,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(0,0,0,0.07)"; + ctx.stroke(); // Draw it + + const Dx = Math.cos(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)); + const Dy = Math.sin(Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)); + let xElec = this.position.x + 40 * Dx; + let yElec = this.position.y + 40 * Dy; + ctx.beginPath(); + ctx.moveTo(xElec, yElec); + const step = 40 + for (let i = 0; i < 6; i++) { + xElec += step * (Dx + 1.5 * (Math.random() - 0.5)) + yElec += step * (Dy + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(xElec, yElec); + } + ctx.strokeStyle = "#000"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + me.drawField = function () { + if (m.fieldMode != 2) { + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) + const range = m.fieldRange; + ctx.save() + ctx.beginPath(); + ctx.fillStyle = "rgba(0,0,0," + Math.min(0.6, (0.04 + m.energy * (0.1 + 0.11 * Math.random()))) + ")"; + ctx.arc(this.position.x, this.position.y, range, angle - Math.PI * m.fieldArc, angle + Math.PI * m.fieldArc, false); + ctx.lineWidth = 2; + ctx.stroke(); + let eye = 13; + if (m.fieldMode == 2) { + eye = 30 + } + let aMag = 0.75 * Math.PI * m.fieldArc + let a = angle + aMag + let cp1x = this.position.x + 0.6 * range * Math.cos(a) + let cp1y = this.position.y + 0.6 * range * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, this.position.x + eye * Math.cos(angle), this.position.y + eye * Math.sin(angle)) + a = angle - aMag + cp1x = this.position.x + 0.6 * range * Math.cos(a) + cp1y = this.position.y + 0.6 * range * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, this.position.x + 1 * range * Math.cos(angle - Math.PI * m.fieldArc), this.position.y + 1 * range * Math.sin(angle - Math.PI * m.fieldArc)) + ctx.fill(); + // ctx.lineTo(this.position.x + eye * Math.cos(angle), this.position.y + eye * Math.sin(angle)); + + //draw random lines in field for cool effect + let offAngle = angle + 1.7 * Math.PI * m.fieldArc * (Math.random() - 0.5); + ctx.beginPath(); + eye = 15; + ctx.moveTo(this.position.x + eye * Math.cos(angle), this.position.y + eye * Math.sin(angle)); + ctx.lineTo(this.position.x + range * Math.cos(offAngle), this.position.y + range * Math.sin(offAngle)); + ctx.strokeStyle = "rgba(0,0,0,0.6)"; + ctx.lineWidth = 1; + ctx.stroke(); + ctx.restore() + } else { + ctx.save() + ctx.beginPath(); + const wave = Math.cos(m.cycle * 0.022); + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) + ctx.arc(this.position.x, this.position.y, m.fieldRange, angle - Math.PI * m.fieldArc, angle + Math.PI * m.fieldArc, false); + ctx.lineWidth = 2.5 - 1.5 * wave; + ctx.stroke(); + const curve = 0.57 + 0.04 * wave + const aMag = (1 - curve * 1.2) * Math.PI * m.fieldArc + let a = angle + aMag + let cp1x = this.position.x + curve * m.fieldRange * Math.cos(a) + let cp1y = this.position.y + curve * m.fieldRange * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, this.position.x + 30 * Math.cos(angle), this.position.y + 30 * Math.sin(angle)) + a = angle - aMag + cp1x = this.position.x + curve * m.fieldRange * Math.cos(a) + cp1y = this.position.y + curve * m.fieldRange * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, this.position.x + 1 * m.fieldRange * Math.cos(angle - Math.PI * m.fieldArc), this.position.y + 1 * m.fieldRange * Math.sin(angle - Math.PI * m.fieldArc)) + ctx.fill(); + ctx.restore() + } + } + me.pushM = function () { + const unit = Vector.normalise(Vector.sub(this.position, player.position)) + if (tech.blockDmg) { + Matter.Body.setVelocity(player, { x: 0.5 * player.velocity.x, y: 0.5 * player.velocity.y }); + //draw electricity + const step = 40 + ctx.beginPath(); + for (let i = 0, len = 0.8 * tech.blockDmg; i < len; i++) { + let x = this.position.x - 20 * unit.x; + let y = this.position.y - 20 * unit.y; + ctx.moveTo(x, y); + for (let i = 0; i < 8; i++) { + x += step * (-unit.x + 1.5 * (Math.random() - 0.5)) + y += step * (-unit.y + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + } + if (m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + m.damage(0.025 * simulation.dmgScale) + } + ctx.lineWidth = 3; + ctx.strokeStyle = "#000"; + ctx.stroke(); + } + const massRoot = Math.sqrt(Math.min(12, Math.max(0.15, player.mass))); // masses above 12 can start to overcome the push back //idk + Matter.Body.setVelocity(player, { + x: this.velocity.x - (15 * unit.x) / massRoot, + y: this.velocity.y - (15 * unit.y) / massRoot + }); + } + me.diveAttack = function () { + const forceMag = this.accelMag * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x += 150 * forceMag * Math.cos(angle); + this.force.y += 150 * forceMag * Math.sin(angle); + ctx.beginPath() + ctx.moveTo(this.position.x + Math.sin(angle), this.position.y + Math.cos(angle)) + ctx.lineTo(this.seePlayer.position.x, this.seePlayer.position.y) + aim = '#000000'; + ctx.stroke() + } + me.phase = 2 * Math.PI * Math.random(); + me.index2 = 0; + me.pilotWave = function () { + const rotate = this.cycle * 0.008; + this.fieldPhase += 0.002; + const off1 = 1 + 0.01 * Math.sin(this.fieldPhase); + const off2 = 1 - 0.01 * Math.cos(this.fieldPhase); + ctx.save() + ctx.beginPath(); + ctx.ellipse(player.position.x, player.position.y, 1.2 * 200 * off1, 1.2 * 150 * off2, rotate, 0, 2 * Math.PI); + ctx.globalCompositeOperation = "exclusion"; //"exclusion" "difference"; + ctx.fillStyle = "#ffffff"; //"#eef"; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + ctx.beginPath(); + ctx.ellipse(player.position.x, player.position.y, 1.2 * 200 * off1, 1.2 * 150 * off2, rotate, 0, 2 * Math.PI * m.energy / m.maxEnergy); + ctx.strokeStyle = "#000000"; + ctx.lineWidth = 4; + ctx.stroke(); + ctx.restore() + const range = this.curlRange / 15, mag = -50; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + const applyCurl = function (center, array, isAntiGravity = true) { + for (let i = 0; i < array.length; ++i) { + if (!array[i].isNotHoldable) { + const sub = Vector.sub(center, array[i].position) + const radius2 = Vector.magnitudeSquared(sub); + + //if too close, like center mob or shield, don't curl // if too far don't curl + if (radius2 < range * range && radius2 > 10000) { + const curlVector = Vector.mult(Vector.perp(Vector.normalise(sub)), mag) + //apply curl force + if (array[i].isMobBullet) { + Matter.Body.setVelocity(array[i], { + x: array[i].velocity.x * 0.97 + curlVector.x * 0.06 - (Math.cos(angle) * 5), + y: array[i].velocity.y * 0.97 + curlVector.y * 0.06 - (Math.sin(angle) * 5) + }) + } else { + Matter.Body.setVelocity(array[i], { + x: array[i].velocity.x * 0.94 + curlVector.x * 0.06 - (Math.cos(angle) * 5), + y: array[i].velocity.y * 0.94 + curlVector.y * 0.06 - (Math.sin(angle) * 5) + }) + } + if (isAntiGravity) array[i].force.y -= 0.8 * simulation.g * array[i].mass + } + } + } + } + applyCurl(this.position, [player]); + } + me.teleportAway = function () {//hehe + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + if (this.seePlayer.recall && !(simulation.cycle % 17)) { + const dist = Vector.sub(this.position, this.seePlayer.position); + const distMag = Vector.magnitude(dist); + const unitVector = Vector.normalise(dist); + const rando = (Math.random() - 0.5) * 50; + if (distMag < 20000) { + Matter.Body.translate(this, Vector.mult(unitVector, distMag + rando)); + } else { + Matter.Body.translate(this, Vector.mult(unitVector, 20000 + rando)); + } + } + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = radius * 2; + ctx.strokeStyle = "rgba(0,0,0,0.08)"; + ctx.stroke(); + if (!this.seePlayer.yes) { + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + if (this.seePlayer.recall && !(simulation.cycle % 17)) { + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + const unitVector = Vector.normalise(dist); + const rando = (Math.random() - 0.5) * 50; + if (distMag < 200000) { + Matter.Body.translate(this, Vector.mult(unitVector, distMag + rando)); + } else { + Matter.Body.translate(this, Vector.mult(unitVector, 200000 + rando)); + } + } + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = radius * 2; + ctx.strokeStyle = "rgba(0,0,0,0.08)"; + ctx.stroke(); + } + } + me.timeAttack = function () { + if (this.seePlayer.recall && !(simulation.cycle % 30) || this.distanceToPlayer2() < 300) { + requestAnimationFrame(() => { + simulation.timePlayerSkip(45) + simulation.loop(); //ending with a wipe and normal loop fixes some very minor graphical issues where things are draw in the wrong locations + }); //wrapping in animation frame prevents errors, probably + } + } + me.harmonic3Phase = function () { //normal standard 3 different 2-d circles + if (tech.harmonics === 2) { + const fieldRange1 = (0.75 + 0.3 * Math.cos(m.cycle / 23)) * m.fieldRange * m.harmonicRadius + const fieldRange2 = (0.68 + 0.37 * Math.cos(m.cycle / 37)) * m.fieldRange * m.harmonicRadius + const fieldRange3 = (0.7 + 0.35 * Math.cos(m.cycle / 47)) * m.fieldRange * m.harmonicRadius + const netfieldRange = Math.max(fieldRange1, fieldRange2, fieldRange3) + ctx.fillStyle = "rgba(0,0,0," + Math.min(0.6, (0.04 + m.energy * (0.1 + 0.11 * Math.random()))) + ")"; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, fieldRange1, 0, 2 * Math.PI); + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, fieldRange2, 0, 2 * Math.PI); + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, fieldRange3, 0, 2 * Math.PI); + ctx.fill(); + //360 block + if (Vector.magnitude(Vector.sub(player.position, this.position)) - this.radius < netfieldRange) { + me.pushM(); + } + for (let i = 0; i < bullet.length; i++) { + if (Vector.magnitude(Vector.sub(bullet[i].position, this.position)) - this.radius < netfieldRange) { + const dx = bullet[i].position.x - this.position.x; + const dy = bullet[i].position.y - this.position.y; + const dist = Math.sqrt(dx * dx + dy * dy); + if (dist < m.fieldRange) { + const angle = Math.atan2(dy, dx); + const mag = (1500 * bullet[i].mass * simulation.g) / dist; + bullet[i].force.x += mag * Math.cos(angle); + bullet[i].force.y += mag * Math.sin(angle); + } + this.energy -= 0.0012; + } + } + } else { + const rotation = simulation.cycle * 0.0031 + const phase = simulation.cycle * 0.023 + const radius = m.fieldRange * m.harmonicRadius + ctx.lineWidth = 1; + ctx.strokeStyle = "rgba(0,0,0,0.5)" + ctx.fillStyle = `rgba(0,0,0,${Math.min(0.6, m.energy * (0.11 + 0.1 * Math.random()) * (3 / tech.harmonics))})`; + // ctx.fillStyle = "rgba(0,0,0," + Math.min(0.7, m.energy * (0.22 - 0.01 * tech.harmonics) * (0.5 + 0.5 * Math.random())) + ")"; + for (let i = 0; i < tech.harmonics; i++) { + ctx.beginPath(); + ctx.ellipse(this.position.x, this.position.y, radius * Math.abs(Math.sin(phase + i / tech.harmonics * Math.PI)), radius, rotation + i / tech.harmonics * Math.PI, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + } + //360 block + if (Vector.magnitude(Vector.sub(player.position, this.position)) - this.radius < radius) { + me.pushM(); + } + for (let i = 0; i < bullet.length; i++) { + if (Vector.magnitude(Vector.sub(bullet[i].position, this.position)) - this.radius < radius) { + const dx = bullet[i].position.x - this.position.x; + const dy = bullet[i].position.y - this.position.y; + const dist = Math.sqrt(dx * dx + dy * dy); + if (dist < m.fieldRange) { + const angle = Math.atan2(dy, dx); + const mag = (1500 * bullet[i].mass * simulation.g) / dist; + bullet[i].force.x += mag * Math.cos(angle); + bullet[i].force.y += mag * Math.sin(angle); + } + this.energy -= 0.0012; + } + } + } + } + me.railGun = function () { + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + const X = this.position.x + const Y = this.position.y + const unitVector = { x: Math.cos(angle), y: Math.sin(angle) } + const unitVectorPerp = Vector.perp(unitVector) + + function magField(mag, arc) { + ctx.moveTo(X, Y); + ctx.bezierCurveTo( + X + unitVector.x * mag, Y + unitVector.y * mag, + X + unitVector.x * mag + unitVectorPerp.x * arc, Y + unitVector.y * mag + unitVectorPerp.y * arc, + X + unitVectorPerp.x * arc, Y + unitVectorPerp.y * arc) + ctx.bezierCurveTo( + X - unitVector.x * mag + unitVectorPerp.x * arc, Y - unitVector.y * mag + unitVectorPerp.y * arc, + X - unitVector.x * mag, Y - unitVector.y * mag, + X, Y) + } + ctx.fillStyle = `rgba(50,20,100,0.05)`; + const magSize = 8 * c * tech.railChargeRate ** 3 + const arcSize = 6 * c * tech.railChargeRate ** 3 + for (let i = 3; i < 7; i++) { + const MAG = magSize * i * i * (0.93 + 0.07 * Math.random()) + const ARC = arcSize * i * i * (0.93 + 0.07 * Math.random()) + ctx.beginPath(); + magField(MAG, ARC) + magField(MAG, -ARC) + ctx.fill(); + } + } + me.waves = []; + me.doLongitudinal = function () { + if (!m.isTimeDilated) { + ctx.strokeStyle = "rgba(0,0,0,0.6)" //"000"; + ctx.lineWidth = 2 * tech.wavePacketDamage + ctx.beginPath(); + // const end = 1100 * tech.bulletsLastLonger / Math.sqrt(tech.waveReflections * 0.5) //should equal about 1767 + const end = 1100 * tech.bulletsLastLonger * Math.pow(0.93, tech.waveReflections) //should equal about 1767 + const damage = 0.0005 * simulation.dmgScale//normal damage for m basically shreds m, so had to nerf this + for (let i = this.waves.length - 1; i > -1; i--) { + const v1 = Vector.add(this.waves[i].position, Vector.mult(this.waves[i].unit1, this.waves[i].radius)) + const v2 = Vector.add(this.waves[i].position, Vector.mult(this.waves[i].unit2, this.waves[i].radius)) + //draw wave + ctx.moveTo(v1.x, v1.y) + ctx.arc(this.waves[i].position.x, this.waves[i].position.y, this.waves[i].radius, this.waves[i].angle, this.waves[i].angle + this.waves[i].arc); + //using small angle linear approximation of circle arc, this will not work if the arc gets large // https://stackoverflow.com/questions/13652518/efficiently-find-points-inside-a-circle-sector + let hits = Matter.Query.ray([player], v1, v2, 50) //Matter.Query.ray(bodies, startPoint, endPoint, [rayWidth]) + for (let j = 0, len = Math.min(30, hits.length); j < len; j++) { + player.force.x += 0.01 * (Math.random() - 0.5) * player.mass + player.force.y += (0.01 * (Math.random() - 0.5) - simulation.g * 0.25) * player.mass //remove force of gravity + Matter.Body.setVelocity(player, { //friction + x: player.velocity.x * 0.95, + y: player.velocity.y * 0.95 + }); + m.damage(damage) + } + hits = Matter.Query.ray(body, v1, v2, 50) + for (let j = 0, len = Math.min(30, hits.length); j < len; j++) { + const who = hits[j].body + //make them shake around + who.force.x += 0.01 * (Math.random() - 0.5) * who.mass + who.force.y += (0.01 * (Math.random() - 0.5) - simulation.g * 0.25) * who.mass //remove force of gravity + + let vertices = who.vertices; + const vibe = 25 + ctx.moveTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x + vibe * (Math.random() - 0.5), vertices[j].y + vibe * (Math.random() - 0.5)); + } + ctx.lineTo(vertices[0].x + vibe * (Math.random() - 0.5), vertices[0].y + vibe * (Math.random() - 0.5)); + + if (tech.isPhononBlock && !who.isNotHoldable && who.speed < 5 && who.angularSpeed < 0.1) { + if (Math.random() < 0.5) b.targetedBlock(who, 50 - Math.min(25, who.mass * 3)) // targetedBlock(who, speed = 50 - Math.min(20, who.mass * 2), range = 1600) { + // Matter.Body.setAngularVelocity(who, (0.25 + 0.12 * Math.random()) * (Math.random() < 0.5 ? -1 : 1)); + who.torque += who.inertia * 0.001 * (Math.random() - 0.5) + } + } + // ctx.stroke(); //draw vibes + this.waves[i].radius += tech.waveBeamSpeed * 1.8 * this.waves[i].expanding //expand / move + if (this.waves[i].radius > end - 30) { + this.waves[i].expanding = -1 + if (this.waves[i].reflection < 1) this.waves.splice(i, 1) //end + } else if (this.waves[i].radius < 25) { + this.waves[i].expanding = 1 + if (this.waves[i].reflection < 1) this.waves.splice(i, 1) //end + } + } + ctx.stroke(); + } + } + me.lasers = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[j], + v2: vertices[j + 1] + }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[0], + v2: vertices[len] + }; + } + } + }; + + const seeRange = 7000; + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { + x: where.x + seeRange * Math.cos(angle), + y: where.y + seeRange * Math.sin(angle) + }; + // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + vertexCollision(where, look, body); + if (!m.isCloak) vertexCollision(where, look, [player]); + if (best.who && (best.who === player) && m.immuneCycle < m.cycle) { + const dmg = 0.0011 * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + //draw beam + if (best.dist2 === Infinity) best = look; + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.lineWidth = 10; + ctx.stroke(); + } + me.pulse = function (charge, angle, where = this.position) { + let best; + angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x) + let explosionRadius = 5.5 * charge + let range = 5000 + const path = [{ + x: where.x + 20 * Math.cos(angle), + y: where.y + 20 * Math.sin(angle) + }, + { + x: where.x + range * Math.cos(angle), + y: where.y + range * Math.sin(angle) + } + ]; + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[j], + v2: vertices[j + 1] + }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[0], + v2: vertices[len] + }; + } + } + }; + //check for collisions + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + if (!best.who) { + vertexCollision(path[0], path[1], body); + vertexCollision(path[0], path[1], [player]); + vertexCollision(path[0], path[1], map); + if (best.dist2 != Infinity) { //if hitting something + path[path.length - 1] = { + x: best.x, + y: best.y + }; + } + } + if (best.who) { + b.explosion(path[1], explosionRadius, "rgba(0,0,0,0)") + const off = explosionRadius * 1.2 + b.explosion({ x: path[1].x + off * (Math.random() - 0.5), y: path[1].y + off * (Math.random() - 0.5) }, explosionRadius, "rgba(0,0,0,0.7)") + b.explosion({ x: path[1].x + off * (Math.random() - 0.5), y: path[1].y + off * (Math.random() - 0.5) }, explosionRadius, "rgba(0,0,0,0.7)") + } + //draw laser beam + ctx.beginPath(); + ctx.moveTo(path[0].x, path[0].y); + ctx.lineTo(path[1].x, path[1].y); + if (charge > 50) { + ctx.strokeStyle = "rgba(0,0,0,0.10)" + ctx.lineWidth = 70 + ctx.stroke(); + } + ctx.strokeStyle = "rgba(0,0,0,0.25)" + ctx.lineWidth = 20 + ctx.stroke(); + ctx.strokeStyle = "#f00"; + ctx.lineWidth = 4 + ctx.stroke(); + + //draw little dots along the laser path + const sub = Vector.sub(path[1], path[0]) + const mag = Vector.magnitude(sub) + for (let i = 0, len = Math.floor(mag * 0.0005 * charge); i < len; i++) { + const dist = Math.random() + simulation.drawList.push({ + x: path[0].x + sub.x * dist + 10 * (Math.random() - 0.5), + y: path[0].y + sub.y * dist + 10 * (Math.random() - 0.5), + radius: 1.5 + 5 * Math.random(), + color: "rgba(0,0,0,0.5)", + time: Math.floor(9 + 25 * Math.random() * Math.random()) + }); + } + } + let c = 0 + me.gun = function () { + if (b.activeGun == 0) {// nailgun + if (this.seePlayer.recall && !(simulation.cycle % 20)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + const dist = Vector.magnitudeSquared(Vector.sub(this.position, player.position)); + const unit = Vector.normalise(Vector.sub(Vector.add(player.position, Vector.mult(player.velocity, Math.sqrt(dist) / 60)), this.position)) + normalBullet(this.position.x, this.position.y); + const v = 10 + 8 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], Vector.mult(unit, 0.009 * this.mass)) + // Matter.Body.setVelocity(mob[mob.length - 1], { + // x: this.velocity.x + this.fireDir.x * v, + // y: this.velocity.y + this.fireDir.y * v + // }); + } + } + if (b.activeGun == 1) {// shotgun + if (this.seePlayer.recall && !(simulation.cycle % 90)) { + const side = 22 + for (let i = 0; i < 12; i++) { + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + const dir = angle + (Math.random() - 0.5) * 1 + const SPEED = 52 + Math.random() * 8 + normalBullet(this.position.x + 35 * Math.cos(angle) + 15 * (Math.random() - 0.5), this.position.y + 35 * Math.sin(angle) + 15 * (Math.random() - 0.5)) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: SPEED * Math.cos(dir), + y: SPEED * Math.sin(dir) + }); + } + } + } else if (b.activeGun == 2) { // super balls + if (this.seePlayer.recall && !(simulation.cycle % 20)) { + const num = 3; + const SPREAD = 0.13; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + let dir = angle - SPREAD * (num - 1) / 2; + const SPEED = 33 + for (let i = 0; i < num; i++) { + ball(this.position.x + 30 * Math.cos(angle), this.position.y + 30 * Math.sin(angle)) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: SPEED * Math.cos(dir), + y: SPEED * Math.sin(dir) + }); + dir += SPREAD + } + } + } else if (b.activeGun == 3) { // wave + this.doLongitudinal() + const halfArc = 0.275 + const anglex = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + const angle = anglex + 0.3 * (Math.random() - 0.5) + this.waves.push({ + position: { + x: this.position.x + 25 * Math.cos(anglex), + y: this.position.y + 25 * Math.sin(anglex), + }, + angle: angle - halfArc, //used in drawing ctx.arc + unit1: { x: Math.cos(angle - halfArc), y: Math.sin(angle - halfArc) }, //used for collision + unit2: { x: Math.cos(angle + halfArc), y: Math.sin(angle + halfArc) }, //used for collision + arc: halfArc * 2, + radius: 25, + reflection: 0, + expanding: 1, + resonanceCount: 0 + }) + } else if (b.activeGun == 4) { // missiles + if (this.seePlayer.recall && !(simulation.cycle % 30)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + missile(this.position); + const v = 10 + 8 * simulation.accelScale + (Math.random() * 20 - Math.random() * 20); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } else if (b.activeGun == 5) { // grenades + if (this.seePlayer.recall && !(simulation.cycle % 30)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + grenade(this.position.x, this.position.y) + const v = 10 + 8 * simulation.accelScale + (Math.random() * 20 - Math.random() * 20); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } else if (b.activeGun == 6) { // spores + if (this.seePlayer.recall && !(simulation.cycle % 30)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + me.drop(this.position.x, this.position.y) + const v = 10 + 8 * simulation.accelScale + (Math.random() * 20 - Math.random() * 20); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } else if (b.activeGun == 7) { // drones + ctx.save() + ctx.lineWidth = "8"; + ctx.strokeStyle = "rgba(100, 0, 150, 0.1)"; + ctx.beginPath(); + for (let i = 0, len = bullet.length; i < len; ++i) { + const dx = bullet[i].position.x - this.position.x; + const dy = bullet[i].position.y - this.position.y; + const dist = Math.sqrt(dx * dx + dy * dy); + if (dist < 500) { + ctx.moveTo(this.position.x + dist, this.position.y); + ctx.arc(this.position.x, this.position.y, dist, 0, 2 * Math.PI) + //ctx.lineTo(bullet[i].position.x, bullet[i].position.y); + const angle = Math.atan2(dy, dx); + const mag = (1500 * bullet[i].mass * simulation.g) / (dist * 0.05); + bullet[i].force.x += mag * Math.cos(angle); + bullet[i].force.y += mag * Math.sin(angle); + } + } + ctx.stroke(); + ctx.restore() + } else if (b.activeGun == 8) { // foam + if (this.seePlayer.recall && !(simulation.cycle % 1)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + foamBullet(this.position.x, this.position.y, 7 + Math.ceil(this.radius / 15), 69); + const v = 10 + 8 * simulation.accelScale + (Math.random() * 20 - Math.random() * 20); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } else if (b.activeGun == 9) { // harpoon - railgun + if (c > 1) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + railBullet(this.position.x, this.position.y); + const v = 10 + 80 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + c = 0; + } else { + c += 0.02; + this.railGun(); + } + } else if (b.activeGun == 10) { // laserMines + if (this.seePlayer.recall && !(simulation.cycle % 100)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + me.laserMine(this.position.x, this.position.y) + const v = 10 + 8 * simulation.accelScale + (Math.random() * 20 - Math.random() * 20); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v, + y: this.velocity.y + this.fireDir.y * v + }); + } + } else if (b.activeGun == 11) { // laser - pulse + //this.lasers(this.position, Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x)) + //if (this.seePlayer.recall && !(simulation.cycle % 20)) { + if (c > 1) { + this.pulse(c * 100) + c = 0; + } else { + if (this.energy < 1 || this.energy > 0.5) { + c += 0.01; + ctx.beginPath(); + const mag = Math.sqrt(c) + ctx.arc(this.position.x, this.position.y, c * 30, 0, 2 * Math.PI) + ctx.fillStyle = '#000000' + ctx.strokeStyle = 'transparent' + ctx.fill(); + ctx.stroke(); + this.energy -= 0.01; + ctx.strokeStyle = "#000000"; + ctx.lineWidth = 1.5 + // ctx.globalAlpha = 1; + } else { + c = 0; + this.energy += 0.1 + } + } + //} + } + } + me.laserMine = function (x, y) { + mobs.spawn(x, y, 3, 20, "#000000"); + let xx = mob[mob.length - 1]; + xx.stroke = "#00000000"; + Matter.Body.setDensity(xx, 0.000005) //one tap + xx.isUnstable = true; + xx.timeLeft = 40 + Math.floor(180 * Math.random()) + xx.leaveBody = false; + xx.isDropPowerUp = false; + xx.collisionFilter.mask = cat.bullet | cat.player | cat.map + xx.showHealthBar = false; + //xx.vertices = Matter.Vertices.rotate(xx.vertices, Math.PI, xx.position); + me.onHit = function () { + this.death(); + }; + xx.do = function () { + this.timeLimit(); + Matter.Body.setAngularVelocity(this, 0.01) + ctx.beginPath(); + ctx.lineWidth = 1; + ctx.strokeStyle = "#00000000" + for (let i = 0; i < this.vertices.length; i++) { + const where = this.vertices[i] + const endPoint = Vector.add(where, Vector.mult(Vector.normalise(Vector.sub(where, this.position)), 2500)) + me.lasers(this.vertices[0], this.angle + Math.PI / 3); + me.lasers(this.vertices[1], this.angle + Math.PI); + me.lasers(this.vertices[2], this.angle - Math.PI / 3); + } + ctx.strokeStyle = "black"; + ctx.stroke(); + ctx.save() + ctx.beginPath(); + ctx.moveTo(this.vertices[0].x, this.vertices[0].y); + ctx.lineTo(this.vertices[1].x, this.vertices[1].y); + ctx.lineTo(this.vertices[2].x, this.vertices[2].y); + ctx.fillStyle = "#000000"; + ctx.strokeStyle = "transparent"; + ctx.fill(); + ctx.closePath(); + ctx.stroke(); + ctx.restore() + } + } + me.seeker = function (x, y) { + mobs.spawn(x, y, sides = 5, radius = 5, "rgb(0,0,0)"); + let yy = mob[mob.length - 1]; + yy.stroke = "transparent"; + yy.onHit = function () { + this.explode(this.mass * 20); + }; + Matter.Body.setDensity(yy, 0.000015); //normal is 0.001 + yy.timeLeft = 420 //* (0.8 + 0.4 * Math.random()); + yy.accelMag = 0.00017 * simulation.accelScale; //* (0.8 + 0.4 * Math.random()) + yy.frictionAir = 0.01 //* (0.8 + 0.4 * Math.random()); + yy.restitution = 0.5; + yy.leaveBody = false; + yy.isDropPowerUp = false; + yy.isBadTarget = true; + yy.isMobBullet = true; + yy.showHealthBar = false; + yy.collisionFilter.category = cat.mobBullet; + yy.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet; + let index = 0; + yy.do = function () { + this.alwaysSeePlayer() + this.timeLimit(); + this.attraction(); + }; + } + me.drop = function (x, y) { + mobs.spawn(x, y, sides = 90, radius = 30, "rgb(0,255,100,0.7)"); + let yyy = mob[mob.length - 1]; + yyy.stroke = "transparent"; + yyy.onDeath = function () { + for (let i = 0, len = 5; i < len; i++) { + me.seeker(this.position.x, this.position.y) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: Math.random() * 30 - Math.random() * 30, + y: Math.random() * 30 - Math.random() * 30 + }); + } + }; + Matter.Body.setDensity(yyy, 0.000015); //normal is 0.001 + yyy.timeLeft = 60 //* (0.8 + 0.4 * Math.random()); + yyy.frictionAir = 0.01 //* (0.8 + 0.4 * Math.random()); + yyy.restitution = 0.5; + yyy.leaveBody = false; + yyy.isDropPowerUp = false; + yyy.isBadTarget = true; + yyy.isMobBullet = true; + yyy.showHealthBar = false; + yyy.collisionFilter.category = cat.mobBullet; + yyy.collisionFilter.mask = null; + yyy.maxRadius = 30; + let index = 0; + yyy.do = function () { + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + Matter.Body.setPosition(this, player.position) + if (player.speed > 2.5) Matter.Body.setVelocity(player, Vector.mult(player.velocity, 0.94)) + } + if (Matter.Query.collides(this, map).length > 0) { + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.1)) + } + this.alwaysSeePlayer() + this.timeLimit(); + ctx.save() + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y) + ctx.fillStyle = "black"; + ctx.arc(this.position.x, this.position.y, this.maxRadius, 0, 2 * Math.PI) + ctx.stroke() + ctx.fill() + ctx.restore() + if (this.maxRadius > 0) { + this.maxRadius -= 0.5; + } + }; + } + }; + restoreBoss(-13350, -1800); + laserEM(-6500 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -3400 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + sniper(-9275 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -3325 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + laserEM(-5750 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -850 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + sniper(-3600 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -1325 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + laserEM(1425 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200), -800 + Math.floor(Math.random() * 200) - Math.floor(Math.random() * 200)); + //restoreBoss(-350, -3225); + wire(); + wire(); + wire(); + wire(); + wire(); + color.map = '#00000000'; + level.customTopLayer = () => { + if (dong.position.x > -3825) { + dong.force.y -= dong.mass * simulation.g; + } else { + dong.force.y += dong.mass * simulation.g; + } + Matter.Body.setAngularVelocity(dong, -0.5) + if (key == true) { + door.isClosing = false; + } else { + door.isClosing = true; + } + door.openClose(); + door.draw() + for (let i = 0, len = map.length; i < len; i++) { //so boss bar renders over the map + ctx.beginPath(); + ctx.moveTo(map[i].vertices[0].x, map[i].vertices[0].y); + for (let j = 0, length = map[i].vertices.length; j < length; j++) { + ctx.lineTo(map[i].vertices[j].x, map[i].vertices[j].y); + } + ctx.lineTo(map[i].vertices[0].x, map[i].vertices[0].y); + ctx.fillStyle = "rgba(68,68,68)"; + ctx.strokeStyle = "transparent"; + ctx.fill(); + ctx.stroke(); + // ctx.setLineDash([]); + } + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].restoreBoss) { + ctx.save(); + ctx.setTransform(1, 0, 0.5, 1, 0, 0); //slanted + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(canvas.width2 / 2, canvas.height2 / 10, canvas.width2, 30); + ctx.fillStyle = "rgba(0,0,0,0.7)"; + ctx.fillRect(canvas.width2 / 2, canvas.height2 / 10, canvas.width2 * mob[i].health, 30); + ctx.restore(); + } + } + }; + const obj = { restoreBoss }; + Object.assign(spawn, obj); //for next map, gonna be a rpg-like thingy I think + }, + map() { + + const elevator = level.elevator(-80.4, -931.6, 180, 50, -1550) + 15900 && player.position.x < 16300 && player.position.y > -960.2 + const slime = level.hazard(15900, -960, 400, 6000); + const slime2 = level.hazard(15147.2, -1782.4, 2000, 822); + const boost1 = level.boost(5950, -20, 700) + const boost2 = level.boost(21088, -1672, 700) + const boost3 = level.boost(19390, -31, 1700) + const boost4 = level.boost(19390, -31, 1700) + const boost5 = level.boost(17274, -1242, 1000) + const portal = level.portal({ x: 443, y: -1636 }, Math.PI, { x: 21391.9, y: -1806.3 }, -Math.PI) + const portal2 = level.portal({ x: 16838.3, y: -626.7 }, Math.PI, { x: 16882.8, y: -2566.5 }, -Math.PI) + const buttonDoor = level.button(21889, -10) + const door = level.door(19119, -2133, 110, 510, 480) + const buttonDoor2 = level.button(18711, -2210) + const door2 = level.door(17041, -412, 110, 510, 480) + const buttonDoor3 = level.button(20456.6, -1636.2) + const door3 = level.door(20238, -781.4, 88, 452, 412) + //y=-1485 + + // simulation.enableConstructMode() + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 15316; + level.exit.y = -84; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#001738"; + color.map = "#444" //custom map color + + + + level.custom = () => { + //spawn.mapRect(22330, -2688.75, 400, 800); + //spawn.mapRect(22330, -1793.5, 400, 800);//-46.25*2=-92.5 + //spawn.mapRect(22330, -804.25, 400, 800);//-46.25*3 + + ctx.fillStyle = "rgba(63,247,251,0.8)" + ctx.fillRect(22330, -2713.75, 550, 700) //15845.0, -1262.2 + ctx.fillRect(22330, -1743.5, 550, 700) + ctx.fillRect(22330, -754.25, 550, 700) + ctx.fillRect(15845.0, -1262.2, 550, 300) + ctx.fillStyle = "rgba(235,235,235,0.9)" + ctx.fillRect(-192, -1973, 6484, 2071) + ctx.fillRect(15109.5, -2867.5, 7284, 2971) + ctx.fillStyle = "rgba(35,35,35,0.8)" + ctx.fillRect(15145.9, -960, 200, 25) + + ctx.fillStyle = "rgba(255,255,255,0.9)" + ctx.fillRect(-677.3, -610.9, 15, 15) + ctx.fillRect(-910.4, 458.3, 15, 15) + ctx.fillRect(-1029.0, 713.7, 15, 15) + ctx.fillRect(42.6, 1332.2, 15, 15) + ctx.fillRect(277.3, 751.8, 15, 15) + ctx.fillRect(797.1, 553.2, 15, 15) + ctx.fillRect(-1458.9, 340.9, 15, 15) + ctx.fillRect(-1780.0, -54.6, 15, 15) + ctx.fillRect(-1260.3, -686.4, 15, 15) + ctx.fillRect(-2064.3, -394.6, 15, 15) + ctx.fillRect(-1815.7, 1156.2, 15, 15) + ctx.fillRect(-1998.1, 1118.4, 15, 15) + + + + buttonDoor.query(); + buttonDoor.draw(); + buttonDoor2.query(); + buttonDoor2.draw(); + buttonDoor3.query(); + buttonDoor3.draw(); + slime.query(); + slime2.query(); + + ctx.fillStyle = `hsla(160, 100%, 43%,${0.3 + 0.07 * Math.random()})` + ctx.fillRect(15900 + 400 * Math.random(), -1360, 2, 6000) + if (buttonDoor.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + if (buttonDoor2.isUp) { + door2.isClosing = true + } else { + door2.isClosing = false + } + if (buttonDoor3.isUp) { + door3.isClosing = true + } else { + door3.isClosing = false + } + door.openClose(); + door2.openClose(); + door3.openClose(); + portal[2].query() + portal[3].query() + portal2[2].query() + portal2[3].query() + + boost1.query(); + boost2.query(); + boost3.query(); + boost4.query(); + boost5.query(); + level.exit.drawAndCheck(); + level.enter.draw(); + }; + + + level.customTopLayer = () => { + door.draw(); + door2.draw(); + door3.draw(); + + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + portal2[0].draw(); + portal2[1].draw(); + portal2[2].draw(); + portal2[3].draw(); + elevator.move() + + if (player.position.x > 15900 && player.position.x < 16300 && player.position.y > -1360.2) { + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y + 10 + }); + } else { + + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: player.velocity.y - 0.2 + }); + + } + + }; + + + //1273.2, -1404.7 + + //first ship base + spawn.mapRect(-300, 0, 6684, 100); //lower floor + spawn.mapRect(-300, -2071, 154, 2071); //far right wall + spawn.mapRect(2511, -300, 1309, 308); //left big block + spawn.mapRect(3820, -184, 1309, 184); //right big block + spawn.mapRect(-300, -739, 2549, 100); //upper right floor + spawn.mapRect(2056, -1309, 2764, 169); //upper center floor + spawn.mapRect(2056, -1309, 193, 650); //upper left floor wall + spawn.mapRect(4636, -1309, 193, 793); //upper right floor wall + spawn.mapRect(4821, -654, 955, 138); //upper right floor + spawn.mapRect(6237, -2071, 147, 2071); //far right wall + spawn.mapRect(-300, -2071, 6684, 154); //roof + + //first ship details + spawn.mapRect(245, -360, 70, 400); //start room wall + spawn.mapRect(500, -1929, 154, 462); + spawn.mapRect(185, -1517, 469, 77); + spawn.mapRect(2773, -682, 469, 77); //walls in 1st room + spawn.mapRect(3743, -566, 77, 469); + spawn.mapRect(3947, -851, 469, 77); + spawn.mapRect(5313, -1309, 1000, 70); //walls in second area + spawn.mapRect(4818, -1006, 400, 70); + spawn.mapRect(4768, -1626, 800, 70); + spawn.mapRect(4760, -1626, 70, 400); + + + //first ship blocks/debris + spawn.debris(3267.6, -797.1, 700, 5); //16 debris per level + spawn.debris(1626.0, -372.5, 1700, 8); //16 debris per level + spawn.debris(1880.1, -1508.9, 3700, 16); //16 debris per level + spawn.debris(5335.3, -1431.6, 3700, 16); //16 debris per level + spawn.debris(1563.8, -1087.9, 700, 5); //16 debris per level + spawn.bodyRect(1540, -1110, 218, 125, 0.9); + + + + //first ship mobs + spawn.randomMob(2903.9, -754.5, 0.7); + spawn.randomMob(5577.0, -217.0, 0.6); + spawn.randomMob(765.8, -1029.7, 0.5); + spawn.randomMob(20079.4, -2219.7, 0.6); + spawn.randomMob(20079.4, -2219.7, 0.7); + spawn.randomMob(20890.9, -1306.0, 0.5); + spawn.randomMob(21284.2, -983.1, 0.5); + spawn.randomMob(20381.0, -254.2, 0.7); + spawn.randomMob(21027.8, -473.8, 0.6); + spawn.randomMob(19448.2, -1323.3, 0.6); + spawn.randomMob(18397.7, -711.2, 0.6); + spawn.randomMob(15547.2, -2249.6, 0.6); + spawn.randomSmallMob(16114.6, -2524.2); + spawn.randomSmallMob(15378.9, -2549.6); + + spawn.randomSmallMob(893.5, -120.8); + spawn.randomSmallMob(3521.8, -419.6); + spawn.randomSmallMob(4386.2, -439.6); + spawn.randomSmallMob(5667.0, -847.8); + spawn.randomSmallMob(3158.5, -1581.8); + spawn.randomSmallMob(3866.7, -1483.2); + spawn.randomSmallMob(4652.3, -1729.4); + spawn.randomSmallMob(1068.7, -106.1); + spawn.randomSmallMob(3545.0, -413.0); + spawn.randomSmallMob(4231.7, -446.3); + spawn.randomSmallMob(1456.4, -1014.8); + spawn.randomSmallMob(20432.4, -1374.3); + spawn.randomSmallMob(20381.0, -254.2); + spawn.randomSmallMob(20353.4, -1845.8); + spawn.randomSmallMob(20353.4, -1845.8); + spawn.randomSmallMob(20648.1, -136.8); + spawn.randomSmallMob(20024.4, -2213.1); + spawn.randomSmallMob(17438.7, -876.7); + + + + //second ship mobs + spawn.debris(17732.3, -550.0, 700, 5); //16 debris per level + spawn.debris(18006.4, -2181.3, 700, 5); //16 debris per level + spawn.debris(16108.6, -2621.1, 700, 5); //16 debris per level + spawn.debris(20823.6, -1332.1, 1300, 5); //16 debris per level + spawn.debris(21095.5, -423.4, 700, 5); //16 debris per level + + + + + + + + spawn.randomSmallMob(1300, -70); + + + // const index = mob.length + spawn.shieldingBoss(769.8, -1119.0) + // console.log(mob[index].onDeath) + // requestAnimationFrame(() => mob[index].onDeath = function() {}); + // console.log(mob[index].onDeath) + + //second ship base + spawn.mapRect(15000, 0, 515, 185); //lower floor 1 + spawn.mapRect(17015, 0, 5500, 185); //lower floor 2 + spawn.mapRect(15000, -2972, 185, 2972); //left wall + spawn.mapRect(15000, -2972, 7515, 185); //roof + spawn.mapRect(22330, -2972, 185, 2972); //right wall + spawn.mapRect(17002, -2972, 169, 2564); //left middle wall + spawn.mapRect(19089, -2972, 169, 855); //right middle wall upper + spawn.mapRect(19089, -1625, 169, 1800); //right middle wall lower + spawn.mapRect(20760, -2972, 169, 1350); //medium wall left of portal + spawn.mapRect(19720, -1625, 1725, 162); //right room upper floor + spawn.mapRect(21440, -2325, 169, 863); //medium wall right of portal + spawn.mapRect(19720, -855, 2725, 162); //right room lower floor + + //engines //y -2972 -> 0 + spawn.mapRect(22330, -2763.75, 400, 800); + spawn.mapRect(22330, -1793.5, 400, 800); + spawn.mapRect(22330, -804.25, 400, 800); + + + + //second ship details + spawn.mapRect(19904, -1465, 85, 362); //upper L + spawn.mapRect(19542, -1191, 412, 88); //lower L + spawn.mapRect(18546, -2199, 600, 82); //2nd room enternce wall + spawn.mapRect(18546, -2499, 82, 2300); + spawn.mapRect(18108, -326, 500, 82); //walls/floors in middle room + spawn.mapRect(17750, -682, 300, 82); + spawn.mapRect(17156, -468, 500, 60); + spawn.mapRect(18022, -1082, 600, 82); + spawn.mapRect(17151, -1196, 500, 82); + spawn.mapRect(17453, -2060, 500, 82); + spawn.mapRect(18197, -2269, 400, 82); + spawn.mapRect(18108, -326, 500, 82); + spawn.mapRect(20542, -1191, 612, 88); + spawn.mapRect(20238, -1191, 88, 412); + spawn.mapRect(21520, -1468, 88, 412); + spawn.mapRect(20238, -330.2, 88, 412); + spawn.mapRect(20819, -328.3, 412, 88); + spawn.mapRect(21532, -708, 88, 412); + spawn.mapRect(15483.8, 12.5, 388, 30); //broken floor + spawn.mapRect(15487.6, 76.6, 488, 24); + spawn.mapRect(15506.5, 134.2, 288, 45); + spawn.mapVertex(16758.6, 135.3, "400 -30 -350 -40 -400 30 400 30"); + spawn.mapVertex(16758.6, 55.3, "423 -30 -408 -20 -400 20 400 20"); + //tank + spawn.mapRect(15310, -960, 600, 135); + spawn.mapRect(16290, -960, 800, 135); + //in tank + spawn.mapRect(16524.8, -2726.8, 40, 400); + spawn.mapRect(16524.8, -2130.9, 400, 40); + spawn.mapRect(16010.2, -2412.2, 300, 40); + spawn.mapRect(15379.2, -2055.1, 400, 40); + + + + //add fuel tanks in the last room + + + spawn.mapRect(21531.9, -707.8, 488, 8); + + //22185.5, -114.8 + spawn.mapVertex(22207.8, -103, "325 -200 100 -200 325 -300"); + spawn.mapRect(22056.6, -70, 225, 212); + + spawn.mapVertex(20723.1, -1734, "325 -200 100 -200 325 -300"); + spawn.mapRect(20571.9, -1701.0, 225, 212); + + spawn.mapVertex(22207.8, -103, "325 -200 100 -200 325 -300"); + spawn.mapRect(22056.6, -70, 225, 212); + //spawn.mapVertex(x,y, "coordinates") + //the parts in quotes is "x y x y x y x y x y" x and y need to be the coordinates of points that define the shape in a concave clockwise direction + + //second ship blocks/debris + spawn.bodyRect(21525, -113, 50, 50, 9); //first button block + spawn.bodyRect(18993, -2283, 50, 50, 9); //second button block + spawn.bodyRect(20303, -1736, 50, 50, 9); //third button block + + + + let randomBoss = Math.floor(Math.random() * 5); //change the bosses + spawn[["blinkBoss", "shooterBoss", "launcherBoss", "pulsarBoss", "beetleBoss", "bladeBoss", "revolutionBoss", "dragonFlyBoss", "spiderBoss"][randomBoss]](17902, -1689, 100, false); + + + + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + // spawn.bodyRect(1540, -1110, 300, 25, 0.9); + // spawn.randomSmallMob(1300, -70); + // spawn.randomMob(2650, -975, 0.8); + // spawn.randomGroup(1700, -900, 0.4); + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + // spawn.secondaryBossChance(100, -1500) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + cantilever() { // made by Eclipse#7932 on discord, (TheSpudguy)(@PurpleSunsetGames on github) + // simulation.enableConstructMode(); + simulation.inGameConsole(`underpass by Eclipse#7932`); + + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 5500; + level.exit.y = 950; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + spawn.mapRect(level.exit.x - 50, level.exit.y + 30, 200, 100); // exit platform + spawn.mapRect(level.exit.x - 50, level.exit.y - 300, 200, 100); // exit platform roof + const endElevator = level.elevator(level.exit.x - 150, level.exit.y - 300, 100, 425, level.exit.y - 300); // end access door + + spawn.randomMob(-200, 350, Infinity); // random mob at the beginning + + spawn.mapRect(-100, 0, 600, 100); // main platform at start + spawn.bodyRect(0, 300, 50, 50); // little squares at start (one of these should be taken while crossing the cantilever to complete the level more easily) + spawn.bodyRect(100, 200, 50, 50); + spawn.bodyRect(50, 250, 50, 50); + spawn.mapRect(450, -20, 50, 20); // main platform ledge + spawn.mapRect(-200, 500, 2200, 100); // lower platform + spawn.mapRect(1850, 380, 100, 50); // cantilever block + spawn.bodyRect(80, -1300, 70, 1300, 1, { friction: .03, frictionAir: .001 }); // cantilever + + spawn.mapRect(3400, 500, 300, 100); // lever platform + spawn.mapRect(3650, 500, 100, 800); // pit + spawn.mapRect(3650, 1300, 2600, 100); + spawn.mapRect(6150, 600, 100, 800); + spawn.mapRect(5650, 600, 100, 650); + spawn.randomMob(4700, 550, Infinity); + spawn.randomMob(4700, 450, Infinity); + spawn.randomMob(4600, 550, Infinity); + + const toggle = level.toggle(3500, 500, false); // first lever + const button = level.button(5900, 1300); + const slidingWall = level.elevator(3750, -1200, 100, 1800, -1200); // first sliding wall + + level.defaultZoom = 1500; + simulation.zoomTransition(level.defaultZoom); + document.body.style.backgroundColor = "#d8badf"; + // color.map = "#444" //custom map color + + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + + level.customTopLayer = () => { + toggle.query(); + button.query(); + button.draw(); + + if (toggle.isOn) { + slidingWall.force.y -= 400; + } + if (!button.isUp) { + endElevator.force.y -= 100; + } + slidingWall.move(); + endElevator.move() + }; + powerUps.addResearchToLevel(); //needs to run after mobs are spawned + }, + tlinat() { // _Destined_ formerly Richard0820#2652 + simulation.inGameConsole(`tlinat by Richard0820`); + simulation.fallHeight = 1 / 0, level.setPosToSpawn(0, -1e3), level.exit.x = 5100, level.exit.y = 3770, spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20), spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20), level.defaultZoom = 3000, simulation.zoomTransition(level.defaultZoom), document.body.style.backgroundColor = "#d8dadf"; + let e = 0, + t = 0; + const boidsFlocking = function (mob, otherMobs) { + const cohesionFactor = 0.01; + const separationFactor = 0.0001; + const alignmentFactor = 0.04; + let averagePosition = { x: 0, y: 0 }; + let averageVelocity = { x: 0, y: 0 }; + let nearbyMobsCount = 0; + for (const otherMob of otherMobs) { + if (otherMob !== mob) { + const distanceSquared = Vector.magnitudeSquared(Vector.sub(mob.position, otherMob.position)); + const boidRangeSquared = 300 * 300; // Adjust boid range as needed + if (distanceSquared < boidRangeSquared) { + averagePosition = Vector.add(averagePosition, otherMob.position); + averageVelocity = Vector.add(averageVelocity, otherMob.velocity); + nearbyMobsCount++; + } + } + } + if (nearbyMobsCount > 0) { + averagePosition = Vector.div(averagePosition, nearbyMobsCount); + averageVelocity = Vector.div(averageVelocity, nearbyMobsCount); + const cohesionForce = Vector.mult(Vector.sub(averagePosition, mob.position), cohesionFactor); + mob.force = Vector.add(mob.force, cohesionForce); + const separationForce = Vector.mult(Vector.sub(mob.position, averagePosition), separationFactor); + mob.force = Vector.add(mob.force, separationForce); + const alignmentForce = Vector.mult(Vector.sub(averageVelocity, mob.velocity), alignmentFactor); + mob.force = Vector.add(mob.force, alignmentForce); + } + }; + function ghoster(x, y, radius = 50 + Math.ceil(Math.random() * 90)) { + mobs.spawn(x, y, 7, radius, "transparent"); + let me = mob[mob.length - 1]; + me.seeAtDistance2 = 300000; + me.accelMag = 0.00004 + 0.00015 * simulation.accelScale; + if (map.length) me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; //required for search + // Matter.Body.setDensity(me, 0.0015); //normal is 0.001 + me.damageReduction = 0.5 + me.stroke = "transparent"; //used for drawGhost + me.alpha = 1; //used in drawGhost + me.isNotCloaked = false; //used in drawGhost + me.isBadTarget = true; + // me.leaveBody = false; + me.collisionFilter.mask = cat.bullet //| cat.body + me.showHealthBar = false; + me.memory = 600; + me.do = function () { + boidsFlocking(me, mob);//Stack, increase power. + if (this.speed > 7) { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.8, + y: this.velocity.y * 0.8 + }); + } + this.seePlayerCheckByDistance(); + this.checkStatus(); + this.attraction(); + this.search(); + //draw + if (this.distanceToPlayer2() < this.seeAtDistance2) { + if (this.alpha < 1) this.alpha += 0.011 * simulation.CDScale; //near player go solid + } else { + if (this.alpha > 0) this.alpha -= 0.05; ///away from player, hide + } + if (this.alpha > 0) { + if (this.alpha > 0.7 && this.seePlayer.recall) { + this.healthBar(); + if (!this.isNotCloaked) { + this.isNotCloaked = true; + this.isBadTarget = false; + this.collisionFilter.mask = cat.player | cat.bullet + } + } + //draw body + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + // ctx.lineWidth = 1; + ctx.fillStyle = `rgba(255,255,255,${this.alpha * this.alpha})`; + ctx.fill(); + } else if (this.isNotCloaked) { + this.isNotCloaked = false; + this.isBadTarget = true; + this.collisionFilter.mask = cat.bullet; //can't touch player or walls + } + }; + } + function o(e, t, o) { + const l = { + J: [" #### ", " # ", " # ", " # ", " # # ", " # # ", " ## "], + I: [" # ", " # ", " # ", " # ", " # ", " # ", " # "], + N: [" # # ", " ## # ", " ## # ", " # ## ", " # ## ", " # # ", " # # "], + " ": [" ", " ", " ", " ", " ", " ", " "], + O: [" ## ", " # # ", " # # ", " # # ", " # # ", " # # ", " ## "], + U: [" # # ", " # # ", " # # ", " # # ", " # # ", " # # ", " ### "], + R: [" #### ", " # #", " #### ", " # # ", " # # ", " # #", " # #"], + D: [" ### ", " # ## ", " # # ", " # # ", " # # ", " # ## ", " ### "], + S: [" #### ", " # ", " # ", " ### ", " ## ", " # ", " ##### "], + C: [" ##### ", " # ", " # ", " # ", " # ", " # ", " ##### "], + V: [" # # ", " # # ", " # # ", " # # ", " # # ", " # # ", " # "], + E: [" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "], + ".": [" ", " ", " ", " ", " ", " ## ", " ## "], + "/": [" #", " # ", " # ", " # ", " # ", " # ", "# "], + G: [" ###### ", " # ", " # ", " # ### ", " # # ", " # # ", " ###### "], + Q: [" ###### ", " # # ", " # # ", " # # ", " # # # ", " # # ", " #### # ", " # "], + 8: [" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "], + g: [" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " ###### "], + Y: [" # # ", " # # ", " # # ", " # ", " # ", " # ", " # "], + 4: [" # ", " # # ", " # # ", " # # ", " ###### ", " # ", " # "], + W: [" # # ", " # # ", " # # ", " # # # ", " # # # # ", " ## ## ", " # # "], + e: [" ###### ", " # # ", " # # ", " ####### ", " # ", " # ", " ###### "], + c: [" ###### ", "# ", "# ", "# ", "# ", "# ", " ###### ", " "], + m: [" # ", " ### ### ", " # # # ", " # # # ", " # # # ", " # # # ", " # # # "] + }, + a = (e, t) => { + ctx.fillStyle = "black", ctx.fillRect(e, t, 50, 50) + }, + n = (e, t, o) => { + const n = l[e]; + if (n) + for (let e = 0; e < n.length; e++) { + const l = n[e]; + for (let n = 0; n < l.length; n++) { + if ("#" === l[n]) { + a(t + 20 * n, o + 20 * e) + } + } + } + }; + for (let l = 0; l < o.length; l++) { + n(o[l], e + 250 * l - Math.abs(1.5 * e), t) + } + } + simulation.inGameConsole(`
Look up
Walk right to tp to maze
Exit is at the bottom left`), Matter.Body.scale(player.parts[3], 2, 2), level.custom = () => { + if (level.exit.drawAndCheck(), level.enter.draw(), player.position.y > 1e5 && Matter.Body.setPosition(player, { + x: 5100, + y: -5925 + }), player.position.x > 2500 && 0 == e) { + Matter.Body.setPosition(player, { + x: 5100, + y: -5925 + }), e++; + for (let e = 0; e < map.length; e++) Math.random() < .75 && ghoster(map[e].position.x, map[e].position.y); + simulation.inGameConsole("Watch out for ghosters
Peace ✌️") + } + player.position.x > level.exit.x && player.position.x < level.exit.x + 100 && player.position.y > level.exit.y - 150 && player.position.y < level.exit.y - 0 && player.velocity.y < .15 && 0 == t && (t++, Matter.Body.scale(player.parts[3], .5, .5)) + }, level.customTopLayer = () => { + player.position.x > -1200 && player.position.x < 4500 && (o(2e3, -3e3, "JOIN OUR DISCORD SERVER"), o(1500, -2700, "DISCORD.GG/Q8gY4WeUcm")) + }, spawn.mapRect(-1e3, -950, 5950, 100), spawn.mapRect(-1325, -3450, 100, 2575), spawn.mapRect(-1325, -950, 350, 100), spawn.mapRect(4850, -3400, 100, 2550), spawn.mapRect(-1325, -3450, 6275, 100), + function (e, t, o, l, a) { + const n = o / a, + s = l / a, + i = e - o / 2, + p = t - l / 2, + r = []; + for (let e = 0; e < a; e++) { + r[e] = []; + for (let t = 0; t < a; t++) r[e][t] = 1 + } + const c = []; + (function e(t, o) { + r[t][o] = 0; + const l = [{ + dx: 0, + dy: -1 + }, { + dx: 1, + dy: 0 + }, { + dx: 0, + dy: 1 + }, { + dx: -1, + dy: 0 + }]; + l.sort((() => Math.random() - .5)); + for (const n of l) { + const l = t + 2 * n.dx, + s = o + 2 * n.dy; + l >= 0 && l < a && s >= 0 && s < a && 1 === r[l][s] && (r[t + n.dx][o + n.dy] = 0, r[l][s] = 0, c.push({ + x: t + n.dx, + y: o + n.dy + }), e(l, s)) + } + })(0, 0), r[a - 1][a - 1] = 1; + for (let e = -1; e < a + 1; e++) { + let t = -1, + o = -1; + for (let l = -1; l < a + 1; l++) + if (e >= 0 && e < a && l >= 0 && l < a && 1 === r[e][l]) - 1 === t && (t = l), o = l; + else if (-1 !== t) { + const l = i + e * n, + a = p + t * s, + r = n, + c = (o - t + 1) * s; + c !== s && spawn.mapRect(l, a, r, c), t = -1, o = -1 + } + } + for (let e = -1; e < a + 1; e++) { + let t = -1, + o = -1; + for (let l = -1; l < a + 1; l++) + if (l >= 0 && l < a && e >= 0 && e < a && 1 === r[l][e]) - 1 === t && (t = l), o = l; + else if (-1 !== t) { + const l = i + t * n, + a = p + e * s, + r = (o - t + 1) * n, + c = s; + r !== n && spawn.mapRect(l, a, r, c), t = -1, o = -1 + } + } + spawn.mapRect(i - n, p - s, n * a, s), spawn.mapRect(i - n, p - s, n, s * a), spawn.mapRect(i + (a - 1) * n, p - s, n, s * (a + 1)), spawn.mapRect(i - n, p + (a - 1) * s, n * (a + 1), s) + }(1e4, -1e3, 1e4, 1e4, 50); + }, + ruins() { // by SiddhUPe + // simulation.enableConstructMode() + simulation.inGameConsole(`ruins by SiddhUPe`); + + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 19531; + level.exit.y = 882 + 70; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + // color.map = "#444" //custom map color + + + level.customTopLayer = () => { }; + spawn.mapRect(875, 0, 1000, 100); + spawn.mapRect(1825, -400, 50, 225); + spawn.mapRect(1825, -400, 675, 50); + spawn.mapRect(1825, 0, 675, 100); + spawn.mapRect(2500, -575, 50, 225); + spawn.mapRect(2500, -575, 850, 50); + spawn.mapRect(2500, -100, 875, 175); + spawn.mapRect(2500, 75, 875, 25); + spawn.mapRect(3350, -575, 25, 50); + spawn.mapRect(2450, -50, 75, 75); + spawn.mapRect(2425, -25, 25, 25); + spawn.mapRect(2475, -75, 25, 25); + spawn.mapRect(3375, -575, 75, 325); + spawn.mapRect(3375, -100, 75, 300); + spawn.mapRect(3450, -50, 25, 250); + spawn.mapRect(3475, -25, 25, 225); + spawn.mapRect(3500, 0, 25, 200); + spawn.mapRect(3525, 25, 25, 175); + spawn.mapRect(3550, 75, 25, 125); + spawn.mapRect(3550, 50, 25, 150); + spawn.mapRect(3575, 75, 25, 125); + spawn.mapRect(3600, 100, 25, 100); + spawn.mapRect(3625, 150, 25, 50); + spawn.mapRect(2875, -1375, 350, 75); + spawn.mapRect(3150, -1375, 75, 350); + spawn.mapRect(3100, -1300, 50, 50); + spawn.mapRect(3075, -1300, 25, 25); + spawn.mapRect(3125, -1250, 25, 25); + spawn.mapRect(2825, -1375, 50, 125); + spawn.mapRect(3100, -1025, 125, 50); + spawn.mapRect(2800, -1350, 25, 75); + spawn.mapRect(3125, -975, 75, 25); + spawn.mapRect(3225, -1350, 25, 300); + spawn.mapRect(2875, -1400, 275, 25); + spawn.mapRect(2900, -1425, 225, 25); + spawn.mapRect(3250, -1325, 25, 250); + spawn.mapRect(2875, -1300, 25, 25); + spawn.mapRect(3125, -1050, 50, 25); + spawn.mapRect(5325, 800, 50, 225); + spawn.mapRect(5325, 975, 300, 50); + spawn.mapRect(5375, 925, 50, 50); + spawn.mapRect(5375, 900, 25, 25); + spawn.mapRect(5425, 950, 25, 25); + spawn.mapRect(5325, 775, 100, 25); + spawn.mapRect(5625, 925, 25, 100); + spawn.mapRect(5350, 800, 50, 25); + spawn.mapRect(5600, 950, 25, 50); + spawn.mapRect(5300, 800, 25, 175); + spawn.mapRect(5400, 1025, 225, 25); + spawn.mapRect(5450, 1050, 125, 25); + spawn.mapRect(5275, 850, 25, 100); + spawn.mapRect(5350, 750, 50, 25); + spawn.mapRect(5650, 950, 25, 50); + spawn.mapRect(16775, -975, 275, 50); + spawn.mapRect(17000, -975, 50, 200); + spawn.mapRect(16775, -975, 25, 100); + spawn.mapRect(17000, -775, 50, 50); + spawn.mapRect(16975, -725, 75, 25); + spawn.mapRect(16950, -925, 50, 50); + spawn.mapRect(16925, -925, 75, 25); + spawn.mapRect(17000, -925, 25, 75); + spawn.mapRect(16975, -925, 25, 50); + spawn.mapRect(16975, -925, 25, 75); + spawn.mapRect(16800, -1000, 200, 25); + spawn.mapRect(16850, -1025, 100, 25); + spawn.mapRect(17050, -925, 25, 200); + spawn.mapRect(17075, -925, 25, 150); + spawn.mapRect(16775, -925, 50, 25); + spawn.mapRect(17000, -750, 25, 25); + spawn.mapRect(16975, -750, 25, 50); + spawn.mapRect(16950, -725, 75, 25); + spawn.mapRect(9475, -1150, 50, 200); + spawn.mapRect(9475, -1150, 25, 25); + spawn.mapRect(9475, -1150, 300, 50); + spawn.mapRect(9725, -1150, 25, 25); + spawn.mapRect(9725, -1150, 50, 200); + spawn.mapRect(9500, -975, 25, 25); + spawn.mapRect(9500, -975, 75, 25); + spawn.mapRect(9700, -975, 25, 25); + spawn.mapRect(9675, -975, 75, 25); + spawn.mapRect(9525, -1175, 200, 25); + spawn.mapRect(9550, -1200, 150, 100); + spawn.mapRect(9450, -1125, 50, 150); + spawn.mapRect(9750, -1125, 50, 150); + spawn.mapRect(9525, -1100, 50, 50); + spawn.mapRect(9675, -1100, 50, 50); + spawn.mapRect(9575, -1100, 25, 25); + spawn.mapRect(9650, -1100, 25, 25); + spawn.mapRect(9500, -1050, 50, 25); + spawn.mapRect(9700, -1100, 25, 75); + spawn.mapRect(11925, -1175, 75, 275); + spawn.mapRect(11925, -1175, 475, 75); + spawn.mapRect(12325, -1175, 75, 275); + spawn.mapRect(11925, -925, 175, 25); + spawn.mapRect(12225, -925, 175, 25); + spawn.mapRect(11950, -925, 125, 50); + spawn.mapRect(12275, -925, 100, 50); + spawn.mapRect(11925, -1200, 475, 25); + spawn.mapRect(11975, -1225, 375, 25); + spawn.mapRect(12000, -1225, 50, 25); + spawn.mapRect(12000, -1275, 325, 75); + spawn.mapRect(11900, -1175, 50, 250); + spawn.mapRect(12375, -1175, 50, 250); + spawn.mapRect(11900, -1150, 50, 150); + spawn.mapRect(11875, -1150, 50, 200); + spawn.mapRect(12375, -1150, 75, 200); + spawn.mapRect(11975, -1100, 50, 25); + spawn.mapRect(12300, -1100, 75, 25); + spawn.mapRect(12300, -950, 25, 50); + spawn.mapRect(12000, -950, 25, 75); + + spawn.mapRect(3625, 125, 25, 50); + spawn.mapRect(3650, 150, 25, 50); + spawn.mapRect(3675, 175, 25, 25); + spawn.mapRect(3450, -75, 25, 50); + spawn.mapRect(3475, -50, 25, 125); + spawn.mapRect(3500, -25, 25, 125); + spawn.mapRect(3500, 0, 50, 125); + spawn.mapRect(3550, 25, 25, 125); + spawn.mapRect(3575, 50, 25, 125); + spawn.mapRect(3600, 75, 25, 75); + spawn.mapRect(3600, 100, 50, 75); + spawn.mapRect(3650, 125, 25, 75); + spawn.mapRect(3675, 150, 25, 50); + spawn.mapRect(3675, 150, 75, 450); + spawn.mapRect(3675, 525, 700, 75); + spawn.mapRect(4300, 150, 75, 450); + mover = level.mover(3375, -100, 75, 100); + pool = level.hazard(3750, 200, 550, 325); + spawn.mapRect(-150, -225, 75, 325); + spawn.mapRect(-150, -325, 425, 100); + spawn.mapRect(-100, -400, 300, 75); + spawn.mapRect(-25, -475, 150, 75); + spawn.mapRect(200, -350, 25, 50); + spawn.mapRect(-50, -425, 25, 100); + spawn.mapRect(-125, -350, 25, 100); + spawn.mapRect(100, -425, 50, 125); + spawn.mapRect(1875, -450, 625, 50); + spawn.mapRect(1950, -500, 550, 50); + spawn.mapRect(2025, -525, 475, 25); + spawn.mapRect(2025, -550, 525, 25); + spawn.mapRect(2125, -575, 400, 25); + spawn.mapRect(2125, -600, 1325, 50); + spawn.mapRect(2475, -550, 950, 200); + spawn.mapRect(1825, -350, 100, 175); + spawn.mapRect(3350, -375, 25, 125); + spawn.mapRect(1850, -425, 50, 25); + spawn.mapRect(1925, -475, 125, 25); + spawn.mapRect(2000, -525, 125, 25); + spawn.mapRect(2100, -575, 200, 25); + spawn.mapRect(2400, -650, 725, 75); + spawn.mapRect(2500, -675, 475, 75); + spawn.mapRect(2625, -725, 225, 100); + spawn.mapRect(2675, -750, 125, 25); + spawn.mapRect(2600, -700, 25, 50); + spawn.mapRect(2850, -700, 25, 75); + spawn.mapRect(3075, -625, 75, 50); + spawn.mapRect(2375, -625, 50, 75); + spawn.mapRect(1900, -350, 100, 75); + spawn.mapRect(1925, -300, 50, 50); + spawn.mapRect(1975, -350, 75, 50); + spawn.mapRect(3325, -350, 50, 25); + spawn.mapRect(150, -25, 1425, 50); + spawn.mapRect(175, 75, 1200, 50); + spawn.mapRect(400, -25, 575, 25); + spawn.mapRect(425, -50, 750, 75); + spawn.mapRect(1250, -50, 125, 100); + spawn.mapRect(1175, -50, 100, 25); + spawn.mapRect(725, 100, 500, 50); + spawn.mapRect(625, -75, 300, 50); + spawn.mapRect(250, -25, 225, 25); + spawn.mapRect(1400, 75, 225, 50); + spawn.mapRect(950, -75, 200, 25); + spawn.mapRect(1200, -75, 125, 25); + spawn.mapRect(425, -50, 100, 25); + spawn.mapRect(450, -75, 100, 50); + spawn.mapRect(250, -50, 125, 50); + spawn.mapRect(250, 125, 125, 25); + spawn.mapRect(475, 100, 100, 50); + spawn.mapRect(650, 125, 25, 25); + spawn.mapRect(675, 100, 75, 50); + spawn.mapRect(825, 125, 200, 50); + spawn.mapRect(-75, 75, 325, 50); + spawn.mapRect(0, 100, 175, 50); + spawn.mapRect(775, -100, 275, 50); + spawn.mapRect(2475, 0, 925, 125); + spawn.mapRect(2500, 50, 875, 100); + spawn.mapRect(2550, 100, 775, 75); + spawn.mapRect(2625, 150, 600, 50); + spawn.mapRect(3225, 125, 275, 75); + spawn.mapRect(1750, -225, 150, 50); + spawn.mapRect(1800, -275, 50, 75); + spawn.mapRect(1775, -250, 75, 75); + spawn.mapRect(3200, -625, 250, 50); + spawn.mapRect(3275, -650, 75, 25); + spawn.mapRect(3175, -625, 25, 25); + spawn.mapRect(3250, -700, 100, 100); + spawn.mapRect(3200, -650, 75, 50); + spawn.mapRect(3225, -675, 75, 100); + spawn.mapRect(3325, -675, 50, 100); + spawn.mapRect(3375, -650, 25, 75); + spawn.mapRect(1575, -25, 100, 25); + spawn.mapRect(1450, 100, 125, 50); + spawn.mapRect(250, -300, 50, 50); + spawn.mapRect(275, -275, 50, 25); + spawn.mapRect(200, -275, 125, 50); + spawn.mapRect(3725, 200, 50, 375); + spawn.mapRect(3750, 275, 50, 300); + spawn.mapRect(3800, 350, 25, 200); + spawn.mapRect(3825, 425, 25, 150); + spawn.mapRect(3850, 500, 25, 75); + spawn.mapRect(4275, 250, 50, 325); + spawn.mapRect(4250, 300, 50, 300); + spawn.mapRect(4225, 375, 75, 200); + spawn.mapRect(4200, 450, 75, 150); + spawn.mapRect(4175, 500, 75, 75); + spawn.mapRect(3950, 500, 150, 50); + spawn.mapRect(4000, 500, 50, 25); + spawn.mapRect(3875, 500, 425, 25); + spawn.mapRect(3625, 200, 50, 75); + spawn.mapRect(3575, 200, 50, 25); + spawn.mapRect(3675, 275, 25, 25); + spawn.mapRect(3650, 275, 25, 25); + spawn.mapRect(3600, 200, 25, 50); + spawn.mapRect(2600, 175, 25, 25); + spawn.mapRect(2700, 175, 425, 100); + spawn.mapRect(2650, 200, 75, 50); + spawn.mapRect(3100, 200, 75, 50); + spawn.mapRect(2675, 250, 25, 25); + spawn.mapRect(2625, 200, 100, 25); + spawn.mapRect(3150, 200, 75, 25); + spawn.mapRect(3175, 225, 25, 25); + spawn.mapRect(3775, 250, 25, 50); + spawn.mapRect(3800, 275, 25, 125); + spawn.mapRect(3800, 325, 50, 225); + spawn.mapRect(3875, 400, 25, 200); + spawn.mapRect(3825, 425, 50, 125); + spawn.mapRect(3850, 375, 25, 100); + spawn.mapRect(3900, 450, 25, 75); + spawn.mapRect(3925, 475, 25, 50); + spawn.mapRect(3450, -600, 25, 325); + spawn.mapRect(3475, -575, 25, 275); + spawn.mapRect(3500, -525, 25, 200); + spawn.mapRect(3525, -500, 25, 150); + spawn.mapRect(3550, -475, 25, 100); + spawn.mapRect(2725, 250, 350, 50); + spawn.mapRect(2750, 275, 300, 50); + spawn.mapRect(3150, 250, 25, 25); + spawn.mapRect(4325, 150, 975, 75); + spawn.mapRect(4375, 225, 900, 25); + spawn.mapRect(4375, 175, 875, 100); + spawn.mapRect(4375, 225, 850, 75); + spawn.mapRect(4375, 225, 825, 100); + spawn.mapRect(4375, 275, 800, 75); + spawn.mapRect(4350, 325, 800, 50); + spawn.mapRect(4375, 350, 750, 50); + spawn.mapRect(4375, 350, 725, 75); + spawn.mapRect(4350, 375, 725, 75); + spawn.mapRect(4350, 400, 700, 75); + spawn.mapRect(4350, 425, 675, 75); + spawn.mapRect(4350, 475, 650, 50); + spawn.mapRect(4375, 500, 600, 50); + spawn.mapRect(4375, 500, 575, 75); + spawn.mapRect(4375, 550, 550, 50); + spawn.mapRect(4425, 125, 775, 75); + spawn.mapRect(5300, 175, 75, 50); + spawn.mapRect(4475, 100, 150, 25); + spawn.mapRect(4825, 125, 300, 25); + spawn.mapRect(4800, 100, 250, 25); + spawn.mapRect(5100, 100, 50, 25); + spawn.mapRect(4650, 100, 75, 25); + spawn.mapRect(5475, 225, 125, 300); + spawn.mapRect(5450, 275, 25, 125); + spawn.mapRect(5450, 450, 25, 75); + spawn.mapRect(5425, 325, 25, 75); + spawn.mapRect(5425, 475, 25, 50); + spawn.mapRect(5575, 250, 50, 150); + spawn.mapRect(5575, 450, 50, 50); + spawn.mapRect(5475, 525, 125, 25); + spawn.mapRect(5500, 550, 75, 25); + spawn.mapRect(5525, 575, 25, 25); + spawn.mapRect(3675, 575, 1050, 50); + spawn.mapRect(4175, 600, 250, 50); + spawn.mapRect(3850, 625, 100, 25); + spawn.mapRect(3700, 625, 75, 25); + spawn.mapRect(4050, 625, 50, 25); + spawn.mapRect(4500, 625, 225, 25); + spawn.mapRect(5725, 150, 75, 225); + spawn.mapRect(5700, 175, 25, 150); + spawn.mapRect(5775, 250, 50, 100); + spawn.mapRect(5950, 325, 75, 75); + spawn.mapRect(5925, 375, 25, 25); + spawn.mapRect(6000, 350, 50, 50); + spawn.mapRect(6125, 425, 1050, 75); + spawn.mapRect(6425, 0, 750, 75); + spawn.mapRect(6400, 25, 50, 50); + spawn.mapRect(6500, -25, 675, 75); + spawn.mapRect(6550, -25, 275, 25); + spawn.mapRect(6475, -25, 125, 75); + spawn.mapRect(6450, -25, 100, 100); + spawn.mapRect(6475, -75, 700, 75); + spawn.mapRect(6500, -75, 75, 25); + spawn.mapRect(6500, -125, 675, 125); + spawn.mapRect(6525, -150, 650, 125); + spawn.mapRect(6550, -175, 625, 50); + spawn.mapRect(6900, -200, 275, 75); + spawn.mapRect(6925, -250, 250, 175); + spawn.mapRect(6950, -275, 225, 75); + spawn.mapRect(6975, -300, 200, 50); + spawn.mapRect(7025, -325, 125, 125); + spawn.mapRect(6400, 50, 75, 175); + spawn.mapRect(6450, 50, 100, 100); + spawn.mapRect(6475, 150, 25, 25); + spawn.mapRect(6550, 75, 25, 25); + spawn.mapRect(6375, 75, 25, 150); + spawn.mapRect(6350, 100, 25, 75); + spawn.mapRect(6650, 50, 225, 50); + spawn.mapRect(6975, 75, 75, 25); + spawn.mapRect(6625, -175, 225, 25); + spawn.mapRect(6675, -200, 275, 25); + spawn.mapRect(6750, -225, 250, 25); + spawn.mapRect(6200, 475, 575, 50); + spawn.mapRect(6925, 500, 125, 25); + spawn.mapRect(6325, 400, 475, 25); + spawn.mapRect(6950, 400, 200, 25); + spawn.mapRect(7100, 75, 75, 100); + spawn.mapRect(7075, 75, 25, 25); + spawn.mapRect(7175, -300, 1650, 350); + spawn.mapRect(7325, -700, 100, 450); + spawn.mapRect(7600, -700, 100, 450); + spawn.mapRect(7900, -700, 100, 450); + spawn.mapRect(8200, -700, 100, 425); + spawn.mapRect(8500, -700, 100, 425); + spawn.mapRect(7275, -825, 1375, 125); + spawn.mapRect(7400, -700, 50, 25); + spawn.mapRect(7575, -700, 50, 25); + spawn.mapRect(7875, -700, 150, 25); + spawn.mapRect(8175, -700, 150, 25); + spawn.mapRect(8475, -700, 150, 25); + spawn.mapRect(7300, -325, 150, 75); + spawn.mapRect(7575, -325, 150, 75); + spawn.mapRect(7875, -325, 150, 75); + spawn.mapRect(8175, -325, 150, 75); + spawn.mapRect(8475, -325, 150, 75); + spawn.mapRect(7700, -700, 25, 25); + spawn.mapRect(7300, -700, 75, 25); + spawn.mapRect(7150, 50, 75, 50); + spawn.mapRect(7175, 100, 25, 25); + spawn.mapRect(7225, 50, 25, 25); + spawn.mapRect(7300, -850, 1325, 75); + spawn.mapRect(7325, -875, 1275, 50); + spawn.mapRect(7375, -900, 1200, 25); + spawn.mapRect(7350, -900, 25, 25); + spawn.mapRect(7375, -900, 200, 25); + + spawn.mapRect(7375, -925, 1175, 25); + spawn.mapRect(7400, -950, 1125, 25); + spawn.mapRect(7425, -975, 1075, 25); + spawn.mapRect(7450, -1000, 1025, 25); + spawn.mapRect(7675, -1050, 525, 50); + spawn.mapRect(7700, -1050, 100, 25); + spawn.mapRect(7700, -1075, 450, 25); + spawn.mapRect(7725, -1100, 400, 25); + spawn.mapRect(7775, -1125, 300, 25); + spawn.mapRect(7650, -1025, 75, 25); + spawn.mapRect(8200, -1025, 25, 25); + spawn.mapRect(8825, -275, 25, 300); + spawn.mapRect(8825, -225, 50, 125); + spawn.mapRect(8850, -50, 25, 75); + spawn.mapRect(7150, 425, 100, 425); + spawn.mapRect(7150, 775, 1600, 100); + spawn.mapRect(8750, 400, 75, 475); + spawn.mapRect(8825, 400, 25, 475); + spawn.mapRect(7225, 450, 50, 325); + spawn.mapRect(7250, 500, 50, 275); + spawn.mapRect(7300, 550, 25, 225); + spawn.mapRect(7325, 600, 25, 175); + spawn.mapRect(7350, 650, 25, 125); + spawn.mapRect(7375, 675, 25, 100); + spawn.mapRect(7400, 700, 25, 75); + spawn.mapRect(7425, 725, 25, 50); + spawn.mapRect(7450, 750, 25, 25); + spawn.mapRect(8725, 425, 50, 375); + spawn.mapRect(8700, 450, 75, 375); + spawn.mapRect(8675, 475, 100, 375); + spawn.mapRect(8650, 500, 125, 375); + spawn.mapRect(8600, 525, 100, 350); + spawn.mapRect(8575, 550, 100, 275); + spawn.mapRect(8550, 575, 150, 250); + spawn.mapRect(8525, 625, 100, 225); + spawn.mapRect(8500, 675, 100, 125); + spawn.mapRect(8625, 825, 25, 25); + spawn.mapRect(8475, 700, 75, 75); + spawn.mapRect(8450, 725, 50, 50); + spawn.mapRect(8425, 750, 100, 25); + wastepool = level.hazard(7250, 575, 1450, 200); + spawn.mapRect(7375, 0, 250, 75); + spawn.mapRect(7700, 0, 725, 75); + spawn.mapRect(8575, 50, 150, 25); + spawn.mapRect(7750, 50, 475, 50); + spawn.mapRect(7425, 50, 175, 50); + spawn.mapRect(8600, 50, 50, 50); + spawn.mapRect(7200, 850, 875, 50); + spawn.mapRect(8225, 850, 125, 50); + spawn.mapRect(8475, 850, 275, 50); + spawn.mapRect(7300, 875, 375, 50); + spawn.mapRect(7925, 875, 100, 50); + spawn.mapRect(8525, 875, 125, 50); + spawn.mapRect(8250, 875, 75, 50); + spawn.mapRect(7800, 900, 50, 25); + spawn.mapRect(8125, 875, 50, 50); + spawn.mapRect(8075, 875, 50, 50); + spawn.mapRect(7125, 500, 25, 325); + spawn.mapRect(7100, 475, 25, 300); + spawn.mapRect(7075, 600, 50, 125); + spawn.mapRect(7075, 500, 50, 25); + spawn.mapRect(8850, 425, 75, 450); + spawn.mapRect(8925, 475, 75, 400); + spawn.mapRect(9000, 550, 75, 325); + spawn.mapRect(9075, 650, 75, 25); + spawn.mapRect(9075, 625, 75, 250); + spawn.mapRect(9150, 675, 75, 200); + spawn.mapRect(9225, 750, 75, 125); + spawn.mapRect(8925, 450, 25, 25); + spawn.mapRect(9000, 500, 25, 75); + spawn.mapRect(9000, 525, 25, 100); + spawn.mapRect(9000, 525, 50, 100); + spawn.mapRect(9050, 575, 50, 100); + spawn.mapRect(9075, 600, 50, 75); + spawn.mapRect(9150, 650, 25, 100); + spawn.mapRect(9225, 725, 50, 100); + spawn.mapRect(9225, 700, 25, 100); + spawn.mapRect(9300, 800, 1375, 75); + spawn.mapRect(9300, 775, 25, 50); + spawn.mapRect(9425, 775, 200, 25); + spawn.mapRect(9500, 875, 200, 25); + spawn.mapRect(9725, 825, 200, 75); + spawn.mapRect(10000, 850, 125, 50); + spawn.mapRect(10225, 850, 400, 50); + spawn.mapRect(9775, 775, 125, 25); + spawn.mapRect(10100, 775, 75, 75); + spawn.mapRect(10275, 750, 225, 75); + spawn.mapRect(9975, 775, 25, 50); + spawn.mapRect(10000, 775, 25, 50); + spawn.mapRect(10025, 775, 25, 75); + spawn.mapRect(10675, 775, 50, 100); + spawn.mapRect(10725, 725, 50, 150); + spawn.mapRect(10775, 650, 50, 225); + spawn.mapRect(10825, 575, 50, 300); + spawn.mapRect(10875, 500, 50, 375); + spawn.mapRect(10925, 425, 275, 450); + spawn.mapRect(11200, 500, 50, 375); + spawn.mapRect(11250, 575, 50, 300); + spawn.mapRect(11300, 650, 50, 225); + spawn.mapRect(11350, 725, 50, 150); + spawn.mapRect(11400, 775, 50, 100); + spawn.mapRect(10700, 750, 75, 75); + spawn.mapRect(10775, 700, 25, 25); + spawn.mapRect(10750, 700, 75, 75); + spawn.mapRect(10800, 625, 125, 75); + spawn.mapRect(10850, 550, 125, 50); + spawn.mapRect(10900, 475, 150, 75); + spawn.mapRect(11125, 475, 100, 50); + spawn.mapRect(11200, 550, 75, 50); + spawn.mapRect(11275, 625, 50, 75); + spawn.mapRect(11325, 700, 50, 75); + spawn.mapRect(11375, 750, 50, 75); + spawn.mapRect(11550, 225, 1525, 75); + spawn.mapRect(11450, 825, 1625, 50); + spawn.mapRect(11450, 800, 1625, 75); + spawn.mapRect(11525, -350, 50, 650); + spawn.mapRect(11850, -350, 50, 650); + spawn.mapRect(12225, -350, 50, 650); + spawn.mapRect(12600, -350, 50, 650); + spawn.mapRect(13000, -350, 75, 650); + spawn.mapRect(11525, -200, 1525, 50); + spawn.mapRect(11525, 50, 1550, 50); + spawn.mapRect(11525, -400, 1550, 50); + spawn.mapRect(11575, -425, 1450, 50); + spawn.mapRect(11625, -450, 1325, 75); + spawn.mapRect(11700, -475, 1175, 75); + spawn.mapRect(11725, -500, 1125, 75); + spawn.mapRect(11825, -400, 100, 75); + spawn.mapRect(11825, 200, 100, 75); + spawn.mapRect(12200, -375, 100, 50); + spawn.mapRect(12200, 200, 100, 75); + spawn.mapRect(12575, 200, 100, 75); + spawn.mapRect(12575, -375, 100, 50); + spawn.mapRect(11500, 825, 50, 25); + spawn.mapRect(11550, 775, 175, 25); + spawn.mapRect(11525, 875, 250, 25); + spawn.mapRect(11875, 750, 225, 50); + spawn.mapRect(11950, 850, 375, 50); + spawn.mapRect(12500, 775, 250, 75); + spawn.mapRect(12750, 850, 175, 50); + + + // books + spawn.bodyRect(11575, -300, 25, 100); + spawn.bodyRect(11600, -300, 25, 100); + spawn.bodyRect(11625, -300, 25, 100); + spawn.bodyRect(11650, -300, 25, 100); + spawn.bodyRect(11675, -300, 25, 100); + spawn.bodyRect(11700, -300, 25, 100); + spawn.bodyRect(11725, -300, 25, 100); + spawn.bodyRect(11750, -300, 25, 100); + spawn.bodyRect(11775, -300, 25, 100); + spawn.bodyRect(11800, -300, 25, 100); + spawn.bodyRect(11825, -300, 25, 100); + spawn.bodyRect(11900, -50, 25, 100); + spawn.bodyRect(11925, -50, 25, 100); + spawn.bodyRect(11950, -50, 25, 100); + spawn.bodyRect(11975, -50, 50, 100); + spawn.bodyRect(12025, -50, 50, 100); + spawn.bodyRect(12075, -50, 25, 100); + spawn.bodyRect(12100, -50, 50, 100); + spawn.bodyRect(12150, -50, 25, 100); + spawn.bodyRect(12175, -50, 25, 100); + spawn.bodyRect(12200, -50, 25, 100); + spawn.bodyRect(11900, -300, 25, 100); + spawn.bodyRect(11925, -300, 25, 100); + spawn.bodyRect(11950, -225, 75, 25); + spawn.bodyRect(12650, -50, 25, 100); + spawn.bodyRect(12675, -50, 25, 100); + spawn.bodyRect(12725, -50, 25, 100); + spawn.bodyRect(12750, -50, 50, 100); + spawn.bodyRect(12650, -275, 25, 75); + spawn.bodyRect(12675, -275, 25, 75); + spawn.bodyRect(12700, -275, 50, 75); + spawn.bodyRect(12750, -275, 25, 75); + spawn.bodyRect(12775, -275, 25, 75); + spawn.bodyRect(12800, -275, 25, 75); + spawn.bodyRect(12825, -275, 25, 75); + spawn.bodyRect(12850, -275, 50, 75); + spawn.bodyRect(12900, -275, 50, 75); + spawn.bodyRect(12950, -275, 50, 75); + spawn.mapRect(12200, 775, 175, 50); + spawn.mapRect(11550, 250, 1500, 75); + spawn.mapRect(11575, 275, 1450, 75); + spawn.mapRect(11600, 325, 1400, 50); + spawn.mapRect(11625, 350, 1350, 50); + spawn.mapRect(11725, 375, 1150, 50); + spawn.mapRect(11900, 400, 800, 50); + spawn.mapRect(12100, 425, 425, 50); + spawn.mapRect(12125, 475, 375, 25); + spawn.mapRect(12200, 475, 225, 50); + spawn.mapRect(11475, -400, 50, 700); + spawn.mapRect(11450, -375, 50, 625); + spawn.mapRect(11425, -350, 100, 600); + spawn.mapRect(11400, -300, 75, 525); + spawn.mapRect(11375, -250, 100, 400); + spawn.mapRect(11350, -150, 50, 200); + spawn.mapRect(13075, 825, 25, 50); + spawn.mapRect(13100, 850, 25, 25); + spawn.mapRect(13200, 700, 100, 225); + spawn.mapRect(13300, 775, 25, 100); + spawn.mapRect(13325, 825, 25, 50); + spawn.mapRect(13175, 775, 25, 125); + spawn.mapRect(13225, 675, 50, 25); + spawn.mapRect(13225, 925, 50, 25); + spawn.mapRect(9250, 75, 1400, 150); + spawn.mapRect(9250, -225, 150, 300); + spawn.mapRect(9250, -275, 575, 50); + spawn.mapRect(9675, -225, 150, 300); + spawn.mapRect(9325, -325, 400, 50); + spawn.mapRect(9400, -350, 250, 25); + spawn.mapRect(9475, -375, 125, 25); + spawn.mapRect(9825, -225, 150, 300); + spawn.mapRect(10225, -225, 150, 300); + spawn.mapRect(9825, -275, 550, 50); + spawn.mapRect(9900, -325, 375, 50); + spawn.mapRect(9950, -350, 275, 25); + spawn.mapRect(10000, -375, 175, 25); + spawn.mapRect(10350, -275, 50, 375); + spawn.mapRect(10400, -250, 25, 325); + spawn.mapRect(10425, -225, 25, 375); + spawn.mapRect(10450, -200, 25, 325); + spawn.mapRect(10475, -175, 25, 350); + spawn.mapRect(10500, -150, 25, 300); + spawn.mapRect(10525, -125, 25, 300); + spawn.mapRect(10550, -100, 25, 225); + spawn.mapRect(10575, -75, 25, 200); + spawn.mapRect(10600, -50, 25, 150); + spawn.mapRect(10625, -25, 25, 175); + spawn.mapRect(9225, -225, 25, 450); + spawn.mapRect(9200, -175, 25, 400); + spawn.mapRect(9175, -150, 50, 375); + spawn.mapRect(9150, -125, 50, 350); + spawn.mapRect(9400, -175, 25, 275); + spawn.mapRect(9425, -125, 25, 200); + spawn.mapRect(9650, -175, 25, 250); + spawn.mapRect(9625, -125, 25, 275); + spawn.mapRect(9975, -175, 25, 300); + spawn.mapRect(10000, -125, 25, 250); + spawn.mapRect(10200, -175, 25, 300); + spawn.mapRect(10175, -125, 25, 225); + spawn.mapRect(9325, 225, 225, 25); + spawn.mapRect(9675, 225, 250, 50); + spawn.mapRect(10075, 225, 200, 25); + spawn.mapRect(10400, 200, 175, 50); + spawn.mapRect(13425, 675, 1425, 100); + spawn.mapRect(13450, 725, 375, 75); + spawn.mapRect(13850, 775, 225, 50); + spawn.mapRect(14150, 750, 300, 50); + spawn.mapRect(14575, 750, 200, 75); + spawn.mapRect(13550, 800, 150, 25); + spawn.mapRect(14250, 800, 225, 25); + spawn.mapRect(13425, 275, 1425, 100); + spawn.mapRect(13475, 250, 1325, 75); + spawn.mapRect(13550, 225, 1125, 75); + spawn.mapRect(13600, 200, 1025, 25); + spawn.mapRect(13650, 150, 925, 50); + spawn.mapRect(13725, 100, 775, 100); + spawn.mapRect(13825, 50, 525, 100); + spawn.mapRect(13900, 0, 350, 75); + spawn.mapRect(13975, -25, 175, 75); + spawn.mapRect(13875, 25, 50, 50); + spawn.mapRect(13800, 75, 75, 50); + spawn.mapRect(13700, 125, 75, 50); + spawn.mapRect(13625, 200, 50, 25); + spawn.mapRect(13650, 175, 25, 25); + spawn.mapRect(13625, 175, 125, 75); + spawn.mapRect(14350, 75, 25, 50); + spawn.mapRect(14250, 0, 25, 75); + spawn.mapRect(14275, 50, 25, 50); + spawn.mapRect(14275, 25, 25, 75); + spawn.mapRect(14500, 125, 25, 75); + spawn.mapRect(14575, 175, 25, 75); + spawn.mapRect(13475, 650, 400, 50); + spawn.mapRect(13975, 675, 75, 25); + spawn.mapRect(14000, 650, 50, 50); + spawn.mapRect(14150, 625, 675, 100); + spawn.mapRect(14325, 625, 100, 25); + spawn.mapRect(14300, 600, 325, 25); + spawn.mapRect(13525, 325, 375, 100); + spawn.mapRect(13975, 375, 400, 25); + spawn.mapRect(14500, 325, 100, 75); + spawn.mapRect(14850, 675, 50, 200); + spawn.mapRect(14875, 700, 50, 175); + spawn.mapRect(14925, 725, 50, 150); + spawn.mapRect(14975, 750, 50, 125); + spawn.mapRect(15025, 775, 50, 100); + spawn.mapRect(15075, 750, 1150, 100); + spawn.mapRect(15100, 825, 225, 50); + spawn.mapRect(15500, 850, 225, 25); + spawn.mapRect(15925, 775, 275, 100); + spawn.mapRect(15775, 825, 50, 50); + spawn.mapRect(15225, 250, 1050, 125); + spawn.mapRect(15250, 200, 1000, 50); + spawn.mapRect(15275, 175, 950, 50); + spawn.mapRect(15300, 150, 900, 50); + spawn.mapRect(15325, 125, 850, 25); + spawn.mapRect(15350, 100, 800, 25); + spawn.mapRect(15375, 75, 750, 25); + spawn.mapRect(15400, 50, 700, 100); + spawn.mapRect(15425, 25, 650, 75); + spawn.mapRect(15450, 0, 600, 50); + spawn.mapRect(15475, -25, 550, 75); + spawn.mapRect(15500, -50, 500, 75); + spawn.mapRect(15525, -75, 450, 75); + spawn.mapRect(15550, -100, 400, 75); + spawn.mapRect(15575, -125, 350, 75); + spawn.mapRect(15600, -150, 300, 50); + spawn.mapRect(15625, -175, 250, 50); + spawn.mapRect(15650, -200, 200, 25); + spawn.mapRect(15675, -225, 150, 75); + spawn.mapRect(15700, -250, 100, 75); + spawn.mapRect(16275, 250, 25, 125); + spawn.mapRect(16250, 225, 25, 25); + spawn.mapRect(15200, 250, 25, 125); + spawn.mapRect(15225, 225, 25, 25); + spawn.mapRect(15275, 350, 175, 50); + spawn.mapRect(15550, 350, 425, 75); + spawn.mapRect(16100, 375, 175, 25); + spawn.mapRect(14700, -375, 50, 325); + spawn.mapRect(14700, -425, 375, 50); + spawn.mapRect(14750, -375, 125, 100); + spawn.mapRect(14750, -275, 75, 75); + spawn.mapRect(14850, -375, 100, 50); + spawn.mapRect(14825, -275, 25, 25); + spawn.mapRect(14950, -375, 25, 25); + spawn.mapRect(14875, -325, 25, 25); + spawn.mapRect(14725, -200, 50, 25); + spawn.mapRect(14700, -75, 100, 25); + spawn.mapRect(15050, -425, 25, 100); + spawn.mapRect(14725, -450, 325, 25); + spawn.mapRect(14775, -475, 225, 25); + spawn.mapRect(14825, -500, 125, 25); + spawn.mapRect(14675, -350, 25, 100); + spawn.mapRect(14675, -175, 25, 75); + spawn.mapRect(14850, 325, 25, 50); + spawn.mapRect(5700, -725, 375, 50); + spawn.mapRect(6025, -725, 50, 325); + spawn.mapRect(5775, -675, 250, 25); + spawn.mapRect(6000, -675, 25, 225); + spawn.mapRect(5950, -650, 50, 75); + spawn.mapRect(5900, -650, 75, 25); + spawn.mapRect(6000, -575, 25, 25); + spawn.mapRect(6050, -700, 50, 275); + spawn.mapRect(5925, -625, 75, 25); + spawn.mapRect(5775, -750, 100, 25); + spawn.mapRect(5950, -750, 100, 25); + spawn.mapRect(5675, -725, 25, 150); + spawn.mapRect(5975, -400, 100, 25); + spawn.mapRect(5650, -700, 25, 75); + spawn.mapRect(5700, -675, 25, 50); + spawn.mapRect(5700, -600, 25, 25); + spawn.mapRect(15275, 750, 225, 25); + spawn.mapRect(15225, 725, 250, 25); + spawn.mapRect(15675, 725, 275, 100); + spawn.mapRect(16075, 725, 125, 50); + spawn.pulsar(5775.349354333542, -594.9058498351887) + spawn.pulsar(5852.915433009502, -545.5679375496002) + spawn.pulsar(5921.99534574469, -480.69487503053097) + spawn.mapRect(3725, -975, 1525, 100); + spawn.mapRect(3750, -650, 300, 75); + spawn.mapRect(4300, -650, 300, 75); + spawn.mapRect(4950, -650, 300, 75); + spawn.mapRect(5250, -975, 75, 400); + spawn.mapRect(3725, -975, 75, 400); + spawn.mapRect(4325, -600, 250, 50); + spawn.mapRect(4350, -550, 200, 25); + spawn.mapRect(3800, -575, 225, 25); + spawn.mapRect(3825, -550, 175, 25); + spawn.mapRect(4975, -600, 275, 50); + spawn.mapRect(5025, -550, 175, 25); + spawn.mapRect(3800, -1025, 1450, 50); + spawn.mapRect(3875, -1075, 1275, 50); + spawn.mapRect(3975, -1125, 1000, 50); + spawn.mapRect(3950, -1100, 50, 25); + spawn.mapRect(3850, -1050, 150, 25); + spawn.mapRect(3775, -1000, 200, 25); + spawn.mapRect(5225, -975, 75, 25); + spawn.mapRect(4950, -1100, 75, 125); + spawn.mapRect(5100, -1050, 75, 75); + spawn.mapRect(5225, -1000, 50, 100); + spawn.mapRect(4350, -675, 150, 75); + spawn.mapRect(4525, -650, 50, 25); + spawn.mapRect(4550, -675, 50, 75); + spawn.mapRect(3825, -650, 50, 25); + spawn.mapRect(3825, -675, 150, 50); + spawn.mapRect(4025, -675, 25, 100); + spawn.mapRect(4950, -675, 75, 50); + spawn.mapRect(5075, -675, 75, 75); + spawn.mapRect(5200, -675, 75, 50); + spawn.pulsar(4068.196906578167, -653.550201356403) + spawn.pulsar(4147.672553167598, -651.0093457935446) + spawn.pulsar(4228.863663369247, -653.4768859607283) + spawn.pulsar(4619.092688319791, -657.3942377732394) + spawn.pulsar(4724.821759138369, -653.4213864043036) + spawn.pulsar(4873.583205330713, -657.4103118310311) + spawn.pulsar(3871.920598597728, -804.0595760512573) + spawn.pulsar(4053.019377134256, -778.0061810623848) + spawn.pulsar(4211.732836201937, -780.4633597161928) + spawn.pulsar(4380.7768131190005, -776.3400515412312) + spawn.pulsar(4533.031170401828, -791.1397513503708) + spawn.pulsar(4663.577749297493, -789.0488615794887) + spawn.pulsar(4965.48351658387, -809.0025104385204) + spawn.pulsar(5122.782442346123, -810.2526936643312) + spawn.mapRect(3700, -875, 25, 250); + spawn.mapRect(5325, -900, 25, 250); + spawn.mapRect(5325, -850, 50, 150); + spawn.mapRect(5375, -825, 25, 75); + spawn.pulsar(14786.058375868968, -140.5759223979466) + spawn.pulsar(14862.320083571307, -177.02507110101413) + spawn.pulsar(14888.982047411475, -216.4856450590454) + spawn.pulsar(14950.503812885598, -280.9333882582806) + spawn.pulsar(15003.202057456116, -316.6767970823471) + spawn.spinner(759.4093972764956, -356.0541595435453) + spawn.spinner(1467.1412487475097, -617.4326431210314) + spawn.mapRect(11850, 775, 50, 50); + spawn.mapRect(12075, 775, 50, 50); + spawn.mapRect(16225, 750, 75, 325); + spawn.mapRect(16300, 775, 50, 325); + spawn.mapRect(16350, 800, 50, 275); + spawn.mapRect(16375, 825, 50, 200); + spawn.mapRect(16450, 875, 25, 150); + spawn.mapRect(16450, 875, 25, 225); + spawn.mapRect(16400, 875, 50, 150); + spawn.mapRect(16225, 1025, 250, 75); + spawn.mapRect(16475, 925, 25, 175); + spawn.mapRect(16500, 975, 25, 125); + spawn.mapRect(16525, 1025, 25, 50); + spawn.mapRect(16425, 1075, 150, 25); + spawn.mapRect(16225, 1100, 1175, 75); + spawn.mapRect(17200, 1050, 25, 50); + spawn.mapRect(17225, 950, 25, 200); + spawn.mapRect(17250, 800, 25, 300); + spawn.mapRect(17275, 725, 25, 400); + spawn.mapRect(17300, 750, 75, 400); + spawn.mapRect(17300, 725, 100, 450); + spawn.mapRect(16300, 250, 1075, 125); + spawn.mapRect(16450, -75, 100, 400); + spawn.mapRect(17100, -75, 100, 400); + spawn.mapRect(16425, 200, 150, 50); + spawn.mapRect(17075, 200, 150, 50); + spawn.mapRect(16425, -75, 150, 25); + spawn.mapRect(17075, -75, 150, 50); + spawn.mapRect(16425, -50, 150, 50); + spawn.mapRect(16575, -75, 525, 50); + spawn.mapRect(17075, -50, 150, 50); + spawn.mapRect(16550, -100, 550, 25); + spawn.mapRect(16575, -125, 500, 75); + spawn.mapRect(16600, -150, 450, 75); + spawn.mapRect(16625, -175, 400, 75); + spawn.mapRect(16675, -200, 275, 50); + spawn.mapRect(16750, -225, 125, 100); + spawn.mapRect(19700, 675, 50, 325); + spawn.mapRect(19725, 700, 50, 250); + spawn.mapRect(19750, 750, 25, 175); + spawn.mapRect(16775, -25, 100, 275); + spawn.mapRect(16750, -25, 150, 25); + spawn.mapRect(16750, 225, 150, 50); + spawn.pulsar(3037.797768861211, -1242.9871362505041) + spawn.pulsar(3070.307596879197, -1219.5627538123044) + spawn.pulsar(3111.2633762820287, -1107.7297980154415) + spawn.pulsar(5417.516810698634, 842.824851834252) + spawn.pulsar(5484.672534515589, 883.9519420960905) + spawn.pulsar(5588.5457723826075, 907.389646857348) + spawn.pulsar(16845.139047921595, -885.6942536135854) + spawn.pulsar(16892.187197333486, -849.5235136465661) + spawn.pulsar(16912.323783455256, -764.5275187038021) + powerUps.spawn(2571.591711269197, -145.6717604789277, 'heal') + powerUps.spawn(4415.693974666946, -15.077304620299628, 'heal') + powerUps.spawn(7505.795753124317, -360.0330849392626, 'heal') + powerUps.spawn(7809.5145838152075, -388.5517653996709, 'heal') + powerUps.spawn(8049.726318297545, 534.4543327703304, 'heal') + powerUps.spawn(8514.444440033667, 551.0268033205841, 'heal') + powerUps.spawn(8927.146055851512, 407.25359241772685, 'heal') + powerUps.spawn(9730.170170158563, 463.5594890235955, 'ammo') + powerUps.spawn(9998.34942087522, 434.9511651200589, 'ammo') + powerUps.spawn(10119.083720019844, 437.4195779326937, 'ammo') + powerUps.spawn(10346.197135080345, 423.1868836972815, 'ammo') + powerUps.spawn(1853.3194789931017, -36.87254038474242, 'ammo') + powerUps.spawn(4491.396397908616, 40.2862012621236, 'ammo') + powerUps.spawn(4954.207518897743, 50.27790416201856, 'ammo') + spawn.mapRect(9125, -50, 75, 275); + spawn.mapRect(9100, 0, 50, 225); + spawn.mapRect(9075, 75, 75, 150); + spawn.mapRect(9050, 150, 125, 50); + spawn.mapRect(9050, 200, 225, 25); + mover1 = level.mover(4000, -1125, 975, 25); + mover2 = level.mover(15675, 725, 275, 25); + spawn.mapRect(15025, -375, 25, 25); + spawn.mapRect(12200, -150, 100, 25); + spawn.mapRect(11825, -150, 100, 25); + spawn.mapRect(11825, 75, 100, 50); + spawn.mapRect(12200, 75, 100, 50); + spawn.mapRect(12575, 100, 75, 25); + spawn.mapRect(12625, 50, 50, 75); + spawn.mapRect(12600, -175, 75, 50); + spawn.mapRect(12575, -175, 75, 50); + spawn.mapRect(14125, 650, 75, 25); + spawn.mapRect(13875, 375, 50, 25); + spawn.mapRect(13300, -525, 325, 50); + spawn.mapRect(13575, -525, 50, 250); + spawn.mapRect(13550, -300, 75, 25); + spawn.mapRect(13300, -525, 25, 75); + spawn.mapRect(13525, -475, 50, 50); + spawn.mapRect(13500, -475, 100, 25); + spawn.mapRect(13550, -475, 25, 100); + spawn.mapRect(13325, -550, 275, 25); + spawn.mapRect(13350, -575, 200, 25); + spawn.mapRect(13625, -500, 25, 175); + spawn.mapRect(13650, -450, 25, 75); + spawn.mapRect(13500, 375, 75, 25); + spawn.mapRect(15550, -950, 50, 225); + spawn.mapRect(15575, -750, 75, 25); + spawn.mapRect(15550, -950, 375, 50); + spawn.mapRect(15925, -950, 50, 225); + spawn.mapRect(15875, -750, 100, 25); + spawn.mapRect(15575, -1000, 375, 75); + spawn.mapRect(15625, -1050, 250, 100); + spawn.mapRect(15600, -1025, 75, 50); + spawn.mapRect(15875, -1000, 25, 25); + spawn.mapRect(15825, -1025, 75, 75); + spawn.mapRect(15700, -1100, 125, 50); + spawn.mapRect(15650, -1075, 75, 50); + spawn.mapRect(15800, -1075, 50, 75); + spawn.mapRect(15575, -725, 50, 25); + spawn.mapRect(15900, -725, 50, 25); + spawn.mapRect(15525, -925, 25, 175); + spawn.mapRect(15950, -925, 50, 200); + spawn.mapRect(15500, -875, 25, 75); + spawn.mapRect(16000, -875, 25, 75); + spawn.mapRect(15600, -900, 50, 75); + spawn.mapRect(15650, -900, 25, 25); + spawn.mapRect(15600, -825, 25, 25); + spawn.mapRect(15875, -900, 50, 50); + spawn.mapRect(15850, -925, 75, 50); + spawn.mapRect(15925, -875, 25, 25); + spawn.mapRect(15925, -850, 25, 25); + spawn.mapRect(15900, -875, 50, 50); + bigpool = level.hazard(9075, 575, 1950, 250); + spawn.mapRect(16000, -775, 25, 50); + spawn.mapRect(16000, -800, 25, 25); + spawn.mapRect(15500, -825, 25, 75); + spawn.mapRect(15475, -850, 75, 75); + spawn.mapRect(16000, -850, 50, 100); + spawn.mapRect(10775, -450, 50, 200); + spawn.mapRect(10775, -275, 100, 25); + spawn.mapRect(11100, -450, 50, 200); + spawn.mapRect(11050, -275, 75, 25); + spawn.mapRect(10775, -450, 375, 25); + spawn.mapRect(10825, -475, 275, 25); + spawn.mapRect(10875, -500, 150, 25); + spawn.mapRect(10900, -525, 100, 25); + spawn.mapRect(10750, -425, 25, 150); + spawn.mapRect(11150, -400, 25, 125); + spawn.mapRect(10725, -400, 50, 100); + spawn.mapRect(11150, -375, 50, 75); + spawn.mapRect(10800, -250, 50, 25); + spawn.mapRect(10825, -425, 50, 50); + spawn.mapRect(10875, -425, 25, 25); + spawn.mapRect(10825, -375, 25, 25); + spawn.mapRect(11050, -425, 50, 50); + spawn.mapRect(11025, -425, 25, 25); + spawn.mapRect(11075, -375, 25, 25); + spawn.mapRect(950, -1075, 50, 200); + spawn.mapRect(950, -1125, 300, 50); + spawn.mapRect(1000, -1075, 50, 50); + spawn.mapRect(1050, -1075, 25, 25); + spawn.mapRect(975, -1025, 50, 25); + spawn.mapRect(975, -1150, 250, 25); + spawn.mapRect(1000, -1175, 200, 25); + spawn.mapRect(900, -1075, 50, 175); + spawn.mapRect(875, -1050, 25, 125); + spawn.mapRect(950, -875, 125, 25); + spawn.mapRect(1250, -1125, 25, 125); + spawn.mapRect(975, -850, 75, 25); + spawn.mapRect(1250, -1100, 50, 75); + spawn.mapRect(925, -900, 50, 25); + spawn.mapRect(1050, -1200, 100, 25); + spawn.mapRect(1225, -1000, 50, 25); + spawn.mapRect(16375, 350, 900, 50); + spawn.mapRect(16400, 375, 850, 50); + spawn.mapRect(16425, 400, 800, 50); + spawn.mapRect(16475, 425, 675, 50); + spawn.mapRect(16625, 475, 375, 25); + spawn.mapRect(16650, 500, 325, 25); + spawn.mapRect(16675, 500, 275, 50); + spawn.mapRect(17400, 775, 25, 325); + spawn.mapRect(17425, 825, 25, 225); + spawn.mapRect(16200, 900, 25, 225); + spawn.mapRect(16175, 925, 25, 125); + spawn.mapRect(16150, 975, 25, 25); + spawn.mapRect(16400, 1150, 850, 50); + spawn.mapRect(16475, 1175, 650, 50); + spawn.mapRect(16575, 1225, 450, 25); + spawn.sneaker(7895.471733263175, 257.75477496554186) + spawn.sneaker(8109.4934675858085, 349.44686618726473) + spawn.sneaker(7525.886813944122, 391.9511482895349) + spawn.sneaker(8076.43795816953, 441.14947363958373) + spawn.pulsar(1064.583377612331, -976.2077284446908) + spawn.pulsar(1158.3436115513837, -1054.4975368803214) + spawn.pulsar(10966.055009228428, -373.8481911663377) + spawn.pulsar(10913.989668763379, -261.59108542627166) + spawn.pulsar(13454.158594286884, -402.8270664336466) + spawn.pulsar(13360.079608974078, -246.97797933698774) + spawn.pulsar(13497.913481830354, -251.68317759640576) + spawn.pulsar(15687.09056963911, -850.8426925141155) + spawn.pulsar(15829.058084589731, -785.4134546702737) + spawn.pulsar(15674.313958480483, -685.0594164868394) + spawn.pulsar(15819.881465281747, -686.4370174238113) + spawn.sneakBoss(18189.441342796745, 537.6633241821036) + thirdpool = level.hazard(16425, 925, 925, 200); + spawn.mapRect(17675, -525, 75, 725); + spawn.mapRect(17625, -475, 75, 650); + spawn.mapRect(17575, -425, 75, 575); + spawn.mapRect(17700, -525, 1125, 75); + spawn.mapRect(17675, 175, 1125, 75); + spawn.mapRect(18775, -525, 75, 775); + spawn.mapRect(18825, -475, 75, 675); + spawn.mapRect(18900, -450, 50, 625); + spawn.mapRect(18950, -400, 50, 500); + spawn.mapRect(17750, -575, 1000, 50); + spawn.mapRect(17775, -625, 950, 50); + spawn.mapRect(17800, -675, 900, 75); + spawn.mapRect(17825, -725, 850, 125); + spawn.mapRect(17850, -750, 800, 25); + spawn.mapRect(17750, 125, 50, 50); + spawn.mapRect(17750, 100, 25, 25); + spawn.mapRect(17800, 150, 25, 25); + spawn.mapRect(17750, -450, 75, 75); + spawn.mapRect(17750, -400, 25, 50); + spawn.mapRect(17800, -450, 50, 25); + spawn.mapRect(18750, -450, 25, 25); + spawn.mapRect(18725, -450, 50, 50); + spawn.mapRect(18700, -475, 25, 25); + spawn.mapRect(18725, -450, 25, 25); + spawn.mapRect(18700, -450, 75, 25); + spawn.mapRect(18750, -425, 25, 50); + spawn.mapRect(18725, 125, 75, 75); + spawn.mapRect(18700, 150, 50, 50); + spawn.mapRect(18750, 100, 75, 50); + spawn.mapRect(17850, 150, 850, 50); + spawn.mapRect(17825, 150, 25, 50); + spawn.mapRect(17550, -350, 25, 450); + spawn.mapRect(19000, -325, 25, 400); + spawn.mapRect(18000, -775, 475, 25); + spawn.mapRect(18025, -800, 425, 75); + spawn.mapRect(18050, -825, 375, 75); + spawn.mapRect(18075, -850, 325, 50); + spawn.mapRect(18100, -875, 275, 100); + spawn.mapRect(18125, -900, 225, 75); + spawn.mapRect(18150, -925, 175, 75); + spawn.mapRect(17275, 750, 1775, 125); + spawn.mapRect(17475, 725, 450, 50); + spawn.mapRect(18200, 725, 200, 50); + spawn.mapRect(18650, 725, 225, 75); + spawn.shieldingBoss(18253.51035871325, -131.1707821125636) + // spawn.blockBoss(12604.846253470663, 607.6074958800299) + spawn.mapRect(17725, 250, 1025, 25); + spawn.mapRect(17775, 275, 925, 25); + spawn.mapRect(17800, 300, 875, 25); + spawn.mapRect(17850, 325, 775, 25); + spawn.mapRect(17375, 275, 25, 75); + spawn.mapRect(19050, 750, 25, 275); + spawn.mapRect(19075, 775, 25, 250); + spawn.mapRect(19100, 800, 25, 225); + spawn.mapRect(19125, 850, 25, 175); + spawn.mapRect(19150, 875, 25, 150); + spawn.mapRect(19175, 925, 25, 100); + spawn.mapRect(19200, 950, 25, 75); + spawn.mapRect(19000, 850, 100, 175); + spawn.mapRect(19050, 975, 650, 50); + spawn.mapRect(19425, 650, 275, 50); + spawn.mapRect(19675, 650, 50, 375); + spawn.mapRect(19050, 1025, 625, 25); + spawn.mapRect(19075, 1050, 575, 25); + spawn.mapRect(19250, 1100, 200, 25); + spawn.mapRect(19175, 1075, 375, 25); + spawn.mapRect(19450, 625, 225, 25); + spawn.mapRect(19500, 600, 150, 50); + spawn.mapRect(19625, 700, 50, 50); + spawn.mapRect(19600, 700, 25, 25); + spawn.mapRect(19650, 750, 25, 25); + spawn.mapRect(19400, 650, 25, 100); + spawn.mapRect(19375, 675, 25, 50); + spawn.mapRect(17600, 875, 250, 25); + spawn.mapRect(18100, 850, 375, 50); + spawn.mapRect(18650, 875, 325, 25); + + pooldunker = level.mover(7175, 425, 50, 25); + level.custom = () => { + level.exit.drawAndCheck(); + pooldunker.VxGoal = 90; + pooldunker.push(); + mover.VxGoal = 45; + mover.push(); + level.enter.draw(); + pool.query(); + wastepool.query(); + thirdpool.query(); + mover1.VxGoal = 12; + mover1.push(); + mover2.VxGoal = 24; + mover2.push(); + bigpool.query(); + + for (i = 0; i < mob.length; i++) { if (mob[i].isBoss == false) { mob[i].damageReduction = 0.13 } } + }; + + spawn.mapRect(-100, 0, 1000, 100); + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + ace() { + simulation.inGameConsole(`ace by Richard0820`); + let isDestroyed = false; + const ace = { + spawnOrbitals(who, radius, chance = Math.min(0.25 + simulation.difficulty * 0.005)) { + if (Math.random() < chance) { + const len = Math.floor(Math.min(15, 3 + Math.sqrt(simulation.difficulty))) + const speed = (0.003 + 0.004 * Math.random() + 0.002 * Math.sqrt(simulation.difficulty)) * ((Math.random() < 0.5) ? 1 : -1) + const offSet = 6.28 * Math.random() + for (let i = 0; i < len; i++) ace.orbital(who, radius, i / len * 2 * Math.PI + offSet, speed) + } + }, + orbital(who, radius, phase, speed) { + // for (let i = 0, len = 7; i < len; i++) spawn.orbital(me, radius + 250, 2 * Math.PI / len * i) + mobs.spawn(who.position.x, who.position.y, 8, 12, "rgb(0,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.01); //normal is 0.001 + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isUnstable = true; //dies when blocked + me.showHealthBar = false; + me.isOrbital = true; + // me.isShielded = true + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet; //cat.player | cat.map | cat.body + me.do = function () { + //if host is gone + if (!who || !who.alive) { + this.death(); + return + } + //set orbit + const time = simulation.cycle * speed + phase + const orbit = { + x: Math.cos(time), + y: Math.sin(time) + } + Matter.Body.setPosition(this, Vector.add(Vector.add(who.position, who.velocity), Vector.mult(orbit, radius))) + //damage player + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + const dmg = 0.03 * simulation.dmgScale + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + this.death(); + } + }; + }, + shield(target, x, y, chance = Math.min(0.02 + simulation.difficulty * 0.005, 0.2) + tech.duplicationChance()) { + if (this.allowShields && Math.random() < chance) { + mobs.spawn(x, y, 9, target.radius + 30, "rgba(255,255,255,0.9)"); + let me = mob[mob.length - 1]; + me.stroke = "rgb(0,0,0)"; + Matter.Body.setDensity(me, 0.00001) //very low density to not mess with the original mob's motion + me.shield = true; + me.damageReduction = 0.05 + me.isUnblockable = true + me.collisionFilter.category = cat.mobShield + me.collisionFilter.mask = cat.bullet; + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: target, //attach shield to target + stiffness: 0.4, + damping: 0.1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + + me.onDamage = function () { + //make sure the mob that owns the shield can tell when damage is done + this.alertNearByMobs(); + this.fill = `rgba(255,255,255,${0.3 + 0.6 * this.health})` + }; + me.leaveBody = false; + me.isDropPowerUp = false; + me.showHealthBar = false; + + me.shieldTargetID = target.id + target.isShielded = true; + if (target.shieldCount > 0) { + target.shieldCount++ + } else { + target.shieldCount = 1 + } + me.shieldCount = target.shieldCount //used with "bubble fusion" + target.shieldID = me.id + me.onDeath = function () { + //clear isShielded status from target + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].id === this.shieldTargetID) mob[i].isShielded = false; + } + }; + me.do = function () { + this.checkStatus(); + }; + + mob.unshift(me); //move shield to the front of the array, so that mob is behind shield graphically + + //swap order of shield and mob, so that mob is behind shield graphically + // mob[mob.length - 1] = mob[mob.length - 2]; + // mob[mob.length - 2] = me; + } + }, + groupShield(targets, x, y, radius, stiffness = 0.4) { + const nodes = targets.length + mobs.spawn(x, y, 9, radius, "rgba(255,255,255,0.9)"); + let me = mob[mob.length - 1]; + me.stroke = "rgb(0,0,0)"; + Matter.Body.setDensity(me, 0.00001) //very low density to not mess with the original mob's motion + me.frictionAir = 0; + me.shield = true; + me.damageReduction = 0.075 + me.collisionFilter.category = cat.mobShield + me.collisionFilter.mask = cat.bullet; + for (let i = 0; i < nodes; ++i) { + mob[mob.length - i - 2].isShielded = true; + //constrain to all mob nodes in group + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: mob[mob.length - i - 2], + stiffness: stiffness, + damping: 0.1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + me.onDamage = function () { + this.alertNearByMobs(); //makes sure the mob that owns the shield can tell when damage is done + this.fill = `rgba(255,255,255,${0.3 + 0.6 * this.health})` + }; + me.onDeath = function () { + //clear isShielded status from target + for (let j = 0; j < targets.length; j++) { + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].id === targets[j]) mob[i].isShielded = false; + } + } + }; + me.leaveBody = false; + me.isDropPowerUp = false; + me.showHealthBar = false; + mob[mob.length - 1] = mob[mob.length - 1 - nodes]; + mob[mob.length - 1 - nodes] = me; + me.do = function () { + this.checkStatus(); + }; + }, + slasher2(x, y, radius = 33 + Math.ceil(Math.random() * 30)) { + mobs.spawn(x, y, 6, radius, "rgb(0,0,0)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.0009 * simulation.accelScale; + me.torqueMagnitude = 0.000012 * me.inertia //* (Math.random() > 0.5 ? -1 : 1); + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.035; + me.delay = 140 * simulation.CDScale; + me.cd = 0; + me.swordRadius = 0; + me.swordVertex = 1 + me.swordRadiusMax = 275 + 3.5 * simulation.difficulty; + me.swordRadiusGrowRate = me.swordRadiusMax * (0.011 + 0.0002 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.03 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + const seeDistance2 = 200000 + ace.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.checkStatus(); + this.seePlayerByHistory(15); + this.attraction(); + this.sword() //does various things depending on what stage of the sword swing + }; + me.swordWaiting = function () { + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + this.laserAngle = -Math.PI / 6 + this.sword = this.swordGrow + this.accelMag = 0 + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + this.laserSword(this.vertices[0], this.angle + this.laserAngle); + this.laserSword(this.vertices[1], this.angle + this.laserAngle + (Math.PI / 3)); + this.laserSword(this.vertices[2], this.angle + this.laserAngle + (Math.PI * 2 / 3)); + this.laserSword(this.vertices[3], this.angle + this.laserAngle + Math.PI); + this.laserSword(this.vertices[4], this.angle + this.laserAngle + (Math.PI * 4 / 3)); + this.laserSword(this.vertices[5], this.angle + this.laserAngle + (Math.PI * 5 / 3)); + this.swordRadius += this.swordRadiusGrowRate + if (this.swordRadius > this.swordRadiusMax || this.isStunned) { + this.sword = this.swordSlash + this.spinCount = 0 + } + } + me.swordSlash = function () { + this.laserSword(this.vertices[0], this.angle + this.laserAngle); + this.laserSword(this.vertices[1], this.angle + this.laserAngle + (Math.PI / 3)); + this.laserSword(this.vertices[2], this.angle + this.laserAngle + (Math.PI * 2 / 3)); + this.laserSword(this.vertices[3], this.angle + this.laserAngle + Math.PI); + this.laserSword(this.vertices[4], this.angle + this.laserAngle + (Math.PI * 4 / 3)); + this.laserSword(this.vertices[5], this.angle + this.laserAngle + (Math.PI * 5 / 3)); + + this.torque += this.torqueMagnitude; + this.spinCount++ + if (this.spinCount > 100 || this.isStunned) { + this.sword = this.swordWaiting + this.swordRadius = 0 + this.accelMag = 0.001 * simulation.accelScale; + this.cd = simulation.cycle + this.delay; + } + } + me.laserSword = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let v = domain[i].vertices; + const len = v.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, v[j], v[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[j], v2: v[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, v[0], v[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[0], v2: v[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [playerBody, playerHead]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(0,0,0,0.1)"; // 0 path + ctx.lineWidth = 15; + ctx.stroke(); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; // 0 path + ctx.lineWidth = 4; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + slasher3(x, y, radius = 33 + Math.ceil(Math.random() * 30)) { + const sides = 6 + mobs.spawn(x, y, sides, radius, "rgb(0,0,0)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.0005 * simulation.accelScale; + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.02; + me.delay = 150 * simulation.CDScale; + me.cd = 0; + me.cycle = 0; + me.swordVertex = 1 + me.swordRadiusInitial = radius / 2; + me.swordRadius = me.swordRadiusInitial; + me.swordRadiusMax = 750 + 6 * simulation.difficulty; + me.swordRadiusGrowRateInitial = 1.08 + me.swordRadiusGrowRate = me.swordRadiusGrowRateInitial//me.swordRadiusMax * (0.009 + 0.0002 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.04 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + const seeDistance2 = me.swordRadiusMax * me.swordRadiusMax + ace.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.checkStatus(); + this.seePlayerByHistory(15); + this.sword() //does various things depending on what stage of the sword swing + }; + me.swordWaiting = function () { + this.attraction(); + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + //find vertex closest to the player + let dist = Infinity + for (let i = 0, len = this.vertices.length; i < len; i++) { + const D = Vector.magnitudeSquared(Vector.sub({ x: this.vertices[i].x, y: this.vertices[i].y }, m.pos)) + if (D < dist) { + dist = D + this.swordVertex = i + } + } + this.laserAngle = this.swordVertex / sides * 2 * Math.PI + Math.PI / sides + this.sword = this.swordGrow + this.cycle = 0 + this.swordRadius = this.swordRadiusInitial + //slow velocity but don't stop + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.5)) + //set angular velocity to 50% + // Matter.Body.setAngularVelocity(this, this.angularVelocity * 0.5) + //gently rotate towards the player with a torque, use cross product to decided clockwise or counterclockwise + const laserStartVector = Vector.sub(this.position, this.vertices[this.swordVertex]) + const playerVector = Vector.sub(this.position, m.pos) + const cross = Matter.Vector.cross(laserStartVector, playerVector) + this.torque = 0.00002 * this.inertia * (cross > 0 ? 1 : -1) + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + const angle = this.angle + this.laserAngle; + const end = { + x: this.vertices[this.swordVertex].x + this.swordRadiusMax * Math.cos(angle), + y: this.vertices[this.swordVertex].y + this.swordRadiusMax * Math.sin(angle) + }; + + const dx = end.x - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].x; + const dy = end.y - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].y; + const angle1 = Math.atan2(dy, dx) * (180 / Math.PI); + + const dx1 = end.x - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].x; + const dy1 = end.y - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].y; + const angle2 = Math.atan2(dy1, dx1) * (180 / Math.PI); + + this.laserSpear(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.laserSpear(this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1], angle1 * (Math.PI / 180)) + this.laserSpear(this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1], angle2 * (Math.PI / 180)) + + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.9)) + // this.swordRadius += this.swordRadiusGrowRate + this.cycle++ + // this.swordRadius = this.swordRadiusMax * Math.sin(this.cycle * 0.03) + this.swordRadius *= this.swordRadiusGrowRate + + if (this.swordRadius > this.swordRadiusMax) this.swordRadiusGrowRate = 1 / this.swordRadiusGrowRateInitial + // if (this.swordRadius > this.swordRadiusMax) this.swordRadiusGrowRate = -Math.abs(this.swordRadiusGrowRate) + if (this.swordRadius < this.swordRadiusInitial || this.isStunned) { + // this.swordRadiusGrowRate = Math.abs(this.swordRadiusGrowRate) + this.swordRadiusGrowRate = this.swordRadiusGrowRateInitial + this.sword = this.swordWaiting + this.swordRadius = 0 + this.cd = simulation.cycle + this.delay; + } + } + me.laserSpear = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let v = domain[i].vertices; + const len = v.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, v[j], v[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[j], v2: v[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, v[0], v[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[0], v2: v[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [playerBody, playerHead]); + if (best.who && (best.who === playerBody || best.who === playerHead)) { + this.swordRadiusGrowRate = 1 / this.swordRadiusGrowRateInitial //!!!! this retracts the sword if it hits the player + + if (m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(0,0,0,0.1)"; // 0 path + ctx.lineWidth = 15; + ctx.stroke(); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; // 0 path + ctx.lineWidth = 4; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + stabber(x, y, radius = 25 + Math.ceil(Math.random() * 12), spikeMax = 7) { + if (radius > 80) radius = 65; + mobs.spawn(x, y, 6, radius, "rgb(0,0,0)"); //can't have sides above 6 or collision events don't work (probably because of a convex problem) + let me = mob[mob.length - 1]; + me.isVerticesChange = true + me.accelMag = 0.0006 * simulation.accelScale; + // me.g = 0.0002; //required if using this.gravity + me.isInvulnerable = false + me.delay = 360 * simulation.CDScale; + me.spikeVertex = 0; + me.spikeLength = 0; + me.isSpikeGrowing = false; + me.spikeGrowth = 0; + me.isSpikeReset = true; + me.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.player //can't touch other mobs + Matter.Body.rotate(me, Math.PI * 0.1); + ace.shield(me, x, y); + // me.onDamage = function () {}; + // me.onHit = function() { //run this function on hitting player + // }; + me.onDeath = function () { + if (this.spikeLength > 4) { + this.spikeLength = 4 + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[this.spikeVertex], this.position)), this.radius * this.spikeLength) + this.vertices[this.spikeVertex].x = this.position.x + spike.x + this.vertices[this.spikeVertex].y = this.position.y + spike.y + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) + } + }; + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + if (this.isSpikeReset) { + if (this.seePlayer.recall) { + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + if (distMag < radius * spikeMax) { + //find nearest vertex + let nearestDistance = Infinity + for (let i = 0, len = this.vertices.length; i < len; i++) { + //find distance to player for each vertex + const dist = Vector.sub(this.seePlayer.position, this.vertices[i]); + const distMag = Vector.magnitude(dist); + //save the closest distance + if (distMag < nearestDistance) { + this.spikeVertex = i + nearestDistance = distMag + } + } + this.spikeLength = 1 + this.isSpikeGrowing = true; + this.isSpikeReset = false; + Matter.Body.setAngularVelocity(this, 0) + } + me.isInvulnerable = false + } + } else { + if (this.isSpikeGrowing) { + this.spikeLength += Math.pow(this.spikeGrowth += 0.02, 8) + // if (this.spikeLength < 2) { + // this.spikeLength += 0.035 + // } else { + // this.spikeLength += 1 + // } + if (this.spikeLength > spikeMax) { + this.isSpikeGrowing = false; + this.spikeGrowth = 0 + } + } else { + Matter.Body.setAngularVelocity(this, this.angularVelocity * 0.8) //reduce rotation + this.spikeLength -= 0.3 + if (this.spikeLength < 1) { + this.spikeLength = 1 + this.isSpikeReset = true + this.radius = radius + } + } + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[this.spikeVertex], this.position)), radius * this.spikeLength) + this.vertices[this.spikeVertex].x = this.position.x + spike.x + this.vertices[this.spikeVertex].y = this.position.y + spike.y + me.isInvulnerable = true + // this.radius = radius * this.spikeLength; + } + if (this.isInvulnerable) { + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + me.damageReduction = 0; + } else { + me.damageReduction = 1; + } + }; + }, + slash(x, y, radius = 80) { + let targets = [] + const sides = 6; + mobs.spawn(x, y, 6, radius, "#000000"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + targets.push(me.id) //add to shield protection + const nodeBalance = Math.random() + const nodes2 = Math.min(15, Math.floor(2 + 4 * nodeBalance + 0.75 * Math.sqrt(simulation.difficulty))) + me.isBoss = true; + me.isSlashBoss = true; + me.showHealthBar = false; + me.damageReduction = 0.1 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.frictionAir = 0.02 + me.seeAtDistance2 = 1000000; + me.accelMag = 0.0004 + 0.00015 * simulation.accelScale; + Matter.Body.setDensity(me, 0.0005); //normal is 0.001 + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map + me.memory = Infinity; + me.seePlayerFreq = 20 + me.lockedOn = null; + me.laserRange = 500; + me.torqueMagnitude = 0.00024 * me.inertia * (Math.random() > 0.5 ? -1 : 1); + me.delay = 70 + 70 * simulation.CDScale; + me.cd = 0; + me.swordRadius = 0; + me.swordVertex = 1 + me.swordRadiusMax = 1100 + 20 * simulation.difficulty; + me.swordRadiusGrowRate = me.swordRadiusMax * (0.005 + 0.0003 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.07 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + me.eventHorizon = 550; + const seeDistance2 = 200000 + ace.shield(me, x, y); + const rangeInnerVsOuter = Math.random() + let speed = (0.006 + 0.001 * Math.sqrt(simulation.difficulty)) * ((Math.random() < 0.5) ? 1 : -1) + let range = radius + 350 + 200 * rangeInnerVsOuter + nodes2 * 7 + for (let i = 0; i < nodes2; i++) ace.orbital(me, range, i / nodes2 * 2 * Math.PI, speed) + const orbitalIndexes = [] //find indexes for all the current nodes2 + for (let i = 0; i < nodes2; i++) orbitalIndexes.push(mob.length - 1 - i) + // add orbitals for each orbital + range = Math.max(60, 100 + 100 * Math.random() - nodes2 * 3 - rangeInnerVsOuter * 80) + speed = speed * (1.25 + 2 * Math.random()) + const subNodes = Math.max(2, Math.floor(6 - 5 * nodeBalance + 0.5 * Math.sqrt(simulation.difficulty))) + for (let j = 0; j < nodes2; j++) { + for (let i = 0, len = subNodes; i < len; i++) ace.orbital(mob[orbitalIndexes[j]], range, i / len * 2 * Math.PI, speed) + } + for (let i = 0, len = 3 + 0.5 * Math.sqrt(simulation.difficulty); i < len; i++) ace.spawnOrbitals(me, radius + 40 + 10 * i, 1); + + const springStiffness = 0.00014; + const springDampening = 0.0005; + + me.springTarget = { + x: me.position.x, + y: me.position.y + }; + const len = cons.length; + cons[len] = Constraint.create({ + pointA: me.springTarget, + bodyB: me, + stiffness: springStiffness, + damping: springDampening + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len].length = 100 + 1.5 * radius; + me.cons = cons[len]; + + me.springTarget2 = { + x: me.position.x, + y: me.position.y + }; + const len2 = cons.length; + cons[len2] = Constraint.create({ + pointA: me.springTarget2, + bodyB: me, + stiffness: springStiffness, + damping: springDampening, + length: 0 + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len2].length = 100 + 1.5 * radius; + me.cons2 = cons[len2]; + me.onDamage = function () { }; + me.onDeath = function () { + isDestroyed = true; + this.removeCons(); + powerUps.spawnBossPowerUp(this.position.x, this.position.y); + }; + me.do = function () { + for (let i = 0; i < this.vertices.length; i++) { + this.harmField(this.vertices[i].x, this.vertices[i].y); + } + this.seePlayerByHistory(40); + this.springAttack(); + this.checkStatus(); + this.sword() //does various things depending on what stage of the sword swing + const eventHorizon = this.eventHorizon * (1 + 0.2 * Math.sin(simulation.cycle * 0.008)) + me.laserRange = eventHorizon; + }; + me.swordWaiting = function () { + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + !m.isCloak && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + //find vertex farthest away from player + let dist = 0 + for (let i = 0, len = this.vertices.length; i < len; i++) { + const D = Vector.magnitudeSquared(Vector.sub({ x: this.vertices[i].x, y: this.vertices[i].y }, m.pos)) + if (D > dist) { + dist = D + this.swordVertex = i + } + } + this.laserAngle = this.swordVertex / 6 * 2 * Math.PI + 0.6283 + this.sword = this.swordGrow + Matter.Body.setAngularVelocity(this, 0) + this.accelMag = 0.0004 + 0.00015 * simulation.accelScale; + this.damageReduction = 0 + this.isInvulnerable = true + this.frictionAir = 1 + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + const angle = this.angle + this.laserAngle; + const end = { + x: this.vertices[this.swordVertex].x + this.swordRadiusMax * Math.cos(angle), + y: this.vertices[this.swordVertex].y + this.swordRadiusMax * Math.sin(angle) + }; + + const dx = end.x - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].x; + const dy = end.y - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].y; + const angle1 = Math.atan2(dy, dx) * (180 / Math.PI); + + const dx1 = end.x - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].x; + const dy1 = end.y - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].y; + const angle2 = Math.atan2(dy1, dx1) * (180 / Math.PI); + + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.laserSword(this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1], angle1 * (Math.PI / 180)) + this.laserSword(this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1], angle2 * (Math.PI / 180)) + this.swordRadius += this.swordRadiusGrowRate + if (this.swordRadius > this.swordRadiusMax) { + this.sword = this.swordSlash + this.spinCount = 0 + } + + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + me.swordSlash = function () { + const angle = this.angle + this.laserAngle; + const end = { + x: this.vertices[this.swordVertex].x + this.swordRadiusMax * Math.cos(angle), + y: this.vertices[this.swordVertex].y + this.swordRadiusMax * Math.sin(angle) + }; + + const dx = end.x - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].x; + const dy = end.y - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].y; + const angle1 = Math.atan2(dy, dx) * (180 / Math.PI); + + const dx1 = end.x - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].x; + const dy1 = end.y - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].y; + const angle2 = Math.atan2(dy1, dx1) * (180 / Math.PI); + + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.laserSword(this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1], angle1 * (Math.PI / 180)) + this.laserSword(this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1], angle2 * (Math.PI / 180)) + this.torque += this.torqueMagnitude; + this.spinCount++ + if (this.spinCount > 80) { + this.sword = this.swordWaiting + this.swordRadius = 0 + this.accelMag = 0.0004 + 0.00015 * simulation.accelScale; + this.cd = simulation.cycle + this.delay; + this.damageReduction = this.startingDamageReduction + this.isInvulnerable = false + this.frictionAir = 0.01 + } + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + me.laserSword = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let v = domain[i].vertices; + const len = v.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, v[j], v[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[j], v2: v[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, v[0], v[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[0], v2: v[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [playerBody, playerHead]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(0,0,0,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(0,0,0,0.1)"; // Black path + ctx.lineWidth = 25; + ctx.stroke(); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; // Black path + ctx.lineWidth = 5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + me.harmField = function (x, y) { + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + // ctx.lineDashOffset = 6*(simulation.cycle % 215); + if (this.distanceToPlayer3(x, y) < this.laserRange) { + if (m.immuneCycle < m.cycle) { + m.damage(0.0003 * simulation.dmgScale); + if (m.energy > 0.1) m.energy -= 0.003 + } + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineTo(m.pos.x + (Math.random() - 0.5) * 3000, m.pos.y + (Math.random() - 0.5) * 3000); + ctx.lineWidth = 2; + ctx.strokeStyle = "rgb(0,0,0)"; + ctx.stroke(); + + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.15)"; + ctx.fill(); + } + ctx.beginPath(); + ctx.arc(x, y, this.laserRange * 0.9, 0, 2 * Math.PI); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + ctx.lineWidth = 1; + ctx.stroke(); + ctx.setLineDash([]); + ctx.fillStyle = "rgba(0,0,0,0.03)"; + ctx.fill(); + } + me.distanceToPlayer3 = function (x, y) { + const dx = x - player.position.x; + const dy = y - player.position.y; + return Math.sqrt(dx * dx + dy * dy); + } + radius = 22 // radius of each node mob + const sideLength = 100 // distance between each node mob + const nodes = 6 + const angle = 2 * Math.PI / nodes + + spawn.allowShields = false; //don't want shields on individual mobs + + for (let i = 0; i < nodes; ++i) { + ace.stabber(x + sideLength * Math.sin(i * angle), y + sideLength * Math.cos(i * angle), radius, 12); + Matter.Body.setDensity(mob[mob.length - 1], 0.003); //extra dense //normal is 0.001 //makes effective life much larger + mob[mob.length - 1].damageReduction = 0.12 + mob[mob.length - 1].showHealthBar = false; + mob[mob.length - 1].isBoss = true; + targets.push(mob[mob.length - 1].id) //track who is in the node boss, for shields + } + + const attachmentStiffness = 0.02 + spawn.constrain2AdjacentMobs(nodes, attachmentStiffness, true); //loop mobs together + + for (let i = 0; i < nodes; ++i) { //attach to center mob + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: mob[mob.length - i - 1], + stiffness: attachmentStiffness, + damping: 0.03 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + //spawn shield around all nodes + ace.groupShield(targets, x, y, sideLength + 1 * radius + nodes * 5 - 25); + spawn.allowShields = true; + }, + } + level.setPosToSpawn(-625, -100); //normal spawn + level.exit.x = -23650; + level.exit.y = 11100; + simulation.fallHeight = 20000; + const door = level.door(350, -200, 25, 225, 225, 10) + const door2 = level.door(6325, -200, 25, 225, 225, 10); + // spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + ace.stabber(425, -100); + ace.stabber(725, -100); + ace.stabber(1000, -100); + ace.stabber(1300, -100); + ace.stabber(1550, -100); + ace.stabber(1850, -100); + ace.stabber(2125, -100); + ace.stabber(2400, -100); + ace.stabber(2675, -100); + ace.stabber(2975, -100); + ace.stabber(3225, -100); + ace.stabber(3525, -100); + ace.stabber(3800, -100); + ace.stabber(4100, -100); + ace.stabber(4375, -100); + ace.stabber(4650, -100); + ace.stabber(4925, -100); + ace.stabber(5200, -100); + ace.stabber(5500, -100); + ace.stabber(5775, -100); + spawn.mapRect(-200, -450, 2825, 75); + spawn.mapRect(-200, 0, 2825, 75); + spawn.mapRect(-300, -400, 150, 50); + spawn.mapRect(-575, -375, 325, 50); + spawn.mapRect(-1175, 0, 700, 75); + spawn.mapRect(-1100, 50, 675, 75); + spawn.mapRect(-1100, -50, 225, 75); + spawn.mapRect(-1025, -75, 200, 50); + spawn.mapRect(-875, -50, 150, 75); + spawn.mapRect(-700, -350, 325, 50); + spawn.mapRect(-950, -100, 150, 50); + spawn.mapRect(-675, -50, 125, 25); + spawn.mapRect(-575, -150, 25, 125); + spawn.mapRect(-650, -50, 25, 75); + spawn.mapRect(-600, -50, 25, 75); + spawn.mapRect(-800, -325, 250, 50); + spawn.mapRect(-1450, 50, 500, 75); + spawn.mapRect(-1550, 100, 475, 100); + spawn.mapRect(-1650, 175, 525, 375); + spawn.mapRect(-1700, 275, 200, 175); + spawn.mapRect(-1550, 525, 475, 100); + spawn.mapRect(-1475, 600, 4125, 100); + spawn.mapRect(-50, 50, 75, 75); + level.chain(-450, 75, 0, false, 13) + level.chain(7475, 600, -0.5498531827, false, 200) + spawn.mapRect(325, -425, 75, 275); + spawn.mapRect(-850, -300, 100, 50); + spawn.mapRect(-900, -125, 75, 50); + spawn.mapRect(-875, -275, 50, 50); + spawn.mapRect(425, -400, 125, 100); + spawn.mapRect(600, -400, 125, 100); + spawn.mapRect(775, -400, 125, 100); + spawn.mapRect(950, -400, 125, 100); + spawn.mapRect(375, -350, 2250, 25); + spawn.mapRect(1125, -400, 125, 100); + spawn.mapRect(1300, -400, 125, 100); + spawn.mapRect(1475, -400, 125, 100); + spawn.mapRect(1650, -400, 125, 100); + spawn.mapRect(1825, -400, 125, 100); + spawn.mapRect(2000, -400, 125, 100); + spawn.mapRect(2175, -400, 125, 100); + spawn.mapRect(2350, -400, 125, 100); + spawn.mapRect(2525, -400, 125, 100); + spawn.mapRect(-1350, 650, 4000, 150); + spawn.mapRect(-1400, 675, 125, 75); + spawn.mapRect(-1325, 25, 200, 50); + spawn.mapRect(2600, 600, 4350, 200); + spawn.mapRect(2550, 0, 4400, 75); + spawn.mapRect(6875, 0, 875, 75); + spawn.mapRect(2500, -450, 5300, 50); + spawn.mapRect(7575, -425, 575, 475); + spawn.mapRect(6825, 600, 650, 125); + spawn.mapRect(6875, 675, 475, 100); + spawn.mapRect(7050, -525, 1175, 175); + spawn.mapRect(7650, -25, 575, 150); + spawn.mapRect(6075, -500, 1125, 75); + spawn.mapRect(2550, -350, 3450, 25); + spawn.mapRect(2700, -400, 125, 100); + spawn.mapRect(2875, -400, 125, 100); + spawn.mapRect(3050, -400, 125, 100); + spawn.mapRect(3225, -400, 125, 100); + spawn.mapRect(3400, -400, 125, 100); + spawn.mapRect(3575, -400, 125, 100); + spawn.mapRect(3750, -400, 125, 100); + spawn.mapRect(3925, -400, 125, 100); + spawn.mapRect(4100, -400, 125, 100); + spawn.mapRect(4275, -400, 125, 100); + spawn.mapRect(4450, -400, 125, 100); + spawn.mapRect(4625, -400, 125, 100); + spawn.mapRect(4800, -400, 125, 100); + spawn.mapRect(4975, -400, 125, 100); + spawn.mapRect(5150, -400, 125, 100); + spawn.mapRect(5325, -400, 125, 100); + spawn.mapRect(5500, -400, 125, 100); + spawn.mapRect(5675, -400, 125, 100); + spawn.mapRect(5850, -400, 125, 100); + spawn.mapRect(6000, -400, 125, 100); + spawn.mapRect(6100, -425, 125, 100); + spawn.mapRect(6150, -450, 200, 75); + spawn.mapRect(2575, -400, 3575, 25); + spawn.mapRect(6300, -425, 75, 250); + spawn.mapRect(-200, -175, 50, 50); + spawn.bodyRect(-950, 475, 150, 125); + spawn.bodyRect(-650, 475, 150, 125); + spawn.bodyRect(-1000, 350, 550, 125); + spawn.bodyRect(-650, 150, 225, 200); + spawn.bodyRect(-1050, 150, 400, 200); + spawn.bodyRect(-1125, 225, 25, 275); + spawn.bodyRect(-1100, 350, 125, 200); + spawn.bodyRect(-800, 475, 150, 125); + spawn.bodyRect(-500, 475, 125, 125); + spawn.mapRect(-3325, -50, 600, 75); + spawn.mapRect(-3250, 0, 450, 75); + spawn.mapRect(-2950, -100, 350, 75); + spawn.mapRect(-2975, -150, 325, 75); + spawn.mapRect(-3150, -250, 125, 25); + spawn.mapRect(-3050, -225, 100, 25); + spawn.mapRect(-3000, -200, 125, 25); + spawn.mapRect(-3425, -75, 325, 50); + spawn.mapRect(-3250, -225, 125, 25); + spawn.mapRect(-3325, -200, 100, 25); + spawn.mapRect(-3100, -300, 25, 50); + spawn.mapRect(-3725, -325, 1300, 25); + spawn.mapRect(-2925, -175, 125, 25); + spawn.mapRect(-3375, -175, 100, 25); + spawn.mapRect(-3550, -150, 250, 75); + spawn.mapRect(-3725, -150, 250, 50); + spawn.mapRect(-3725, -200, 125, 75); + spawn.mapRect(-3625, -175, 50, 25); + spawn.mapRect(-3750, -125, 50, 25); + spawn.mapRect(-3750, -50, 125, 50); + spawn.mapRect(-3650, -125, 75, 100); + spawn.mapRect(-2750, 0, 100, 75); + spawn.mapRect(-2675, 25, 175, 25); + spawn.mapRect(-2850, 0, 150, 50); + spawn.mapRect(-3150, 50, 25, 75); + spawn.mapRect(-2900, 50, 25, 75); + spawn.mapRect(-3300, 100, 575, 25); + spawn.mapRect(-24300, 11125, 51525, 6250); + spawn.mapVertex(7900, -675, "0 0 500 -200 500 300 -450 300") + spawn.mapRect(-24300, 9575, 475, 1750); + spawn.mapRect(26800, 9575, 425, 1750); + spawn.hopper(-3100, -150); + spawn.mapRect(11625, 8375, 11200, 225); + spawn.mapRect(22600, 8375, 225, 3225); + spawn.mapRect(11625, 8375, 225, 1800); + spawn.mapRect(12425, 9825, 225, 875); + spawn.mapRect(13150, 10725, 225, 575); + spawn.mapRect(14125, 10450, 5025, 200); + spawn.mapRect(21775, 10625, 1050, 225); + spawn.mapRect(20325, 10925, 1300, 200); + spawn.mapRect(20825, 10250, 750, 225); + spawn.mapRect(19500, 10000, 1000, 225); + + + ace.slasher2(-22725, 10325); + ace.slasher3(-23425, 10250); + ace.slasher2(-23350, 10700); + ace.slasher3(-21725, 11075); + ace.slasher2(-21525, 10025); + ace.slasher3(-20950, 9750); + ace.slasher2(-19975, 9700); + ace.slasher3(-18850, 9650); + ace.slasher2(-18675, 9700); + ace.slasher3(-18250, 9125); + ace.slasher2(-17775, 8925); + ace.slasher3(-16975, 8875); + ace.slasher2(-16475, 9125); + ace.slasher3(-16125, 9275); + ace.slasher2(-15650, 9225); + ace.slasher3(-15200, 9175); + ace.slasher2(-16800, 9325); + ace.slasher3(-17450, 9525); + ace.slasher2(-18375, 9625); + ace.slasher3(-19650, 9375); + ace.slasher2(-20600, 9225); + ace.slasher3(-21625, 9400); + ace.slasher2(-22450, 9775); + ace.slasher3(-22900, 10000); + ace.slasher2(-23275, 9300); + ace.slasher3(-23125, 9150); + ace.slasher2(2800, 9350); + ace.slasher3(4925, 9825); + ace.slasher2(3725, 10525); + ace.slasher3(1850, 10450); + ace.slash(16850, 10075); + spawn.mapVertex(-14325, 11000, "0 0 4000 -2000 10000 -3000 16000 -2000 20000 0"); + + let q = Matter.Bodies.rectangle(7525 + (1100 / 2), 10675 + (150 / 2), 1100, 150, { + density: 0.05, + isNotHoldable: false, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qq = Matter.Bodies.rectangle(7375 + (150 / 2), 10550 + (200 / 2), 150, 200, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqq = Matter.Bodies.rectangle(7450 + (1250 / 2), 10500 + (100 / 2), 1250, 100, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqq = Matter.Bodies.rectangle(8625 + (150 / 2), 10550 + (200 / 2), 150, 200, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqqq = Matter.Bodies.rectangle(7600 + (100 / 2), 10350 + (200 / 2), 100, 200, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqqqq = Matter.Bodies.rectangle(8475 + (100 / 2), 10350 + (200 / 2), 100, 200, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqqqqq = Matter.Bodies.rectangle(7650 + (725 / 2), 10325 + (75 / 2), 725, 75, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqqqqqq = Matter.Bodies.rectangle(8000 + 100, 10200 + (150 / 2), 200, 150, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqqqqqqq = Matter.Bodies.rectangle(6975 + (1125 / 2), 10250 + 25, 1125, 50, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqqqqqqqq = Matter.Bodies.rectangle(7600 + 50, 10575 + (125 / 2), 100, 125, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqqqqqqqqq = Matter.Bodies.rectangle(8475 + 50, 10575 + (125 / 2), 100, 125, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + let qqqqqqqqqqqq = Matter.Bodies.rectangle(8025 + 50, 10575 + (125 / 2), 100, 125, { + density: 0.05, + isNotHoldable: true, + restitution: 1.05, + isStatic: false + }, true, [true], 0); + + + wasd = Matter.Body.create({ + parts: [q, qq, qqq, qqqq, qqqqq, qqqqqq, qqqqqqq, qqqqqqqq, qqqqqqqqq, qqqqqqqqqq, qqqqqqqqqqq, qqqqqqqqqqqq] + }); + + body[body.length] = q; + body[body.length] = qq; + body[body.length] = qqq; + body[body.length] = qqqq; + body[body.length] = qqqqq; + body[body.length] = qqqqqq; + body[body.length] = qqqqqqq; + body[body.length] = qqqqqqqq; + body[body.length] = qqqqqqqqq; + body[body.length] = qqqqqqqqqq; + body[body.length] = qqqqqqqqqqq; + body[body.length] = qqqqqqqqqqqq; + // body[body.length] = wasd; + + Matter.Composite.add(engine.world, wasd) + composite[composite.length] = wasd; + // wasd.friction -= 0.5 + setTimeout(function () { + wasd.collisionFilter.category = cat.map; + wasd.collisionFilter.mask = cat.body | cat.player | cat.bullet | cat.mobBullet | cat.mob | cat.map + }, 100); + let Vx = 0; + var gradient = ctx.createLinearGradient(0, 0, 10975 / 2, 0); + gradient.addColorStop(0, "#00000000"); + gradient.addColorStop(1, "#686868"); + level.custom = () => { + wasd.force.y += simulation.g * wasd.mass; + if (Matter.Query.collides(wasd, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && input.down && isDestroyed) { + wasd.force.x += Math.cos(m.angle) * 75; + Matter.Body.setVelocity(player, wasd.velocity) + m.Vx = player.velocity.x - wasd.velocity.x; + } + for (let i = 0; i < mob.length; i++) { + if (Matter.Query.collides(wasd, [mob[i]]).length > 0 && !mob[i].isBoss && isDestroyed) { + const dmg = 1; + mob[i].damage(dmg, true); + simulation.drawList.push({ //add dmg to draw queue + x: mob[i].position.x, + y: mob[i].position.y, + radius: Math.sqrt(dmg) * 50, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + break + } + } + Vx = wasd.velocity.x / 5; + level.exit.drawAndCheck(); + drawSeats(475, -50, 5600, 125, 20, "darkgray"); + door.openClose() + door2.openClose() + if (player.position.y < 25) { + door.isClosing = false; + door2.isClosing = false; + } else { + door.isClosing = true; + door2.isClosing = true; + } + ctx.fillStyle = "red"; + ctx.fillRect(-825, -75, 50, 50); + + b.pulse(30, 0, { x: -2500, y: (25 + (25 / 2)) }); + ctx.save() + ctx.translate(11750, 8475) + ctx.fillStyle = gradient; + ctx.fillRect(0, 0, 10975, 2800); + ctx.restore() + drawHead(7400, 0, Math.PI * 0.1); + drawHead(7460, 0, Math.PI * 0.5); + drawHead(7520, 0, Math.PI * 0.3); + drawHead(22400, 11125, Math.PI * 0.3); + drawHead(21925, 10625, Math.PI * 0.5); + drawHead(21175, 10250, Math.PI * 0.1); + drawHead(22525, 10625, Math.PI * 0.7); + drawHead(22525, 11125, Math.PI * 0.9); + drawHead(22225, 11125, Math.PI * 1.5); + }; + level.customTopLayer = () => { + drawSeats(500, -50, 5600, 125); + + ctx.strokeStyle = 'red'; + ctx.lineWidth = 20; + ctx.beginPath(); + ctx.setLineDash([40, 40]); + ctx.lineDashOffset = (-simulation.cycle * Vx) % 80; + + ctx.moveTo(q.vertices[0].x, q.vertices[0].y); + for (let i = 1; i < q.vertices.length; i++) { + ctx.lineTo(q.vertices[i].x, q.vertices[i].y); + } + ctx.lineTo(q.vertices[0].x, q.vertices[0].y); + ctx.closePath(); + ctx.stroke(); + ctx.setLineDash([0, 0]); + }; + function drawSeats(x, y, w, h, num = 20, c = "gray") { + const seatWidth = w / num; + const seatHeight = h / num; + + for (let i = 0; i < num; i++) { + const seatX = x + i * seatWidth; + const seatY = y; + + // Draw the seat parts + ctx.fillStyle = c; + ctx.fillRect(seatX - 100, seatY, 125, 25); + ctx.fillRect(seatX, seatY - 125, 25, 150); + ctx.fillRect(seatX - 75, seatY, 25, 75); + ctx.fillRect(seatX - 25, seatY, 25, 75); + } + } + function drawHead(x, y, angle) { + ctx.save(); + ctx.translate(x, y - 30); + ctx.rotate(angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + } + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isSlashBoss) { + simulation.ephemera.push({ + name: "bossBar", + do() { + if (level.levels[level.onLevel] == "ace" && !isDestroyed) { + ctx.save(); + ctx.setTransform(1, 0, -0.5, 1, 0, 0); //slanted + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(canvas.width2 / 2, canvas.height2 / 10, canvas.width2, 30); + ctx.fillStyle = "rgba(0,0,0,0.7)"; + ctx.fillRect(canvas.width2 / 2, canvas.height2 / 10, canvas.width2 * mob[i].health, 30); + ctx.restore(); + } + }, + }) + } + } + }, + crimsonTowers() { + simulation.inGameConsole(`crimsonTowers by Richard0820. Thank you desboot for the video: Source`) + const ace = { + spawnOrbitals(who, radius, chance = Math.min(0.25 + simulation.difficulty * 0.005)) { + if (Math.random() < chance) { + const len = Math.floor(Math.min(15, 3 + Math.sqrt(simulation.difficulty))) + const speed = (0.003 + 0.004 * Math.random() + 0.002 * Math.sqrt(simulation.difficulty)) * ((Math.random() < 0.5) ? 1 : -1) + const offSet = 6.28 * Math.random() + for (let i = 0; i < len; i++) ace.orbital(who, radius, i / len * 2 * Math.PI + offSet, speed) + } + }, + orbital(who, radius, phase, speed) { + // for (let i = 0, len = 7; i < len; i++) spawn.orbital(me, radius + 250, 2 * Math.PI / len * i) + mobs.spawn(who.position.x, who.position.y, 8, 12, "rgb(0,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.01); //normal is 0.001 + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isUnstable = true; //dies when blocked + me.showHealthBar = false; + me.isOrbital = true; + // me.isShielded = true + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet; //cat.player | cat.map | cat.body + me.do = function () { + //if host is gone + if (!who || !who.alive) { + this.death(); + return + } + //set orbit + const time = simulation.cycle * speed + phase + const orbit = { + x: Math.cos(time), + y: Math.sin(time) + } + Matter.Body.setPosition(this, Vector.add(Vector.add(who.position, who.velocity), Vector.mult(orbit, radius))) + //damage player + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + const dmg = 0.03 * simulation.dmgScale + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + this.death(); + } + }; + }, + shield(target, x, y, chance = Math.min(0.02 + simulation.difficulty * 0.005, 0.2) + tech.duplicationChance()) { + if (this.allowShields && Math.random() < chance) { + mobs.spawn(x, y, 9, target.radius + 30, "rgba(255,255,255,0.9)"); + let me = mob[mob.length - 1]; + me.stroke = "rgb(0,0,0)"; + Matter.Body.setDensity(me, 0.00001) //very low density to not mess with the original mob's motion + me.shield = true; + me.damageReduction = 0.05 + me.isUnblockable = true + me.collisionFilter.category = cat.mobShield + me.collisionFilter.mask = cat.bullet; + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: target, //attach shield to target + stiffness: 0.4, + damping: 0.1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + + me.onDamage = function () { + //make sure the mob that owns the shield can tell when damage is done + this.alertNearByMobs(); + this.fill = `rgba(255,255,255,${0.3 + 0.6 * this.health})` + }; + me.leaveBody = false; + me.isDropPowerUp = false; + me.showHealthBar = false; + + me.shieldTargetID = target.id + target.isShielded = true; + if (target.shieldCount > 0) { + target.shieldCount++ + } else { + target.shieldCount = 1 + } + me.shieldCount = target.shieldCount //used with "bubble fusion" + target.shieldID = me.id + me.onDeath = function () { + //clear isShielded status from target + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].id === this.shieldTargetID) mob[i].isShielded = false; + } + }; + me.do = function () { + this.checkStatus(); + }; + + mob.unshift(me); //move shield to the front of the array, so that mob is behind shield graphically + + //swap order of shield and mob, so that mob is behind shield graphically + // mob[mob.length - 1] = mob[mob.length - 2]; + // mob[mob.length - 2] = me; + } + }, + groupShield(targets, x, y, radius, stiffness = 0.4) { + const nodes = targets.length + mobs.spawn(x, y, 9, radius, "rgba(255,255,255,0.9)"); + let me = mob[mob.length - 1]; + me.stroke = "rgb(0,0,0)"; + Matter.Body.setDensity(me, 0.00001) //very low density to not mess with the original mob's motion + me.frictionAir = 0; + me.shield = true; + me.damageReduction = 0.075 + me.collisionFilter.category = cat.mobShield + me.collisionFilter.mask = cat.bullet; + for (let i = 0; i < nodes; ++i) { + mob[mob.length - i - 2].isShielded = true; + //constrain to all mob nodes in group + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: mob[mob.length - i - 2], + stiffness: stiffness, + damping: 0.1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + me.onDamage = function () { + this.alertNearByMobs(); //makes sure the mob that owns the shield can tell when damage is done + this.fill = `rgba(255,255,255,${0.3 + 0.6 * this.health})` + }; + me.onDeath = function () { + //clear isShielded status from target + for (let j = 0; j < targets.length; j++) { + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].id === targets[j]) mob[i].isShielded = false; + } + } + }; + me.leaveBody = false; + me.isDropPowerUp = false; + me.showHealthBar = false; + mob[mob.length - 1] = mob[mob.length - 1 - nodes]; + mob[mob.length - 1 - nodes] = me; + me.do = function () { + this.checkStatus(); + }; + }, + slasher2(x, y, radius = 33 + Math.ceil(Math.random() * 30)) { + mobs.spawn(x, y, 6, radius, "rgb(0,0,0)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.0009 * simulation.accelScale; + me.torqueMagnitude = 0.000012 * me.inertia //* (Math.random() > 0.5 ? -1 : 1); + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.035; + me.delay = 140 * simulation.CDScale; + me.cd = 0; + me.swordRadius = 0; + me.swordVertex = 1 + me.swordRadiusMax = 275 + 3.5 * simulation.difficulty; + me.swordRadiusGrowRate = me.swordRadiusMax * (0.011 + 0.0002 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.03 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + const seeDistance2 = 200000 + ace.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.checkStatus(); + this.seePlayerByHistory(15); + this.attraction(); + this.sword() //does various things depending on what stage of the sword swing + }; + me.swordWaiting = function () { + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + this.laserAngle = -Math.PI / 6 + this.sword = this.swordGrow + this.accelMag = 0 + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + this.laserSword(this.vertices[0], this.angle + this.laserAngle); + this.laserSword(this.vertices[1], this.angle + this.laserAngle + (Math.PI / 3)); + this.laserSword(this.vertices[2], this.angle + this.laserAngle + (Math.PI * 2 / 3)); + this.laserSword(this.vertices[3], this.angle + this.laserAngle + Math.PI); + this.laserSword(this.vertices[4], this.angle + this.laserAngle + (Math.PI * 4 / 3)); + this.laserSword(this.vertices[5], this.angle + this.laserAngle + (Math.PI * 5 / 3)); + this.swordRadius += this.swordRadiusGrowRate + if (this.swordRadius > this.swordRadiusMax || this.isStunned) { + this.sword = this.swordSlash + this.spinCount = 0 + } + } + me.swordSlash = function () { + this.laserSword(this.vertices[0], this.angle + this.laserAngle); + this.laserSword(this.vertices[1], this.angle + this.laserAngle + (Math.PI / 3)); + this.laserSword(this.vertices[2], this.angle + this.laserAngle + (Math.PI * 2 / 3)); + this.laserSword(this.vertices[3], this.angle + this.laserAngle + Math.PI); + this.laserSword(this.vertices[4], this.angle + this.laserAngle + (Math.PI * 4 / 3)); + this.laserSword(this.vertices[5], this.angle + this.laserAngle + (Math.PI * 5 / 3)); + + this.torque += this.torqueMagnitude; + this.spinCount++ + if (this.spinCount > 100 || this.isStunned) { + this.sword = this.swordWaiting + this.swordRadius = 0 + this.accelMag = 0.001 * simulation.accelScale; + this.cd = simulation.cycle + this.delay; + } + } + me.laserSword = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let v = domain[i].vertices; + const len = v.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, v[j], v[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[j], v2: v[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, v[0], v[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[0], v2: v[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [playerBody, playerHead]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(0,0,0,0.1)"; // 0 path + ctx.lineWidth = 15; + ctx.stroke(); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; // 0 path + ctx.lineWidth = 4; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + slasher3(x, y, radius = 33 + Math.ceil(Math.random() * 30)) { + const sides = 6 + mobs.spawn(x, y, sides, radius, "rgb(0,0,0)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.0005 * simulation.accelScale; + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.02; + me.delay = 150 * simulation.CDScale; + me.cd = 0; + me.cycle = 0; + me.swordVertex = 1 + me.swordRadiusInitial = radius / 2; + me.swordRadius = me.swordRadiusInitial; + me.swordRadiusMax = 750 + 6 * simulation.difficulty; + me.swordRadiusGrowRateInitial = 1.08 + me.swordRadiusGrowRate = me.swordRadiusGrowRateInitial//me.swordRadiusMax * (0.009 + 0.0002 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.04 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + const seeDistance2 = me.swordRadiusMax * me.swordRadiusMax + ace.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.checkStatus(); + this.seePlayerByHistory(15); + this.sword() //does various things depending on what stage of the sword swing + }; + me.swordWaiting = function () { + this.attraction(); + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + //find vertex closest to the player + let dist = Infinity + for (let i = 0, len = this.vertices.length; i < len; i++) { + const D = Vector.magnitudeSquared(Vector.sub({ x: this.vertices[i].x, y: this.vertices[i].y }, m.pos)) + if (D < dist) { + dist = D + this.swordVertex = i + } + } + this.laserAngle = this.swordVertex / sides * 2 * Math.PI + Math.PI / sides + this.sword = this.swordGrow + this.cycle = 0 + this.swordRadius = this.swordRadiusInitial + //slow velocity but don't stop + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.5)) + //set angular velocity to 50% + // Matter.Body.setAngularVelocity(this, this.angularVelocity * 0.5) + //gently rotate towards the player with a torque, use cross product to decided clockwise or counterclockwise + const laserStartVector = Vector.sub(this.position, this.vertices[this.swordVertex]) + const playerVector = Vector.sub(this.position, m.pos) + const cross = Matter.Vector.cross(laserStartVector, playerVector) + this.torque = 0.00002 * this.inertia * (cross > 0 ? 1 : -1) + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + const angle = this.angle + this.laserAngle; + const end = { + x: this.vertices[this.swordVertex].x + this.swordRadiusMax * Math.cos(angle), + y: this.vertices[this.swordVertex].y + this.swordRadiusMax * Math.sin(angle) + }; + + const dx = end.x - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].x; + const dy = end.y - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].y; + const angle1 = Math.atan2(dy, dx) * (180 / Math.PI); + + const dx1 = end.x - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].x; + const dy1 = end.y - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].y; + const angle2 = Math.atan2(dy1, dx1) * (180 / Math.PI); + + this.laserSpear(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.laserSpear(this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1], angle1 * (Math.PI / 180)) + this.laserSpear(this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1], angle2 * (Math.PI / 180)) + + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.9)) + // this.swordRadius += this.swordRadiusGrowRate + this.cycle++ + // this.swordRadius = this.swordRadiusMax * Math.sin(this.cycle * 0.03) + this.swordRadius *= this.swordRadiusGrowRate + + if (this.swordRadius > this.swordRadiusMax) this.swordRadiusGrowRate = 1 / this.swordRadiusGrowRateInitial + // if (this.swordRadius > this.swordRadiusMax) this.swordRadiusGrowRate = -Math.abs(this.swordRadiusGrowRate) + if (this.swordRadius < this.swordRadiusInitial || this.isStunned) { + // this.swordRadiusGrowRate = Math.abs(this.swordRadiusGrowRate) + this.swordRadiusGrowRate = this.swordRadiusGrowRateInitial + this.sword = this.swordWaiting + this.swordRadius = 0 + this.cd = simulation.cycle + this.delay; + } + } + me.laserSpear = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let v = domain[i].vertices; + const len = v.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, v[j], v[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[j], v2: v[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, v[0], v[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[0], v2: v[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [playerBody, playerHead]); + if (best.who && (best.who === playerBody || best.who === playerHead)) { + this.swordRadiusGrowRate = 1 / this.swordRadiusGrowRateInitial //!!!! this retracts the sword if it hits the player + + if (m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(0,0,0,0.1)"; // 0 path + ctx.lineWidth = 15; + ctx.stroke(); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; // 0 path + ctx.lineWidth = 4; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + stabber(x, y, radius = 25 + Math.ceil(Math.random() * 12), spikeMax = 7) { + if (radius > 80) radius = 65; + mobs.spawn(x, y, 6, radius, "rgb(0,0,0)"); //can't have sides above 6 or collision events don't work (probably because of a convex problem) + let me = mob[mob.length - 1]; + me.isVerticesChange = true + me.accelMag = 0.0006 * simulation.accelScale; + // me.g = 0.0002; //required if using this.gravity + me.isInvulnerable = false + me.delay = 360 * simulation.CDScale; + me.spikeVertex = 0; + me.spikeLength = 0; + me.isSpikeGrowing = false; + me.spikeGrowth = 0; + me.isSpikeReset = true; + me.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.player //can't touch other mobs + Matter.Body.rotate(me, Math.PI * 0.1); + ace.shield(me, x, y); + // me.onDamage = function () {}; + // me.onHit = function() { //run this function on hitting player + // }; + me.onDeath = function () { + if (this.spikeLength > 4) { + this.spikeLength = 4 + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[this.spikeVertex], this.position)), this.radius * this.spikeLength) + this.vertices[this.spikeVertex].x = this.position.x + spike.x + this.vertices[this.spikeVertex].y = this.position.y + spike.y + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) + } + }; + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + if (this.isSpikeReset) { + if (this.seePlayer.recall) { + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + if (distMag < radius * spikeMax) { + //find nearest vertex + let nearestDistance = Infinity + for (let i = 0, len = this.vertices.length; i < len; i++) { + //find distance to player for each vertex + const dist = Vector.sub(this.seePlayer.position, this.vertices[i]); + const distMag = Vector.magnitude(dist); + //save the closest distance + if (distMag < nearestDistance) { + this.spikeVertex = i + nearestDistance = distMag + } + } + this.spikeLength = 1 + this.isSpikeGrowing = true; + this.isSpikeReset = false; + Matter.Body.setAngularVelocity(this, 0) + } + me.isInvulnerable = false + } + } else { + if (this.isSpikeGrowing) { + this.spikeLength += Math.pow(this.spikeGrowth += 0.02, 8) + // if (this.spikeLength < 2) { + // this.spikeLength += 0.035 + // } else { + // this.spikeLength += 1 + // } + if (this.spikeLength > spikeMax) { + this.isSpikeGrowing = false; + this.spikeGrowth = 0 + } + } else { + Matter.Body.setAngularVelocity(this, this.angularVelocity * 0.8) //reduce rotation + this.spikeLength -= 0.3 + if (this.spikeLength < 1) { + this.spikeLength = 1 + this.isSpikeReset = true + this.radius = radius + } + } + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[this.spikeVertex], this.position)), radius * this.spikeLength) + this.vertices[this.spikeVertex].x = this.position.x + spike.x + this.vertices[this.spikeVertex].y = this.position.y + spike.y + me.isInvulnerable = true + // this.radius = radius * this.spikeLength; + } + if (this.isInvulnerable) { + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + me.damageReduction = 0; + } else { + me.damageReduction = 1; + } + }; + }, + slash(x, y, radius = 80) { + let targets = [] + const sides = 6; + mobs.spawn(x, y, 6, radius, "#000000"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + targets.push(me.id) //add to shield protection + const nodeBalance = Math.random() + const nodes2 = Math.min(15, Math.floor(2 + 4 * nodeBalance + 0.75 * Math.sqrt(simulation.difficulty))) + me.isBoss = true; + me.isSlashBoss = true; + me.showHealthBar = false; + me.damageReduction = 0.1 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.frictionAir = 0.02 + me.seeAtDistance2 = 1000000; + me.accelMag = 0.0004 + 0.00015 * simulation.accelScale; + Matter.Body.setDensity(me, 0.0005); //normal is 0.001 + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map + me.memory = Infinity; + me.seePlayerFreq = 20 + me.lockedOn = null; + me.laserRange = 500; + me.torqueMagnitude = 0.00024 * me.inertia * (Math.random() > 0.5 ? -1 : 1); + me.delay = 70 + 70 * simulation.CDScale; + me.cd = 0; + me.swordRadius = 0; + me.swordVertex = 1 + me.swordRadiusMax = 1100 + 20 * simulation.difficulty; + me.swordRadiusGrowRate = me.swordRadiusMax * (0.005 + 0.0003 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.07 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + me.eventHorizon = 550; + const seeDistance2 = 200000 + ace.shield(me, x, y); + const rangeInnerVsOuter = Math.random() + let speed = (0.006 + 0.001 * Math.sqrt(simulation.difficulty)) * ((Math.random() < 0.5) ? 1 : -1) + let range = radius + 350 + 200 * rangeInnerVsOuter + nodes2 * 7 + for (let i = 0; i < nodes2; i++) ace.orbital(me, range, i / nodes2 * 2 * Math.PI, speed) + const orbitalIndexes = [] //find indexes for all the current nodes2 + for (let i = 0; i < nodes2; i++) orbitalIndexes.push(mob.length - 1 - i) + // add orbitals for each orbital + range = Math.max(60, 100 + 100 * Math.random() - nodes2 * 3 - rangeInnerVsOuter * 80) + speed = speed * (1.25 + 2 * Math.random()) + const subNodes = Math.max(2, Math.floor(6 - 5 * nodeBalance + 0.5 * Math.sqrt(simulation.difficulty))) + for (let j = 0; j < nodes2; j++) { + for (let i = 0, len = subNodes; i < len; i++) ace.orbital(mob[orbitalIndexes[j]], range, i / len * 2 * Math.PI, speed) + } + for (let i = 0, len = 3 + 0.5 * Math.sqrt(simulation.difficulty); i < len; i++) ace.spawnOrbitals(me, radius + 40 + 10 * i, 1); + + const springStiffness = 0.00014; + const springDampening = 0.0005; + + me.springTarget = { + x: me.position.x, + y: me.position.y + }; + const len = cons.length; + cons[len] = Constraint.create({ + pointA: me.springTarget, + bodyB: me, + stiffness: springStiffness, + damping: springDampening + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len].length = 100 + 1.5 * radius; + me.cons = cons[len]; + + me.springTarget2 = { + x: me.position.x, + y: me.position.y + }; + const len2 = cons.length; + cons[len2] = Constraint.create({ + pointA: me.springTarget2, + bodyB: me, + stiffness: springStiffness, + damping: springDampening, + length: 0 + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len2].length = 100 + 1.5 * radius; + me.cons2 = cons[len2]; + me.onDamage = function () { }; + me.onDeath = function () { + isDestroyed = true; + this.removeCons(); + powerUps.spawnBossPowerUp(this.position.x, this.position.y); + }; + me.do = function () { + for (let i = 0; i < this.vertices.length; i++) { + this.harmField(this.vertices[i].x, this.vertices[i].y); + } + this.seePlayerByHistory(40); + this.springAttack(); + this.checkStatus(); + this.sword() //does various things depending on what stage of the sword swing + const eventHorizon = this.eventHorizon * (1 + 0.2 * Math.sin(simulation.cycle * 0.008)) + me.laserRange = eventHorizon; + }; + me.swordWaiting = function () { + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + !m.isCloak && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + //find vertex farthest away from player + let dist = 0 + for (let i = 0, len = this.vertices.length; i < len; i++) { + const D = Vector.magnitudeSquared(Vector.sub({ x: this.vertices[i].x, y: this.vertices[i].y }, m.pos)) + if (D > dist) { + dist = D + this.swordVertex = i + } + } + this.laserAngle = this.swordVertex / 6 * 2 * Math.PI + 0.6283 + this.sword = this.swordGrow + Matter.Body.setAngularVelocity(this, 0) + this.accelMag = 0.0004 + 0.00015 * simulation.accelScale; + this.damageReduction = 0 + this.isInvulnerable = true + this.frictionAir = 1 + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + const angle = this.angle + this.laserAngle; + const end = { + x: this.vertices[this.swordVertex].x + this.swordRadiusMax * Math.cos(angle), + y: this.vertices[this.swordVertex].y + this.swordRadiusMax * Math.sin(angle) + }; + + const dx = end.x - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].x; + const dy = end.y - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].y; + const angle1 = Math.atan2(dy, dx) * (180 / Math.PI); + + const dx1 = end.x - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].x; + const dy1 = end.y - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].y; + const angle2 = Math.atan2(dy1, dx1) * (180 / Math.PI); + + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.laserSword(this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1], angle1 * (Math.PI / 180)) + this.laserSword(this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1], angle2 * (Math.PI / 180)) + this.swordRadius += this.swordRadiusGrowRate + if (this.swordRadius > this.swordRadiusMax) { + this.sword = this.swordSlash + this.spinCount = 0 + } + + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + me.swordSlash = function () { + const angle = this.angle + this.laserAngle; + const end = { + x: this.vertices[this.swordVertex].x + this.swordRadiusMax * Math.cos(angle), + y: this.vertices[this.swordVertex].y + this.swordRadiusMax * Math.sin(angle) + }; + + const dx = end.x - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].x; + const dy = end.y - this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1].y; + const angle1 = Math.atan2(dy, dx) * (180 / Math.PI); + + const dx1 = end.x - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].x; + const dy1 = end.y - this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1].y; + const angle2 = Math.atan2(dy1, dx1) * (180 / Math.PI); + + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.laserSword(this.vertices[this.swordVertex + 1 > (sides - 1) ? 0 : this.swordVertex + 1], angle1 * (Math.PI / 180)) + this.laserSword(this.vertices[this.swordVertex - 1 < 0 ? (sides - 1) : this.swordVertex - 1], angle2 * (Math.PI / 180)) + this.torque += this.torqueMagnitude; + this.spinCount++ + if (this.spinCount > 80) { + this.sword = this.swordWaiting + this.swordRadius = 0 + this.accelMag = 0.0004 + 0.00015 * simulation.accelScale; + this.cd = simulation.cycle + this.delay; + this.damageReduction = this.startingDamageReduction + this.isInvulnerable = false + this.frictionAir = 0.01 + } + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + me.laserSword = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let v = domain[i].vertices; + const len = v.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, v[j], v[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[j], v2: v[j + 1] }; + } + } + results = simulation.checkLineIntersection(v1, v1End, v[0], v[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { x: results.x, y: results.y, dist2: dist2, who: domain[i], v1: v[0], v2: v[len] }; + } + } + }; + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + vertexCollision(where, look, body); // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + if (!m.isCloak) vertexCollision(where, look, [playerBody, playerHead]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(0,0,0,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(0,0,0,0.1)"; // Black path + ctx.lineWidth = 25; + ctx.stroke(); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; // Black path + ctx.lineWidth = 5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + me.harmField = function (x, y) { + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + // ctx.lineDashOffset = 6*(simulation.cycle % 215); + if (this.distanceToPlayer3(x, y) < this.laserRange) { + if (m.immuneCycle < m.cycle) { + m.damage(0.0003 * simulation.dmgScale); + if (m.energy > 0.1) m.energy -= 0.003 + } + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineTo(m.pos.x + (Math.random() - 0.5) * 3000, m.pos.y + (Math.random() - 0.5) * 3000); + ctx.lineWidth = 2; + ctx.strokeStyle = "rgb(0,0,0)"; + ctx.stroke(); + + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.15)"; + ctx.fill(); + } + ctx.beginPath(); + ctx.arc(x, y, this.laserRange * 0.9, 0, 2 * Math.PI); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + ctx.lineWidth = 1; + ctx.stroke(); + ctx.setLineDash([]); + ctx.fillStyle = "rgba(0,0,0,0.03)"; + ctx.fill(); + } + me.distanceToPlayer3 = function (x, y) { + const dx = x - player.position.x; + const dy = y - player.position.y; + return Math.sqrt(dx * dx + dy * dy); + } + radius = 22 // radius of each node mob + const sideLength = 100 // distance between each node mob + const nodes = 6 + const angle = 2 * Math.PI / nodes + + spawn.allowShields = false; //don't want shields on individual mobs + + for (let i = 0; i < nodes; ++i) { + ace.stabber(x + sideLength * Math.sin(i * angle), y + sideLength * Math.cos(i * angle), radius, 12); + Matter.Body.setDensity(mob[mob.length - 1], 0.003); //extra dense //normal is 0.001 //makes effective life much larger + mob[mob.length - 1].damageReduction = 0.12 + mob[mob.length - 1].showHealthBar = false; + mob[mob.length - 1].isBoss = true; + targets.push(mob[mob.length - 1].id) //track who is in the node boss, for shields + } + + const attachmentStiffness = 0.02 + spawn.constrain2AdjacentMobs(nodes, attachmentStiffness, true); //loop mobs together + + for (let i = 0; i < nodes; ++i) { //attach to center mob + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: mob[mob.length - i - 1], + stiffness: attachmentStiffness, + damping: 0.03 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + //spawn shield around all nodes + ace.groupShield(targets, x, y, sideLength + 1 * radius + nodes * 5 - 25); + spawn.allowShields = true; + }, + } + level.setPosToSpawn(0, -50); + color.map = "crimson"; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + spawn.mapRect(0, 0, 1, 1); + level.defaultZoom = 1800; + simulation.zoomTransition(level.defaultZoom); + document.body.style.backgroundColor = "#d8dadf"; + const isSus = Math.random() < 0.001; //A very lucky person gets rickrolled + const mediaSource = isSus ? "https://ia801509.us.archive.org/10/items/Rick_Astley_Never_Gonna_Give_You_Up/Rick_Astley_Never_Gonna_Give_You_Up.ogv" : "https://cdn.glitch.me/b559a783-c0cb-4369-92e3-0c0a5556ba01/n-gon%20evangelion%20-%20Made%20with%20Clipchamp%20(8).mp4?v=1692134040246" + let videoContainer; + let video = document.createElement("video"); + video.src = mediaSource; + video.autoPlay = true; + video.loop = true; + video.muted = true; + videoContainer = { + video: video, + ready: true, + }; + video.play(); + const boost1 = level.boost(8835, -3675, 7500); + const boost2 = level.boost(-8935, -3675, 7500); + ace.slash(0, -15000 + 1800); + function Raindrop(minX, minY, maxX, maxY) { + this.x = minX + Math.random() * (maxX - minX); + this.y = minY + Math.random() * (maxY - minY); + this.speed = Math.random() * 5 + 25; + this.length = Math.random() * 20 + 30; + } + function forceField(x, y, width, height) { + return { + min: { x: x, y: y }, + max: { x: x + width, y: y + height }, + width: width, + height: height, + maxHeight: height, + raindrops: [], + drawRaindrop(drop) { + if (Math.sqrt(Math.pow(player.position.x - drop.x, 2) + Math.pow(player.position.y - drop.y, 2)) + Math.PI < 5000) { + ctx.beginPath(); + ctx.moveTo(drop.x, drop.y); + ctx.lineTo(drop.x, drop.y + drop.length); + ctx.strokeStyle = '#00FFFF'; + ctx.lineWidth = 10; + ctx.lineCap = 'butt'; + ctx.stroke(); + } + }, + updateRaindrop(drop) { + drop.y += drop.speed; + if ((Matter.Query.ray(map, { x: drop.x, y: drop.y }, { x: drop.x, y: drop.y - drop.length }).length === 0) == false) { + simulation.drawList.push({ + x: drop.x, + y: drop.y - drop.length, + radius: 10, + color: "rgb(0,100,250,0.3)", + time: 8 + }); + do { + drop.y = this.min.y + this.height * Math.random(); + drop.x = this.min.x + this.width * Math.random(); + } while (drop.x > this.min.x && drop.x < this.max.x && drop.y > this.min.y && drop.y < this.max.y) + } + }, + isOn: true, + query() { + if (this.isOn) { + ctx.fillStyle = `rgba(200, 20, 10, 0.55)` + ctx.fillRect(this.min.x, this.min.y, this.width, this.height) + if (this.height > 0 && Matter.Query.region([player], this).length) { + player.force.y -= 0.015; + m.energy = m.maxEnergy; + } + // if(this.raindrops.length < 300) { // too many (like 900) can cause a little bit of lag minus 5 ~ 10 fps, but it really just depends on your computer + // this.raindrops.push(new Raindrop()); + // } + // for (let i = 0; i < this.raindrops.length; i++) { + // const drop = this.raindrops[i]; + // this.drawRaindrop(drop); + // this.updateRaindrop(drop); + // } + } + }, + } + } + const forceField1 = forceField(-750, -30000, 1500, 20000); + level.custom = () => { + if (player.position.y < -20000) { + level.nextLevel(); + } + forceField1.query(); + boost1.query(); + boost2.query(); + level.exit.drawAndCheck(); + level.enter.draw(); + ctx.beginPath(); + ctx.strokeStyle = "rgba(220, 20, 10, 0.55)"; + ctx.lineWidth = 1500; + ctx.lineJoin = "miter" + ctx.miterLimit = 100; + ctx.moveTo(map[272].vertices[0].x, map[272].vertices[0].y); + for (let i = 0; i < map[272].vertices.length; i++) { + ctx.lineTo(map[272].vertices[i].x, map[272].vertices[i].y); + } + ctx.closePath(); + ctx.stroke(); + }; + let checkVid = () => { + if (simulation.paused && !videoContainer.paused) { + videoContainer.paused = true; + video.pause(); + } else if (!simulation.paused && videoContainer.paused) { + videoContainer.paused = false; + video.play(); + } + requestAnimationFrame(checkVid); + } + checkVid(); + simulation.ephemera.push({ + name: "vid", + do() { + if (level.levels[level.onLevel] !== "crimsonTowers") simulation.removeEphemera(this.name); + if (mediaSource && !isSus) { + ctx.drawImage(videoContainer.video, -1600, -15000, 3200, 1800); + } else if (mediaSource) { + ctx.drawImage(videoContainer.video, -1920 / 2, -15000, 1920, 1080); + } + } + }); + level.customTopLayer = () => { + ctx.fillStyle = "rgba(220, 20, 10, 0.1)"; + ctx.fillRect(-6725, -3500, 475, 2925); + ctx.fillRect(-8725, -3700, 450, 2925); + ctx.fillRect(-4725, -3300, 450, 2925); + ctx.fillRect(-2725, -3100, 450, 2925); + ctx.fillRect(-725, -2900, 450, 2925); + ctx.fillRect(275, -2900, 450, 2925); + ctx.fillRect(2275, -3100, 450, 2925); + ctx.fillRect(4275, -3300, 450, 2925); + ctx.fillRect(6275, -3500, 450, 2925); + ctx.fillRect(8275, -3700, 450, 2925); + }; + spawn.mapRect(-10000, 0, 20000, 2000); + spawn.mapRect(-9050, -3650, 350, 50); + spawn.mapRect(8700, -3650, 350, 50); + spawn.mapRect(-275, -2825, 550, 50); + spawn.mapRect(-225, -500, 450, 50); + spawn.mapRect(-250, -1575, 500, 50); + function spawnTower(index, y = 0) { + const x = index - 1325; + spawn.mapRect(x + 1025, y + -950, 125, 750); + spawn.mapRect(x + 1125, y + -225, 50, 50); + spawn.mapRect(x + 1500, y + -950, 125, 750); + spawn.mapRect(x + 1475, y + -225, 50, 50); + spawn.mapRect(x + 1600, y + -225, 50, 50); + spawn.mapRect(x + 1000, y + -225, 50, 50); + spawn.mapRect(x + 1475, y + -475, 50, 50); + spawn.mapRect(x + 1125, y + -750, 50, 50); + spawn.mapRect(x + 1050, y + -2025, 100, 1125); + spawn.mapRect(x + 1500, y + -2025, 100, 1125); + spawn.mapRect(x + 1475, y + -1050, 50, 50); + spawn.mapRect(x + 1125, y + -1325, 50, 50); + spawn.mapRect(x + 1475, y + -1550, 50, 50); + spawn.mapRect(x + 1125, y + -1875, 50, 50); + spawn.mapRect(x + 1075, y + -2900, 75, 925); + spawn.mapRect(x + 1500, y + -2900, 75, 925); + spawn.mapRect(x + 1475, y + -2150, 50, 50); + spawn.mapRect(x + 1125, y + -2475, 50, 50); + spawn.mapRect(x + 1475, y + -2800, 50, 50); + spawn.mapRect(x + 1000, y + -975, 50, 50); + spawn.mapRect(x + 1025, y + -2050, 50, 50); + spawn.mapRect(x + 1050, y + -2925, 50, 50); + spawn.mapRect(x + 1550, y + -2925, 50, 50); + spawn.mapRect(x + 1600, y + -975, 50, 50); + spawn.mapRect(x + 1575, y + -2050, 50, 50); + for (let i = 0; i < 5; i++) { + if (Math.random() > 0.5) { ace.slasher2(index, y - (i * 500) - 500) } else { ace.slasher3(index, y - (i * 500) - 500) }; + } + } + // ace.slash(0, -5000); + function spawnChain(x, y, x1, y1, length = 39) { + const angle = Math.atan2(y1 - y, x1 - x); + chain(x, y, angle, true, length); + } + function chain(x, y, angle = 0, isAttached = true, len = 15, radius = 20, stiffness = 1, damping = 1) { + const gap = 2 * radius + const unit = { + x: Math.cos(angle), + y: Math.sin(angle) + } + for (let i = 0; i < len; i++) { + bullet[bullet.length] = Bodies.polygon(x + gap * unit.x * i, y + gap * unit.y * i, 12, radius, { + inertia: Infinity, + isNotHoldable: true + }); + const who = bullet[bullet.length - 1]; + who.do = () => { }; + who.collisionFilter.category = cat.body; + who.collisionFilter.mask = cat.player | cat.bullet | cat.body | cat.bullet | cat.bullet | cat.bulletBullet + Composite.add(engine.world, who); //add to world + who.classType = "bullet" + } + for (let i = 1; i < len; i++) { + consBB[consBB.length] = Constraint.create({ + bodyA: bullet[bullet.length - i], + bodyB: bullet[bullet.length - i - 1], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + cons[cons.length] = Constraint.create({ + pointA: { + x: x, + y: y + }, + bodyB: bullet[bullet.length - len], + stiffness: 1, + damping: damping + }); + Composite.add(engine.world, cons[cons.length - 1]); + if (isAttached) { + cons[cons.length] = Constraint.create({ + pointA: { + x: x + gap * unit.x * (len - 1), + y: y + gap * unit.y * (len - 1) + }, + bodyB: bullet[bullet.length - 1], + stiffness: 1, + damping: damping + }); + Composite.add(engine.world, cons[cons.length - 1]); + } + } + spawnChain(-2250, -3100, -750, -2900); + spawnChain(-4250, -3300, -2750, -3100); + spawnChain(-6250, -3500, -4750, -3300); + spawnChain(-8250, -3700, -6750, -3500); + spawnChain(750, -2900, 2250, -3100); + spawnChain(2750, -3100, 4250, -3300); + spawnChain(4750, -3300, 6250, -3500); + spawnChain(6750, -3500, 8250, -3700); + // spawnChain(-3000, -30000, -9500, -20400, 291); + // spawnChain(3000, -30000, 9500, -20400, 291); + spawnTower(500); + spawnTower(2500, -200); + spawn.mapRect(2000, -200, 7000, 300); + spawnTower(4500, -400); + spawn.mapRect(4000, -400, 5000, 300); + spawnTower(6500, -600); + spawn.mapRect(6000, -600, 5000, 300); + spawnTower(8500, -800); + spawn.mapRect(8000, -800, 3000, 300); + spawnTower(-500); + spawnTower(-2500, -200); + spawn.mapRect(-10000, -200, 8000, 300); + spawnTower(-4500, -400); + spawn.mapRect(-10000, -400, 6000, 300); + spawnTower(-6500, -600); + spawn.mapRect(-10000, -600, 4000, 300); + spawnTower(-8500, -800); + spawn.mapRect(-10000, -800, 2000, 300); + spawn.mapVertex(10000, -9450, "-1000 0 1000 0 1000 -10000 500 -20000 -500 -20000 -1000 -10000"); + spawn.mapVertex(-10000, -9450, "-1000 0 1000 0 1000 -10000 500 -20000 -500 -20000 -1000 -10000"); + spawn.mapRect(-11000, -675, 2000, 2675); + spawn.mapRect(9000, -675, 2000, 2675); + spawn.mapVertex(0, -30000, "0 0 3000 -10000 6000 0 3000 10000"); + spawn.mapRect(-8750, -10000, 8000, 100); + spawn.mapRect(750, -10000, 8000, 100); + spawn.mapVertex(0, -10020, "-1000 0 -5000 300 5000 300 1000 0"); + spawn.mapRect(-800, -10250, 100, 350); + spawn.mapRect(700, -10250, 100, 350); + const a = 200; + const maxTheta = 10 * Math.PI; + const spiralX = (theta) => a * theta * Math.cos(theta); + const spiralY = (theta) => a * theta * Math.sin(theta); + for (let i = 1; i <= maxTheta; i += 0.2) { + const x = spiralX(i); + const y = spiralY(i) + (-15000 + 1800 / 2); + spawn.mapRect(x, y, 100, 100); + } + level.exit.y = map[272].position.y; + level.exit.x = map[272].position.x; + }, + LaunchSite() { + simulation.inGameConsole(`Launch Site by Des Boot`); + simulation.inGameConsole(`The rain stopped...`); + level.setPosToSpawn(0, -50); //normal spawn + const elevatortoggle = level.toggle(13650, 3000) + let newMobsSpawned = false; + let leverTimer = 0; + level.exit.x = 11900; + level.exit.y = -800; + const boost1 = level.boost(12050, 200, 1000) + const boost2 = level.boost(13575, 780, 700) + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + const mover = level.mover(5700, 2680, 3800, 25, 10); //x,y,width.height,VxGoal,force + + //spawning debris + spawn.debris(2700, 2200, 3000, 10); //16 debris per level + spawn.debris(10055, 483, 1300, 10); //16 debris per level + spawn.debris(10500, -240, 1000, 10); //16 debris per level + spawn.debris(9500, 1773.3, 3700, 10); //16 debris per level + + // color.map = "#444" //custom map color + powerUps.spawn(5400, 850, "heal") + powerUps.spawn(5400, 850, "heal") + powerUps.spawn(8650, 2000, "ammo") + powerUps.spawn(8650, 2000, "ammo") + powerUps.spawn(8650, 2000, "ammo") + powerUps.spawn(8650, 2000, "ammo") + level.custom = () => { + + ctx.fillStyle = `rgba(68, 68, 68)` + ctx.fillRect(11450, 700, 50, 125); + ctx.fillRect(11425, 750, 75, 75); + if (newMobsSpawned) { + // ctx.fillStyle = `#00FFFF22`; + ctx.fillStyle = `rgba(0, 255, 255, ${leverTimer / 5})` + ctx.fillRect(11500, 700, 450, 2375 + 100) + ctx.fill() + ctx.fillStyle = `#00f2ff` + ctx.fillRect(11500 + Math.floor(Math.random() * 450), 700, 5, 2375 + 100) + ctx.fillRect(11500 + Math.floor(Math.random() * 450), 700, 5, 2375 + 100) + ctx.fill() + + if (m.pos.x > 11500 && m.pos.x < 11950 && m.pos.y > 800 && m.pos.y < 2700) { + player.force.y -= m.mass * simulation.g + (input.down ? 0 : 0.012 * 4); + } + } + + //light rain + ctx.beginPath() + ctx.fillStyle = "rgba(30,150,117,255)" + ctx.rect(Math.random() * 1600 - 1500, -5000, Math.random() * 3 + 1.5, 5000) + ctx.rect(Math.random() * 2400 - 1500, -5000, Math.random() * 3 + 1.5, 5000) + ctx.rect(Math.random() * 3200 - 1500, -5000, Math.random() * 3 + 1.5, 5000) + ctx.rect(Math.random() * 3000 - 4500, -5000, Math.random() * 3 + 1.5, 8000) + ctx.rect(Math.random() * 3000 - 4500, -5000, Math.random() * 3 + 1.5, 8000) + ctx.rect(Math.random() * 3000 - 4500, -5000, Math.random() * 3 + 1.5, 8000) + + ctx.fill(); + mover.push(); + boost1.query(); + boost2.query(); + + elevatortoggle.query(); + if (elevatortoggle.isOn) { + if (newMobsSpawned == false) { + leverTimer += 0.0125; + //last room mobs + spawn.randomSmallMob(11723.3, -127.5); + spawn.randomSmallMob(10525.2, 727.5); + spawn.randomSmallMob(11290.5, 556.0); + spawn.randomMob(11182.6, 1788.0, 0.8); + spawn.randomGroup(10606.7, -248, 0.4); + spawn.randomGroup(11066.3, 560.4, 0.4); + newMobsSpawned = true; + } + }; + + if (leverTimer > 0 && leverTimer < 1) { + leverTimer += 0.0125 + } + + ctx.fillStyle = "rgba(0,0,0,0.3)" + ctx.beginPath() + ctx.moveTo(5150, 1050) + ctx.lineTo(5580, 1480) + ctx.lineTo(5818, 1203) + ctx.lineTo(5873.4, 1012.4) + ctx.fill() + ctx.beginPath() + ctx.moveTo(5150, 1050) + ctx.lineTo(5580, 1480) + ctx.lineTo(5818, 1203) + ctx.lineTo(5873.4, 1012.4) + ctx.fill() + ctx.beginPath() + ctx.moveTo(5700, 2300) + ctx.lineTo(6100, 2700) + ctx.lineTo(9600, 2700) + ctx.lineTo(10000, 2300) + ctx.fill() + ctx.fillRect(4400, 2050, 550, 800) + ctx.fillStyle = "rgba(0,0,0,0.2)" + ctx.fillRect(4730, 1347, 253, 700) + ctx.fillRect(4950, 2047, 33, 700) + ctx.fillRect(11500, 100, 550, 150) + ctx.moveTo(11800, -700) + ctx.lineTo(12050, -700) + ctx.lineTo(12050, -280) + ctx.lineTo(11950, -280) + ctx.fill() + + //ladder + ctx.fillRect(12065, -770, 20, 870) + ctx.fillRect(12115, -770, 20, 870) + ctx.fillRect(12055, -770, 90, 15) + ctx.fillRect(12055, -710, 90, 15) + ctx.fillRect(12055, -660, 90, 15) + ctx.fillRect(12055, -600, 90, 15) + ctx.fillRect(12055, -540, 90, 15) + ctx.fillRect(12055, -480, 90, 15) + ctx.fillRect(12055, -420, 90, 15) + ctx.fillRect(12055, -360, 90, 15) + ctx.fillRect(12055, -300, 90, 15) + ctx.fillRect(12055, -240, 90, 15) + ctx.fillRect(12055, -180, 90, 15) + ctx.fillRect(12055, -120, 90, 15) + ctx.fillRect(12055, -60, 90, 15) + ctx.fillRect(12055, 0, 90, 15) + ctx.fillRect(12055, 60, 90, 15) + + //post rocket shadows + ctx.fillStyle = "rgba(0,0,0,0.3)" + ctx.fillRect(10000, 510, 50, 700) + + //general background shadows + ctx.fillStyle = "rgba(0,0,0,0.1)" + ctx.fillRect(9500, -800, 5000, 3100) + ctx.fillRect(10000, 2300, 5000, 700) + ctx.moveTo(10000, 2300) + ctx.lineTo(10000, 2700) + ctx.lineTo(9600, 2700) + ctx.fill() + ctx.moveTo(2500, 500) + ctx.lineTo(3660, 1660) + ctx.lineTo(4291.1, 2978.1) + ctx.lineTo(6100, 2700) + ctx.lineTo(5700, 2300) + ctx.lineTo(5884.8, 380.1) + ctx.fill() + + //boss room shadow + ctx.fillRect(11950, 2000, 5000, 1100) + ctx.fillRect(12150, -25, 3000, 250) + ctx.fillRect(12000, 225, 3000, 750) + ctx.fillRect(11700, -1200, 600, 400) + level.exit.drawAndCheck(); + + level.enter.draw(); + } + + level.customTopLayer = () => { + if (12150 < m.pos.x && m.pos.y < 1000) { + ctx.fillStyle = `rgba(68, 68, 68, ${Math.max(0.3, Math.min((12350 - m.pos.x) / 100, 0.99))})` + } else { + ctx.fillStyle = `rgba(68, 68, 68, 68)` + } + + ctx.fillRect(12150, -30, 1600, 1000) + mover.draw(); + + //vanishing platform + vanisher.query(); + + //rocket + ctx.fillStyle = "rgba(202,88,0,1)" + ctx.fillRect(6800, -1000, 600, 2800) + ctx.beginPath() + ctx.moveTo(7400, -998)//base right + ctx.lineTo(7350, -1400)//1/3rd up + ctx.lineTo(7250, -1700)//2/3rd up + ctx.lineTo(7100, -1900)//peak + ctx.lineTo(6950, -1700)//2/3rd down + ctx.lineTo(6850, -1400)//1/3rd down + ctx.lineTo(6800, -998)//baseleft + ctx.fill() + + + ctx.fillStyle = "rgba(255,255,255,1)" + ctx.fillRect(6900, 0, 400, 2000) + ctx.fillRect(6800, 1700, 600, 300) + ctx.fillRect(6450, -400, 250, 2100) + ctx.fillRect(7500, -400, 250, 2100) + + //right engine + ctx.beginPath() + ctx.moveTo(6450, -398)//base right + ctx.lineTo(6575, -900)//peak + ctx.lineTo(6700, -398)//baseleft + ctx.fill() + + //right engine + ctx.beginPath() + ctx.moveTo(7500, -398)//base right + ctx.lineTo(7625, -900)//peak + ctx.lineTo(7750, -398)//baseleft + ctx.fill() + + //right wing + ctx.beginPath() + ctx.moveTo(6910, 450) + ctx.lineTo(6910, 1710) + ctx.lineTo(6250, 1700) + ctx.lineTo(6250, 1600) + ctx.lineTo(6780, 1030) + ctx.fill() + + //left wing + ctx.beginPath() + ctx.moveTo((7100 - 6910) + 7100, 450) + ctx.lineTo((7100 - 6910) + 7100, 1710) + ctx.lineTo((7100 - 6250) + 7100, 1700) + ctx.lineTo((7100 - 6250) + 7100, 1600) + ctx.lineTo((7100 - 6780) + 7100, 1030) + ctx.fill() + + //main rocket tip + ctx.beginPath() + ctx.moveTo(7300, 2)//base right + ctx.lineTo(7250, -300)//1/3rd up + ctx.lineTo(7175, -500)//2/3rd up + ctx.lineTo(7100, -600)//peak + ctx.lineTo(7025, -500)//2/3rd down + ctx.lineTo(6950, -300)//1/3rd down + ctx.lineTo(6900, 2)//baseleft + ctx.fill() + + //right wing outline + ctx.fillStyle = "rgba(0,0,0,1)" + ctx.beginPath() + ctx.moveTo((7100 - 6250) + 7100, 1700) + ctx.lineTo((7100 - 6250) + 7100, 1600) + ctx.lineTo((7100 - 6780) + 7100, 1030) + ctx.lineTo((7100 - 6800) + 7100, 918) + ctx.lineTo((7100 - 6800) + 7100, 1030) + ctx.lineTo((7100 - 6290) + 7100, 1600) + ctx.fill() + + //left wing outline + ctx.beginPath() + ctx.moveTo(6250, 1700) + ctx.lineTo(6250, 1600) + ctx.lineTo(6780, 1030) + ctx.lineTo(6800, 918) + ctx.lineTo(6800, 1030) + ctx.lineTo(6290, 1600) + ctx.fill() + ctx.fillRect(6800, 2000, 600, 50) + ctx.fillRect(6850, 2050, 500, 150) + + + + //light + if (elevatortoggle.isOn) { + ctx.fillStyle = `rgba(242, 255, 0, ${3 * Math.sqrt(leverTimer) / 10})` + ctx.beginPath() + ctx.moveTo(13070, 2012) + ctx.lineTo(12930, 2012) + ctx.lineTo(12230, 2700) + ctx.lineTo(13770, 2700) + ctx.fill() + } + + //shadows + ctx.fillStyle = "rgba(0,0,0,0.3)" + ctx.beginPath() + ctx.moveTo(1800, -400) + ctx.lineTo(2500, 300) + ctx.lineTo(2854, 21) + ctx.lineTo(1974.5, -453.5) + ctx.fill() + + ctx.beginPath() + ctx.moveTo(1800, 0) + ctx.lineTo(3460, 1660) + ctx.lineTo(1522.9, 2431.8) + ctx.lineTo(983.5, 887.3) + ctx.fill() + }; + + //GEOMETRY + + //vanishing platform + var vanisher = level.vanish(10250, 201, 500, 20); + + //blocks + spawn.bodyRect(3700, 1210, 200, 300, 0.9); + spawn.bodyRect(3900, 1210, 220, 150, 0.9); + + //main ground + spawn.mapRect(-1500, 0, 3300, 3700); + spawn.mapRect(-1500, 2700, 15000, 700); + spawn.mapRect(9500, -1500, 2000, 800); + spawn.mapRect(9500, -1500, 500, 2300); + + + spawn.mapRect(2500, 0, 3200, 500); + spawn.mapRect(5700, 0, 500, 2300); + spawn.mapRect(1800, 1100, 800, 2600); + spawn.mapRect(2600, 1660, 1800, 2040); + spawn.mapRect(1800, -495, 200, 100); + spawn.mapVertex(2400, -230, "0 10 900 510 800 510 750 510 0 110"); + + //stairs + spawn.mapRect(2600, 1150, 50, 550); + spawn.mapRect(2650, 1200, 50, 500); + spawn.mapRect(2700, 1250, 50, 450); + spawn.mapRect(2750, 1300, 50, 400); + spawn.mapRect(2800, 1350, 50, 350); + spawn.mapRect(2850, 1400, 50, 300); + spawn.mapRect(2900, 1450, 50, 250); + spawn.mapRect(2950, 1500, 50, 200); + spawn.mapRect(3000, 1550, 50, 150); + spawn.mapRect(3050, 1600, 50, 100); + spawn.mapRect(12100, 1650, 50, 50); + + //platforms in first room + spawn.mapRect(4435, 1300, 550, 50); + spawn.mapRect(4685, 1300, 50, 550); + spawn.mapRect(4400, 2000, 550, 50); + spawn.mapRect(5150, 1000, 550, 50); + spawn.mapVertex(5500, 1550, "0 0 -500 600 100 0 -400 600"); + + //second room + spawn.mapRect(8000, 0, 1500, 2300); + spawn.mapRect(6200, 2200, 1800, 100); + + //stairs after rocket + spawn.mapRect(10300, 2650, 1000, 50); + spawn.mapRect(10350, 2600, 950, 50); + spawn.mapRect(10400, 2550, 900, 50); + spawn.mapRect(10450, 2500, 850, 50); + spawn.mapRect(10500, 2450, 800, 50); + spawn.mapRect(10550, 2400, 750, 50); + spawn.mapRect(10600, 2350, 700, 50); + spawn.mapRect(10650, 2300, 650, 50); + spawn.mapRect(10700, 2250, 600, 50); + spawn.mapRect(10750, 2200, 550, 50); + spawn.mapRect(10800, 2150, 500, 50); + spawn.mapRect(10850, 2100, 450, 50); + spawn.mapRect(10900, 2050, 400, 50); + spawn.mapRect(10950, 2000, 550, 700); + + //light + spawn.mapRect(12925, 2000, 150, 12); + + //roof over stairs + spawn.mapRect(9500, 1200, 1000, 500); + spawn.mapRect(9500, 2200, 500, 100); + spawn.mapRect(9500, 800, 2000, 400); + spawn.mapRect(11950, 800, 2000, 1200); + spawn.mapRect(13900, 800, 2000, 2600); + spawn.mapRect(11950, 2000, 150, 400); + + //last room + spawn.mapRect(10500, 200, 3000, 80); + spawn.mapRect(11950, 200, 100, 1000); + spawn.mapRect(10000, 435, 50, 75); + spawn.mapRect(11000, -50, 60, 250); + spawn.mapRect(11500, -1500, 60, 1100); + spawn.mapRect(11500, 50, 500, 50); + spawn.mapRect(12000, 260, 155, 1000); + + //exit room + spawn.mapRect(11500, -1500, 300, 800); + spawn.mapRect(11950, -280, 100, 380); + spawn.mapRect(12150, -1500, 100, 1600); + spawn.mapRect(11800, -770, 250, 70); + spawn.mapRect(11800, -1500, 350, 400); + spawn.mapRect(12150, -1500, 3000, 1500); + spawn.mapRect(13700, 0, 2000, 800); + spawn.mapRect(13200, 550, 50, 300); + + //MOBS + + + //mobs in first room + spawn.randomSmallMob(4700, 2500); + spawn.randomMob(4100, 1000, 0.8); + spawn.randomGroup(5000, 700, 0.4); + + //second room mobs + spawn.randomSmallMob(9800, 2000); + spawn.randomMob(10910.6, 1559.8, 0.8); + spawn.randomMob(12441.5, 2340.6, 0.8); + spawn.randomMob(11182.6, 1788.0, 0.8); + spawn.randomMob(13381.7, 2437.2, 0.8); + spawn.randomGroup(10472.4, 2079.0, 0.4); + + //boss room + spawn.randomLevelBoss(12786, 2461, ["launcherBoss", "laserTargetingBoss", "blinkBoss", "streamBoss", "historyBoss", "grenadierBoss", "blockBoss", "revolutionBoss", "slashBoss"]); + spawn.mapRect(13500, 3000, 500, 400); + spawn.mapRect(13500, 2700, 325, 60); + + //extra boss + spawn.randomLevelBoss(12808.8, 527.0, ["blinkBoss"]); + + + + + + // powerUps.spawnStartingPowerUps(1475, -1175); + // spawn.debris(750, -2200, 3700, 16); //16 debris per level + // spawn.bodyRect(1540, -1110, 300, 25, 0.9); + // spawn.randomSmallMob(1300, -70); + // spawn.randomMob(2650, -975, 0.8); + // spawn.randomGroup(1700, -900, 0.4); + // if (simulation.difficulty > 1) spawn.randomLevelBoss(2200, -1300); + // spawn.secondaryBossChance(100, -1500) + powerUps.addResearchToLevel() //needs to run after mobs are spawned + + }, + shipwreck() { + simulation.inGameConsole(`shipwreck by 3xionDev`); + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 1500; + level.exit.y = -1875; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#05001C"; + // color.map = "#444" //custom map color + spawn.mapRect(-325, 0, 650, 300); + spawn.mapRect(-275, -675, 50, 700); + spawn.mapRect(-325, -1025, 650, 300); + spawn.mapRect(-275, -750, 50, 75); + spawn.mapRect(300, 50, 675, 200); + spawn.mapRect(925, 50, 450, 150); + spawn.mapRect(275, -750, 50, 275); + spawn.mapRect(275, -325, 50, 325); + spawn.bodyRect(150, -175, 100, 100); + spawn.bodyRect(-200, -450, 100, 400); + spawn.bodyRect(-150, -650, 25, 50); + spawn.bodyRect(-200, -700, 25, 25); + spawn.bodyRect(175, -250, 75, 100); + spawn.mapRect(875, -50, 100, 100); + spawn.mapRect(350, -175, 25, 25); + spawn.mapRect(325, -175, 175, 225); + spawn.bodyRect(375, -225, 50, 50); + spawn.bodyRect(700, -450, 125, 125); + spawn.mapRect(1375, 25, 400, 100); + spawn.mapRect(1675, -175, 100, 200); + spawn.mapRect(1775, -175, 225, 100); + spawn.mapRect(1575, -75, 100, 100); + spawn.mapRect(1775, -75, 175, 100); + spawn.mapRect(1300, 125, 250, 25); + spawn.mapRect(850, 200, 225, 25); + spawn.mapRect(1100, 200, 50, 100); + spawn.mapRect(1250, 175, 50, 125); + spawn.mapRect(1950, -150, 275, 50); + spawn.mapRect(2125, -150, 25, 25); + spawn.mapRect(2125, -175, 1025, 100); + spawn.mapRect(2625, -350, 25, 25); + spawn.mapRect(2650, -325, 25, 150); + spawn.mapRect(2625, -400, 50, 250); + spawn.bodyRect(1900, -200, 325, 25); + spawn.bodyRect(2525, -275, 100, 100); + spawn.bodyRect(2575, -325, 50, 50); + spawn.mapRect(425, -75, 150, 125); + spawn.bodyRect(350, -250, 75, 75); + spawn.bodyRect(1250, -200, 25, 25); + spawn.bodyRect(1150, -350, 100, 175); + spawn.bodyRect(1375, -375, 25, 25); + spawn.bodyRect(1375, -400, 50, 100); + spawn.mapRect(2650, -400, 500, 50); + spawn.mapRect(3100, -175, 300, 50); + spawn.bodyRect(2700, -250, 75, 25); + spawn.bodyRect(2725, -275, 25, 25); + spawn.bodyRect(2750, -250, 25, 25); + spawn.bodyRect(2825, -275, 75, 100); + spawn.randomMob(3650, -250, 0); + spawn.bodyRect(2925, -225, 50, 50); + spawn.mapRect(325, -950, 25, 25); + spawn.mapRect(325, -975, 650, 200); + spawn.mapRect(975, -900, 200, 100); + spawn.mapRect(1175, -850, 100, 100); + spawn.mapRect(1275, -800, 75, 125); + spawn.mapRect(1350, -725, 25, 125); + spawn.mapRect(1225, -800, 25, 25); + spawn.mapRect(950, -925, 100, 25); + spawn.mapRect(1150, -875, 100, 25); + spawn.mapRect(1250, -825, 75, 50); + spawn.mapRect(1125, -825, 75, 50); + spawn.mapRect(1250, -775, 50, 50); + spawn.mapRect(1400, -225, 100, 200); + spawn.mapRect(1550, -150, 125, 75); + spawn.mapRect(1500, -100, 75, 75); + spawn.mapRect(1175, -225, 225, 100); + spawn.mapRect(1475, -200, 100, 100); + spawn.mapRect(1300, -175, 125, 100); + spawn.mapRect(1250, -150, 50, 200); + spawn.mapRect(1600, -275, 50, 150); + spawn.mapRect(1300, -275, 75, 75); + spawn.mapRect(1475, -375, 50, 225); + spawn.mapRect(1575, -225, 25, 100); + spawn.mapRect(1500, -325, 50, 125); + spawn.bodyRect(1400, -350, 25, 50); + spawn.bodyRect(1650, -425, 50, 50); + spawn.bodyRect(1750, -475, 25, 125); + spawn.bodyRect(1725, -575, 150, 50); + spawn.bodyRect(1625, -425, 25, 50); + spawn.bodyRect(1175, -425, 75, 75); + spawn.mapRect(325, -625, 175, 50); + spawn.mapRect(425, -800, 25, 175); + spawn.mapRect(375, -800, 25, 200); + spawn.mapRect(500, -800, 25, 225); + spawn.mapRect(475, -800, 50, 225); + spawn.mapRect(675, -875, 50, 575); + spawn.mapRect(675, -150, 25, 175); + spawn.mapRect(700, -150, 25, 75); + spawn.mapRect(675, -125, 25, 200); + spawn.bodyRect(675, -300, 50, 150); + spawn.mapRect(2125, -1025, 1025, 100); + spawn.mapRect(3050, -975, 325, 50); + spawn.mapRect(3300, -925, 75, 600); + spawn.bodyRect(3300, -325, 75, 125); + spawn.bodyRect(3325, -325, 25, 25); + spawn.mapRect(3300, -325, 75, 25); + spawn.mapRect(3325, -175, 1100, 25); + spawn.mapRect(3325, -950, 1100, 25); + spawn.mapRect(3350, -725, 225, 25); + spawn.mapRect(3500, -925, 75, 200); + spawn.mapRect(3350, -850, 175, 25); + spawn.bodyRect(4075, -625, 125, 125); + spawn.bodyRect(3850, -825, 75, 50); + spawn.bodyRect(4050, -800, 25, 50); + spawn.bodyRect(4150, -825, 75, 100); + spawn.bodyRect(3900, -800, 50, 75); + spawn.bodyRect(3575, -375, 100, 75); + spawn.bodyRect(3800, -675, 75, 100); + spawn.bodyRect(3950, -875, 250, 150); + spawn.bodyRect(3975, -700, 50, 100); + spawn.bodyRect(4150, -775, 200, 125); + spawn.bodyRect(3825, -700, 50, 125); + spawn.bodyRect(3575, -550, 125, 50); + spawn.bodyRect(3750, -550, 25, 25); + spawn.bodyRect(3600, -625, 75, 50); + spawn.bodyRect(3550, -500, 75, 50); + spawn.bodyRect(4200, -675, 75, 75); + spawn.bodyRect(4400, -600, 50, 125); + spawn.mapRect(4375, -175, 350, 25); + spawn.mapRect(4475, -200, 475, 50); + spawn.mapRect(4450, -925, 25, 25); + spawn.mapRect(4475, -950, 475, 50); + spawn.mapRect(4350, -950, 225, 25); + spawn.mapRect(4450, -925, 100, 750); + spawn.mapRect(4650, -900, 825, 700); + spawn.mapRect(5250, -825, 475, 550); + spawn.mapRect(5550, -725, 700, 350); + spawn.mapRect(6100, -625, 550, 150); + spawn.mapRect(6600, -575, 225, 50); + spawn.mapRect(1325, -875, 50, 200); + spawn.mapRect(1275, -825, 50, 25); + spawn.mapRect(1275, -875, 25, 50); + spawn.mapRect(1225, -900, 75, 25); + spawn.mapRect(1325, -900, 50, 75); + spawn.mapRect(1075, -925, 200, 75); + spawn.mapRect(1275, -975, 75, 150); + spawn.mapRect(1300, -800, 100, 150); + spawn.mapRect(1375, -725, 50, 150); + spawn.mapRect(-325, -1525, 650, 300); + spawn.mapRect(150, -1275, 50, 375); + spawn.mapRect(-100, -1350, 50, 450); + spawn.mapRect(-325, -2600, 650, 300); + spawn.mapRect(-275, -2400, 25, 50); + spawn.mapRect(-275, -2325, 50, 825); + spawn.mapRect(300, -1475, 675, 200); + spawn.bodyRect(375, -1250, 75, 75); + spawn.bodyRect(800, -1275, 25, 300); + spawn.mapRect(1950, -1000, 175, 100); + spawn.mapRect(1850, -950, 125, 125); + spawn.mapRect(1825, -875, 75, 125); + spawn.mapRect(1825, -800, 25, 125); + spawn.mapRect(1800, -750, 25, 150); + spawn.mapRect(1775, -625, 50, 150); + spawn.mapRect(2000, -900, 25, 225); + spawn.mapRect(2075, -925, 50, 400); + spawn.mapRect(1000, -825, 25, 300); + spawn.mapRect(1050, -900, 50, 25); + spawn.mapRect(1050, -925, 50, 25); + spawn.mapRect(2475, -100, 50, 350); + spawn.mapRect(2650, -100, 25, 725); + spawn.mapRect(2350, -950, 50, 350); + spawn.mapRect(775, -825, 25, 375); + spawn.mapRect(3750, -950, 25, 175); + spawn.mapRect(3625, -925, 25, 275); + spawn.mapRect(4225, -925, 50, 200); + spawn.mapRect(950, -1425, 200, 100); + spawn.mapRect(1150, -1400, 150, 75); + spawn.mapRect(1300, -1350, 25, 100); + spawn.mapRect(1275, -1350, 25, 50); + spawn.bodyRect(1300, -1250, 25, 275); + spawn.bodyRect(2600, -1575, 375, 550); + spawn.bodyRect(2625, -1300, 75, 150); + spawn.bodyRect(2700, -1475, 100, 275); + spawn.bodyRect(2525, -1200, 75, 150); + spawn.mapRect(1675, -1400, 200, 75); + spawn.mapRect(1825, -1425, 225, 100); + spawn.mapRect(1650, -1350, 75, 100); + spawn.mapRect(1700, -1275, 25, 125); + spawn.bodyRect(1225, -1425, 550, 25); + spawn.bodyRect(1300, -1650, 100, 150); + spawn.bodyRect(1600, -1675, 100, 200); + spawn.bodyRect(1575, -1525, 25, 25); + spawn.bodyRect(1450, -1575, 25, 125); + spawn.bodyRect(1500, -1650, 75, 50); + spawn.mapRect(2325, -1225, 50, 200); + spawn.mapRect(2375, -1300, 100, 275); + spawn.mapRect(2225, -1125, 125, 100); + spawn.mapRect(2300, -1150, 50, 50); + spawn.bodyRect(2250, -850, 75, 100); + spawn.mapRect(150, -2550, 800, 200); + spawn.mapRect(875, -2500, 275, 100); + spawn.mapRect(325, -2400, 75, 375); + spawn.mapRect(325, -1800, 75, 350); + spawn.bodyRect(325, -2025, 75, 225); + spawn.mapRect(-150, -2375, 25, 375); + spawn.mapRect(25, -2400, 50, 500); + spawn.mapRect(-100, -2375, 25, 225); + spawn.mapRect(200, -2350, 50, 250); + spawn.bodyRect(250, -1875, 25, 75); + spawn.bodyRect(-50, -2050, 50, 50); + spawn.mapRect(1050, -1350, 50, 150); + spawn.mapRect(575, -1325, 25, 100); + spawn.mapRect(400, -1300, 25, 75); + spawn.mapRect(525, -1300, 50, 125); + spawn.mapRect(575, -2400, 75, 275); + spawn.mapRect(650, -2325, 25, 325); + spawn.mapRect(625, -2150, 50, 75); + spawn.mapRect(625, -2375, 50, 100); + spawn.mapRect(600, -2125, 25, 25); + spawn.mapRect(650, -2075, 25, 150); + spawn.mapRect(675, -2375, 50, 200); + spawn.mapRect(650, -2200, 50, 75); + spawn.mapRect(625, -2100, 50, 75); + spawn.mapRect(1100, -2475, 950, 50); + spawn.mapRect(1325, -1825, 450, 25); + spawn.mapRect(1475, -1850, 150, 50); + spawn.mapRect(1725, -2425, 50, 600); + spawn.mapRect(1325, -2450, 50, 450); + spawn.mapRect(1475, -2425, 25, 150); + spawn.mapRect(1675, -2425, 25, 600); + spawn.bodyRect(1450, -2175, 50, 75); + spawn.bodyRect(1650, -2200, 50, 50); + spawn.mapRect(950, -1550, 75, 125); + spawn.mapRect(900, -1500, 50, 50); + spawn.mapRect(2000, -2475, 125, 50); + spawn.mapRect(2100, -2475, 1050, 100); + spawn.mapRect(3050, -2425, 300, 50); + spawn.mapRect(3225, -2400, 1350, 25); + spawn.mapRect(4475, -2400, 475, 50); + spawn.mapRect(4900, -2375, 1125, 50); + spawn.mapRect(3950, -1350, 2075, 50); + spawn.mapRect(4075, -1325, 75, 400); + spawn.mapRect(4775, -1325, 75, 425); + spawn.mapRect(6000, -2350, 1075, 1025); + spawn.mapRect(6675, -2250, 950, 825); + spawn.mapRect(7375, -2050, 700, 425); + spawn.mapRect(7850, -1900, 425, 125); + spawn.mapRect(8200, -1850, 275, 25); + spawn.mapRect(5000, -2350, 75, 400); + spawn.mapRect(5200, -2350, 25, 600); + spawn.mapRect(5600, -2325, 25, 475); + spawn.mapRect(5750, -2350, 50, 300); + spawn.mapRect(5800, -2325, 25, 400); + spawn.mapRect(5775, -2075, 25, 50); + spawn.bodyRect(5325, -2250, 75, 125); + spawn.bodyRect(5925, -1800, 75, 125); + spawn.bodyRect(5475, -1800, 75, 225); + spawn.bodyRect(5350, -2050, 175, 100); + spawn.bodyRect(5475, -2125, 75, 125); + spawn.bodyRect(5750, -1750, 100, 100); + spawn.bodyRect(5900, -1950, 175, 150); + spawn.bodyRect(4600, -1950, 150, 275); + spawn.bodyRect(4875, -1875, 150, 100); + spawn.mapRect(5675, -1600, 350, 50); + spawn.mapRect(4325, -1300, 25, 200); + spawn.mapRect(3975, -2375, 75, 350); + spawn.mapRect(4250, -2375, 25, 550); + spawn.mapRect(2875, -2400, 75, 400); + spawn.mapRect(3050, -2425, 25, 700); + spawn.mapRect(2450, -2425, 75, 550); + spawn.mapRect(3375, -2375, 25, 525); + spawn.mapRect(3325, -1125, 75, 225); + spawn.mapRect(3125, -1200, 25, 200); + spawn.mapRect(2975, -1225, 75, 225); + spawn.mapRect(1875, -2425, 50, 550); + spawn.mapRect(1900, -1925, 475, 50); + spawn.mapRect(2300, -2400, 75, 475); + spawn.bodyRect(2025, -2325, 50, 50); + spawn.bodyRect(2150, -2300, 100, 100); + spawn.bodyRect(2025, -2325, 25, 100); + spawn.bodyRect(2125, -2275, 75, 75); + spawn.bodyRect(2250, -2250, 25, 50); + spawn.bodyRect(2000, -2325, 75, 100); + spawn.bodyRect(2150, -2300, 75, 100); + spawn.bodyRect(1975, -2300, 75, 75); + spawn.bodyRect(2150, -2300, 75, 75); + spawn.bodyRect(2025, -2350, 50, 125); + spawn.bodyRect(2250, -2325, 50, 75); + spawn.randomMob(2625, -750, 0); + spawn.randomMob(3200, -725, 0); + spawn.randomMob(2900, -575, 0); + spawn.randomMob(700, -1100, 0); + spawn.randomMob(3275, -1575, 0); + spawn.randomMob(3950, -1500, 0); + spawn.randomMob(3725, -1300, 0); + spawn.randomMob(3625, -1700, 0); + spawn.randomMob(2250, -1675, 0); + spawn.randomMob(550, -1875, 0); + spawn.randomMob(1600, -700, 0); + spawn.randomMob(1050, -400, 0); + spawn.randomSmallMob(1085, -1591); + spawn.randomSmallMob(1516, -532); + spawn.randomGroup(1551, -466, 0.4); + if (simulation.difficulty > 1) spawn.randomLevelBoss(3928, -655); + spawn.secondaryBossChance(4088, -1744) + + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { }; + }, + unchartedCave() { + simulation.inGameConsole(`unchartedCave by 3xionDev`); + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 20985; + level.exit.y = 2816; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1900 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#979797"; + + spawn.randomMob(1000, -975, 0); + spawn.randomMob(2550, -575, 0); + spawn.randomMob(2050, -325, 0); + spawn.randomMob(2475, -1350, 0); + spawn.randomMob(2800, -1100, 0); + spawn.randomMob(3400, -1250, 0); + spawn.randomMob(3375, -425, 0); + spawn.randomMob(4575, -775, 0); + spawn.randomMob(5750, -750, 0); + spawn.randomMob(5475, -325, 0); + spawn.randomMob(7625, -250, 0); + spawn.randomMob(9675, 525, 0); + spawn.randomMob(12150, 1200, 0); + spawn.randomMob(12825, 1275, 0); + spawn.randomMob(13175, 1725, 0); + spawn.randomMob(13725, 1375, 0); + spawn.randomMob(15550, 2375, 0); + spawn.randomMob(17625, 3550, 0); + spawn.randomMob(18850, 3500, 0); + spawn.mapRect(-150, 0, 300, 75); + spawn.mapRect(-375, 25, 2550, 75); + spawn.mapRect(-400, -950, 75, 1025); + spawn.mapRect(-400, 75, 50, 25); + spawn.mapRect(-400, -1750, 100, 800); + spawn.mapRect(-350, -1050, 50, 1125); + spawn.mapRect(-400, -1950, 100, 275); + spawn.mapRect(1875, 25, 2075, 75); + spawn.mapRect(-400, 50, 4350, 1175); + spawn.mapRect(-400, 650, 4350, 1175); + spawn.mapRect(2975, 25, 3575, 1800); + spawn.mapRect(-375, -1925, 1725, 800); + spawn.mapRect(-400, -2275, 5625, 725); + spawn.mapRect(1075, -1725, 500, 425); + spawn.mapRect(1275, -1325, 200, 125); + spawn.mapRect(1525, -1325, 25, 75); + spawn.mapRect(1400, -1425, 125, 200); + spawn.mapRect(1400, -1725, 325, 275); + spawn.mapRect(1675, -1600, 125, 100); + spawn.mapRect(-350, -1200, 250, 250); + spawn.mapRect(-175, -1225, 250, 175); + spawn.mapRect(-50, -1150, 275, 50); + spawn.bodyRect(-275, -475, 75, 175); + spawn.bodyRect(325, -750, 50, 50); + spawn.mapRect(2075, -1575, 75, 725); + spawn.mapRect(1900, -1600, 50, 325); + spawn.mapRect(2600, -1675, 25, 850); + spawn.mapRect(2125, -1625, 125, 425); + spawn.mapRect(2125, -1200, 50, 75); + spawn.mapRect(2075, -875, 25, 150); + spawn.mapRect(2025, -1625, 50, 250); + spawn.mapRect(4700, -2275, 2175, 1275); + spawn.mapRect(3975, -1725, 1125, 400); + spawn.mapRect(4300, -1400, 650, 200); + spawn.mapRect(4600, -1225, 175, 125); + spawn.mapRect(3925, -1600, 175, 150); + spawn.mapRect(3950, -1450, 50, 75); + spawn.mapRect(4225, -1350, 150, 100); + spawn.mapRect(3875, -1600, 175, 175); + spawn.mapRect(4450, -1275, 200, 125); + spawn.mapRect(4850, -1125, 50, 550); + spawn.mapRect(5225, -1175, 25, 400); + spawn.mapRect(3250, -1725, 25, 1200); + spawn.mapRect(3600, -1750, 75, 550); + spawn.mapRect(2850, -1700, 325, 325); + spawn.mapRect(2900, -1525, 175, 750); + spawn.mapRect(2975, -900, 75, 450); + spawn.mapRect(550, -175, 150, 500); + spawn.mapRect(625, -300, 125, 450); + spawn.mapRect(725, -175, 50, 475); + spawn.mapRect(675, -400, 25, 200); + spawn.mapRect(450, -25, 150, 150); + spawn.mapRect(275, -1200, 75, 625); + spawn.mapRect(300, -1300, 150, 600); + spawn.mapRect(425, -1250, 25, 800); + spawn.mapRect(425, -1225, 125, 425); + spawn.mapRect(525, -1175, 100, 250); + spawn.mapRect(175, -1200, 175, 375); + spawn.mapRect(1600, -375, 50, 650); + spawn.mapRect(1650, -525, 75, 725); + spawn.mapRect(1450, -225, 150, 475); + spawn.mapRect(1400, -125, 100, 275); + spawn.mapRect(1500, -325, 125, 150); + spawn.mapRect(1750, -225, 100, 350); + spawn.mapRect(1700, -300, 75, 275); + spawn.mapRect(1850, -150, 25, 325); + spawn.mapRect(1750, -50, 75, 225); + spawn.mapRect(1600, -50, 200, 250); + spawn.mapRect(1700, -600, 25, 125); + spawn.bodyRect(1275, -250, 50, 125); + spawn.mapRect(6450, 50, 675, 2000); + spawn.mapRect(6925, 175, 675, 300); + spawn.mapRect(7450, 300, 675, 775); + spawn.mapRect(6925, 325, 1275, 1850); + spawn.mapRect(7025, 125, 375, 100); + spawn.mapRect(7500, 275, 425, 100); + spawn.mapRect(6700, -2275, 1975, 1575); + spawn.mapRect(6475, -1175, 400, 300); + spawn.mapRect(6550, -925, 250, 150); + spawn.mapRect(6600, -825, 175, 75); + spawn.mapRect(6300, -1050, 325, 100); + spawn.mapRect(8050, 400, 450, 1675); + spawn.mapRect(8275, 475, 800, 1550); + spawn.mapRect(8600, 575, 925, 1475); + spawn.mapRect(8400, 425, 300, 100); + spawn.mapRect(8975, 550, 300, 100); + spawn.mapRect(6900, -775, 2375, 200); + spawn.mapRect(7350, -725, 2125, 275); + spawn.mapRect(7725, -550, 1800, 225); + spawn.mapRect(8300, -400, 1750, 125); + spawn.mapRect(8725, -350, 1350, 225); + spawn.mapRect(8525, -375, 400, 150); + spawn.mapRect(8650, -250, 150, 50); + spawn.mapRect(8200, -350, 175, 50); + spawn.mapRect(7600, -475, 275, 100); + spawn.mapRect(7475, -500, 175, 75); + spawn.mapRect(7200, -600, 300, 75); + spawn.mapRect(7075, -600, 150, 25); + spawn.mapRect(7125, -575, 100, 25); + spawn.mapRect(7275, -525, 100, 25); + spawn.mapRect(7500, 225, 275, 125); + spawn.mapRect(5800, -1175, 675, 100); + spawn.mapRect(9400, 625, 500, 1725); + spawn.mapRect(9750, 775, 575, 1500); + spawn.mapRect(10050, 1075, 675, 1300); + spawn.mapRect(9725, -250, 975, 350); + spawn.mapRect(10275, -100, 1000, 625); + spawn.mapRect(10125, 25, 375, 350); + spawn.mapRect(9900, 25, 375, 225); + spawn.mapRect(10075, 250, 200, 50); + spawn.mapRect(10275, 425, 75, 75); + spawn.mapRect(10150, 325, 200, 75); + spawn.mapRect(10200, 375, 125, 100); + spawn.mapRect(9600, -175, 225, 200); + spawn.mapRect(9650, -25, 125, 100); + spawn.mapRect(9450, -200, 225, 175); + spawn.mapRect(10000, 200, 50, 25); + spawn.mapRect(9800, 50, 200, 125); + spawn.mapRect(9875, 725, 150, 75); + spawn.mapRect(10300, 900, 100, 325); + spawn.mapRect(10375, 950, 75, 225); + spawn.mapRect(10425, 1000, 75, 175); + spawn.mapRect(9100, -150, 375, 75); + spawn.mapRect(3525, 0, 1850, 100); + spawn.mapRect(3650, -25, 1475, 175); + spawn.mapRect(4000, -100, 950, 225); + spawn.mapRect(4450, -175, 300, 175); + spawn.mapRect(1825, -25, 775, 100); + spawn.mapRect(4150, -1375, 175, 75); + spawn.mapRect(3800, -1600, 125, 100); + spawn.mapRect(2700, 0, 175, 100); + spawn.mapRect(2750, -50, 75, 150); + spawn.mapRect(2775, -25, 75, 75); + spawn.bodyRect(3775, -575, 50, 75); + spawn.mapRect(8050, -2300, 4650, 1750); + spawn.mapRect(9300, -975, 2450, 575); + spawn.mapRect(9925, -775, 2350, 700); + spawn.mapRect(10675, -600, 2025, 1175); + spawn.mapRect(10300, 825, 50, 125); + spawn.mapRect(10000, 750, 100, 25); + spawn.mapRect(9875, 700, 75, 75); + spawn.mapRect(9850, 675, 75, 50); + spawn.mapRect(8975, 525, 225, 50); + spawn.mapRect(8625, 450, 225, 50); + spawn.mapRect(8925, -150, 175, 50); + spawn.mapRect(-500, 1775, 10800, 1800); + spawn.mapRect(10075, 2200, 625, 1850); + spawn.mapRect(10525, 475, 250, 75); + spawn.mapRect(10450, 1025, 25, 25); + spawn.mapRect(10450, 1050, 150, 25); + spawn.mapRect(10675, 1125, 175, 1700); + spawn.mapRect(10725, 1225, 400, 725); + spawn.mapRect(10975, 1425, 300, 1300); + spawn.mapRect(11225, 1550, 700, 1275); + spawn.mapRect(11725, 1625, 1150, 1150); + spawn.mapRect(11050, 1275, 125, 350); + spawn.mapRect(11150, 1350, 75, 175); + spawn.mapRect(10825, 1200, 125, 75); + spawn.mapRect(10325, 1750, 1275, 1150); + spawn.mapRect(11250, 1500, 325, 100); + spawn.mapRect(11225, 1475, 200, 75); + spawn.mapRect(11525, 1525, 350, 75); + spawn.mapRect(11875, 1575, 425, 100); + spawn.mapRect(12200, 1625, 25, 25); + spawn.mapRect(12200, 1600, 250, 75); + spawn.randomMob(11250, 675, 0); + spawn.bodyRect(10900, 575, 50, 625); + spawn.mapRect(11050, 575, 1725, 200); + spawn.mapRect(11275, 750, 1650, 125); + spawn.mapRect(11575, 875, 1525, 150); + spawn.mapRect(11450, 850, 250, 125); + spawn.mapRect(11325, 850, 225, 50); + spawn.mapRect(11400, 875, 100, 75); + spawn.mapRect(11175, 750, 200, 75); + spawn.mapRect(11125, 775, 100, 25); + spawn.mapRect(11250, 825, 50, 25); + spawn.mapRect(11675, 1025, 400, 50); + spawn.mapRect(12175, 1025, 50, 150); + spawn.mapRect(11625, 1000, 75, 50); + spawn.mapRect(12200, 1175, 25, 25); + spawn.mapRect(12400, 950, 100, 275); + spawn.mapRect(12450, 1200, 50, 100); + spawn.mapRect(12425, 1225, 50, 125); + spawn.mapRect(12425, 1325, 25, 75); + spawn.mapRect(12325, 1025, 25, 100); + spawn.mapRect(12625, 1000, 625, 150); + spawn.mapRect(12775, 1150, 600, 50); + spawn.bodyRect(12075, 1325, 100, 50); + spawn.mapRect(12825, 2000, 800, 975); + spawn.mapRect(13475, 1625, 150, 475); + spawn.mapRect(12850, 1750, 50, 275); + spawn.mapRect(12875, 1850, 75, 225); + spawn.mapRect(12950, 1925, 75, 125); + spawn.mapRect(13450, 1700, 50, 350); + spawn.mapRect(13400, 1750, 75, 350); + spawn.mapRect(13325, 1875, 100, 200); + spawn.mapRect(13350, 1800, 75, 100); + spawn.mapRect(13300, 1950, 25, 75); + spawn.mapRect(12925, 1900, 75, 25); + spawn.mapRect(12900, 1800, 25, 75); + spawn.mapRect(13000, 1975, 150, 25); + spawn.mapRect(12475, 100, 1150, 925); + spawn.mapRect(13200, 100, 925, 1100); + spawn.mapRect(13525, 1150, 400, 75); + spawn.mapRect(13875, 1200, 175, 125); + spawn.mapRect(13975, 1300, 75, 225); + spawn.mapRect(14025, 1425, 25, 225); + spawn.mapRect(13600, 1700, 100, 1250); + spawn.mapRect(13675, 1775, 150, 1200); + spawn.mapRect(13775, 1825, 75, 1150); + spawn.mapRect(13825, 1900, 50, 1075); + spawn.mapRect(13850, 1950, 75, 1025); + spawn.mapRect(13875, 2025, 75, 950); + spawn.mapRect(13925, 2100, 50, 1025); + spawn.mapRect(13900, 2125, 100, 1000); + spawn.mapRect(13975, 2225, 75, 900); + spawn.mapRect(14000, 2375, 100, 750); + spawn.mapRect(14050, 1200, 75, 525); + spawn.mapRect(14075, 1625, 100, 150); + spawn.mapRect(14175, 1750, 50, 175); + spawn.mapRect(14150, 1750, 50, 75); + spawn.mapRect(14225, 1875, 50, 150); + spawn.mapRect(14250, 2000, 50, 150); + spawn.mapRect(14100, 300, 300, 1450); + spawn.mapRect(14225, 1675, 150, 250); + spawn.mapRect(14300, 1700, 100, 675); + spawn.mapRect(14275, 1925, 50, 175); + spawn.mapRect(14025, 2300, 50, 200); + spawn.mapRect(14075, 2600, 275, 700); + spawn.mapRect(14050, 2425, 75, 475); + spawn.mapRect(14100, 2525, 50, 150); + spawn.mapRect(14150, 2575, 50, 100); + spawn.mapRect(14325, 2650, 800, 1300); + spawn.mapRect(15000, 2600, 1075, 1275); + spawn.mapRect(15100, 2550, 1200, 1400); + spawn.mapRect(14375, 1075, 1400, 1175); + spawn.mapRect(14375, 2225, 200, 50); + spawn.mapRect(14375, 2275, 75, 75); + spawn.mapRect(14425, 2275, 75, 25); + spawn.mapRect(14775, 2200, 50, 125); + spawn.mapRect(14725, 2250, 25, 125); + spawn.bodyRect(14300, 2375, 50, 225); + spawn.mapRect(15075, 2600, 50, 25); + spawn.mapRect(15075, 2575, 50, 50); + spawn.mapRect(14950, 2625, 50, 25); + spawn.mapRect(15525, 2525, 300, 50); + spawn.mapRect(15550, 2500, 175, 100); + spawn.mapRect(14975, 2250, 200, 25); + spawn.mapRect(14400, 1000, 1900, 1250); + spawn.mapRect(15925, 2250, 275, 25); + spawn.mapRect(15975, 2275, 150, 25); + spawn.mapRect(16075, 2300, 25, 75); + spawn.mapRect(16250, 2575, 275, 1275); + spawn.mapRect(16400, 2600, 250, 1300); + spawn.mapRect(16525, 2675, 300, 1150); + spawn.mapRect(16650, 2725, 300, 1175); + spawn.mapRect(16200, 1050, 600, 1225); + spawn.mapRect(16525, 1025, 500, 1300); + spawn.mapRect(16725, 1150, 525, 1225); + spawn.mapRect(16900, 1425, 550, 1000); + spawn.mapRect(16375, 2250, 250, 50); + spawn.mapRect(16675, 2325, 75, 25); + spawn.mapRect(16850, 2400, 25, 25); + spawn.mapRect(16850, 2375, 100, 50); + spawn.mapRect(16800, 2375, 50, 25); + spawn.mapRect(16575, 2650, 150, 75); + spawn.mapRect(16625, 2625, 50, 50); + spawn.mapRect(16800, 2700, 50, 50); + spawn.mapRect(16950, 2900, 450, 1175); + spawn.mapRect(16900, 2825, 100, 275); + spawn.mapRect(16900, 2775, 75, 150); + spawn.mapRect(16950, 2850, 100, 125); + spawn.mapRect(17600, 3000, 350, 25); + spawn.mapRect(17650, 3025, 200, 50); + spawn.mapRect(17750, 3050, 100, 1200); + spawn.mapRect(17850, 3025, 25, 425); + spawn.mapRect(18200, 3100, 450, 25); + spawn.mapRect(18250, 3125, 150, 100); + spawn.mapRect(18400, 3125, 200, 50); + spawn.mapRect(18400, 3150, 75, 900); + spawn.mapRect(18400, 3950, 75, 375); + spawn.mapRect(17750, 4000, 100, 325); + spawn.mapRect(18200, 3075, 525, 50); + spawn.mapRect(18450, 3175, 50, 275); + spawn.mapRect(18575, 3125, 50, 50); + spawn.mapRect(18600, 3100, 50, 50); + spawn.mapRect(18325, 3200, 100, 175); + spawn.mapRect(18350, 3350, 75, 100); + spawn.mapRect(18375, 3450, 25, 75); + spawn.mapRect(18500, 3175, 25, 150); + spawn.mapRect(17725, 3075, 50, 175); + spawn.mapRect(17700, 3075, 25, 50); + spawn.mapRect(18550, 3150, 50, 1275); + spawn.mapRect(18975, 2975, 525, 25); + spawn.mapRect(19025, 2975, 400, 75); + spawn.mapRect(19150, 3025, 150, 1400); + spawn.mapRect(19250, 3025, 100, 325); + spawn.mapRect(19100, 3050, 75, 225); + spawn.mapRect(19125, 3275, 50, 75); + spawn.mapRect(19275, 3325, 50, 200); + spawn.mapRect(19700, 3000, 525, 50); + spawn.mapRect(19750, 3050, 175, 1275); + spawn.mapRect(19925, 3025, 100, 225); + spawn.mapRect(19900, 3200, 75, 250); + spawn.mapRect(20025, 3050, 50, 100); + spawn.mapRect(20000, 3150, 50, 75); + spawn.mapRect(19900, 3450, 50, 125); + spawn.mapRect(19725, 3050, 75, 150); + spawn.mapRect(19650, 3025, 25, 25); + spawn.mapRect(19650, 3000, 625, 25); + spawn.mapRect(17375, 1450, 3525, 250); + spawn.mapRect(17400, 1675, 100, 400); + spawn.mapRect(17475, 1675, 75, 150); + spawn.mapRect(17525, 1650, 125, 75); + spawn.mapRect(17475, 1775, 50, 175); + spawn.mapRect(17425, 2025, 50, 200); + spawn.mapRect(17825, 1650, 375, 75); + spawn.mapRect(17975, 1700, 100, 125); + spawn.mapRect(18050, 1800, 50, 150); + spawn.mapRect(18025, 1675, 100, 150); + spawn.mapRect(18075, 1900, 25, 175); + spawn.mapRect(20550, 2825, 825, 1525); + spawn.mapRect(20825, 1450, 550, 250); + spawn.mapRect(21350, 1450, 300, 2700); + spawn.mapRect(21100, 1650, 275, 425); + spawn.mapRect(21225, 2025, 175, 275); + spawn.mapRect(21175, 2025, 75, 150); + spawn.mapRect(21300, 2275, 75, 150); + spawn.mapRect(21000, 1675, 100, 300); + spawn.mapRect(21050, 1950, 50, 100); + spawn.mapRect(20700, 1700, 200, 50); + spawn.mapRect(20750, 1725, 50, 225); + spawn.mapRect(20800, 1725, 50, 175); + spawn.mapRect(20750, 1925, 25, 150); + spawn.mapRect(20975, 1675, 50, 225); + spawn.mapRect(21275, 2300, 50, 50); + spawn.mapRect(20550, 1700, 150, 50); + spawn.mapRect(20550, 1725, 50, 825); + spawn.mapRect(20575, 1725, 50, 300); + spawn.mapRect(20600, 1725, 50, 75); + spawn.mapRect(20600, 1875, 25, 350); + spawn.mapRect(20675, 1750, 25, 400); + spawn.bodyRect(20550, 2550, 50, 275); + spawn.mapRect(20500, 2850, 75, 1500); + spawn.mapRect(20475, 2900, 50, 1425); + spawn.bodyRect(21200, 2550, 50, 75); + spawn.bodyRect(20775, 2225, 75, 75); + + spawn.mapRect(19525, 1700, 550, 25); + spawn.mapRect(19650, 1725, 100, 275); + spawn.mapRect(19725, 1700, 50, 525); + spawn.mapRect(19750, 1725, 250, 150); + spawn.mapRect(19775, 1850, 100, 225); + spawn.mapRect(19850, 1875, 100, 75); + spawn.mapRect(19600, 1675, 125, 175); + spawn.mapRect(18425, 1700, 1050, 50); + spawn.mapRect(18475, 1750, 800, 25); + spawn.randomMob(12000, 2850, 0); + spawn.mapRect(10550, 2725, 5275, 1775); + spawn.mapRect(15700, 3850, 5950, 1050); + spawn.mapRect(8225, 2975, 4050, 1500); + spawn.mapRect(12100, -2300, 9350, 2925); + spawn.mapRect(14175, 350, 8725, 1075); + spawn.mapRect(20825, -2325, 3700, 2650); + spawn.mapRect(21450, 50, 4450, 5925); + spawn.mapRect(16325, 1125, 7175, 400); + spawn.mapRect(-875, -3775, 27375, 1625); + spawn.mapRect(-3250, -4000, 2925, 8075); + spawn.mapRect(8125, 4475, 18250, 7300); + spawn.mapRect(7125, 3975, 8775, 2800); + spawn.mapRect(-4300, -4475, 2300, 11350); + spawn.randomGroup(5835, -532, 0.4); + if (simulation.difficulty > 1) spawn.randomLevelBoss(18823, 2191); + spawn.secondaryBossChance(20217, 1913) + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + }; + level.customTopLayer = () => { }; + }, + dojo() { // By weird_pusheen + simulation.inGameConsole(`dojo by werid_pusheen, fixed by Cornbread 2100`) + const vanishes = []; + const smoofes = []; + const leftRotor = level.rotor(-550, 900, 950, 25); + leftRotor.frictionAir = 0.01; + var leftSchwoof = level.boost(-20, -60, -2000); + var rightSchwoof = level.button(2550, -50); + var rightSchwoofState = false; + var rightSchwoofLive = true; + spawn.mapRect(2513, -39, 200, 100); + var pathPoints = [ + [0, 0], // Index 0 is owned by M and is set to M's position during play + // this means that occasionally the boss will bonk M on the way to somewhere else, which gives it a chance to hurt M and gives the player a chance to hurt it + [250, -750], /* Left bases */ + [250, -2500], + [350, -1500], // Left doorway + [1150, -1500], // Home base + [1150, -2750], // Upper base + [1950, -1500], // Right doorway + [2050, -750], /* Right bases */ + [2050, -2500], + [-150, -250], // Left porthole + ]; + function isntIn(point, array) { + for (var x = 0; x < array.length; x++) { + if (point[0] == array[x][0] && point[1] == array[x][1]) { + return false; + } + } + return true; + } + function isObstructed(v1, v2) { + var ret = Matter.Query.ray(map, + { + x: v1[0], + y: v1[1], + }, + { + x: v2[0], + y: v2[1] + }).length != 0; + return ret; // Kinda-ish stolen from mob.js + } + function pythag(p1, p2) { + var dx = p1[0] - p2[0]; + var dy = p1[1] - p2[1]; + return Math.sqrt(dx * dx + dy * dy); + } + var path = undefined; // This is a stupid way to go about pathfinding code. I might even clean it up! + function pathFind(goalPoint, startPoint, curPath = []) { + var myPoint = startPoint; + if (curPath.length) { + myPoint = curPath[curPath.length - 1]; + } + if (path && (curPath.length >= path.length)) { // If we've already found a shorter or equal path, no reason to continue and waste CPU time + return; // Minimizes for HOP COUNT, not PATH LENGTH - path length was buggy + } + if (!isObstructed(myPoint, goalPoint)) { // If the line to the goal point ain't blocked by a map object, we've arrived! + path = [...curPath]; + path.push(goalPoint); + return; + } + pathPoints.forEach(testPoint => { + if (isntIn(testPoint, curPath)) { // If it's reusing points, there's clearly something wrong + if (!isObstructed(myPoint, testPoint)) { // If the line to the test point ain't blocked by a map object + var thing = [...curPath]; + thing.push(testPoint); + pathFind(goalPoint, startPoint, thing); // Branch to a valid test point + } + } + }); + } + level.setPosToSpawn(1200, 500); + level.exit.x = 51500; + level.exit.y = -1875; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); + level.defaultZoom = 1500; + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + + spawn.mapRect(-500, 0, 3300, 300); // Floor + spawn.mapRect(-100, -3000, 2500, 100); // Ceiling + spawn.mapRect(-200, -3000, 100, 2600); // Left wall + spawn.mapRect(2400, -3000, 100, 3000); // Right wall + + spawn.mapRect(500, -1000, 100, 500); /* obstruction blocks */ + smoofes.push(map[map.length - 1]); + spawn.mapRect(500, -2500, 100, 500); + smoofes.push(map[map.length - 1]); + spawn.mapRect(1700, -1000, 100, 500); + smoofes.push(map[map.length - 1]); + spawn.mapRect(1700, -2500, 100, 500); + smoofes.push(map[map.length - 1]); + + spawn.mapRect(-1000, 550, 200, 50); // Left chonky stepppp low + spawn.mapRect(-800, 300, 200, 50); // Left chonky stepppp high + spawn.mapVertex(-1000, 1200, "0 0 100 0 700 500 700 700 0 700"); // Left chonky + spawn.mapRect(3100, 550, 200, 50); // Right chonky stepppp low + spawn.mapRect(2900, 300, 200, 50); // Right chonky stepppp high + spawn.mapVertex(3300, 1200, "0 0 -100 0 -700 500 -700 700 0 700"); // Right chonky + const leftElevator = level.elevator(-1400 - 300, 1450, 300, 100, 500); + const rightElevator = level.elevator(-1400 + 5100, 1450, 300, 100, 500); + + spawn.mapRect(-150, -1700, 200, 50); + spawn.mapRect(400, -2050, 200, 50); + spawn.mapRect(1600, -1000, 200, 50); + + spawn.randomMob(1200, 700); + spawn.randomMob(600, 1000); + spawn.randomMob(1800, 1000); + spawn.randomMob(3200, 400); + spawn.randomMob(3000, 200); + spawn.randomMob(-900, 400); + spawn.randomMob(-700, 200); + spawn.randomMob(1200, 1000); + for (var i = 0; i < 4; i++) { + spawn.randomSmallMob(Math.random() * 600 - 600, Math.random() * 3000 - 400); + } + spawn.grenadier(-300, -1000); + spawn.grenadier(2600, -1000); + + spawn.mapRect(-1400, 1450, 5100, 100); // The True Floor + + const slime = level.hazard(-1250, 1400, 4800, 50); + slime.maxHeight = 600; + simulation.draw.body = function () { + ctx.beginPath(); + for (let i = 0, len = body.length; i < len; ++i) { + if (!body[i].hidden) { + let vertices = body[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + } + } + ctx.lineWidth = 2; + ctx.fillStyle = color.block; + ctx.fill(); + ctx.strokeStyle = color.blockS; + ctx.stroke(); + } // Override the old draw code to allow intelligent hiding of blocks - preferably this becomes official code because it's just a single added if statement and makes a lot of things cleaner and more intelligent + + const vanish = function (x, y, width, height) { // normal vanishes don't work well on my map for some reason, so I rewrote + x += width / 2; + y += height / 2; + const getVertices = function (bX, bY, bW, bH) { return [{ x: bX, y: bY, index: 0, isInternal: false }, { x: bX + bW, y: bY, index: 1, isInternal: false }, { x: bX + bW, y: bY + bH, index: 4, isInternal: false }, { x: bX, y: bY + bH, index: 3, isInternal: false }] }; + const cMask = cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + const vertices = getVertices(x, y, width, height); + const block = body[body.length] = Bodies.fromVertices(x, y, vertices, { + collisionFilter: { + category: cat.map, + mask: cMask + }, + isNoSetCollision: true, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + isNonStick: true, //this keep sporangium from sticking + isTouched: false, + cWidth: width, + hiddenCycle: 0, + isStatic: true, + query() { + if (this.cWidth <= 0) { + if (this.cWidth > -100) { + this.cWidth = -100; + Matter.Body.setVertices(this, vertices); + } + this.isTouched = false; + this.collisionFilter.mask = undefined; + this.hidden = true; + this.hiddenCycle++; + if (this.hiddenCycle > 100) { + if (Matter.Query.collides(this, [player]).length) { + this.hiddenCycle = 50; + } + else { + this.hiddenCycle = 0; + this.cWidth = width; + this.collisionFilter.mask = cMask; + this.hidden = false; + } + } + } + else if (this.isTouched) { + Matter.Body.setVertices(this, getVertices(x, y, this.cWidth, height * (this.cWidth / width))); + this.cWidth -= 3; + } + else if (Matter.Query.collides(this, [player]).length) { // Elseif short circuit avoids expensive collision detection + this.isTouched = true; + } + } + }); + return block; + }; + + vanishes.push(vanish(800, 800, 800, 50)); + vanishes.push(vanish(400, 1100, 400, 50)); + vanishes.push(vanish(1600, 1100, 400, 50)); + for (const vanishBlock of vanishes) Composite.add(engine.world, vanishBlock); + spawn.bodyRect(1700, 812, 300, 25, 1, { + collisionFilter: { + category: cat.body, + mask: cat.player | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet | cat.map + }, + isNoSetCollision: true, + isNotHoldable: true, + isNonStick: true, //this keep sporangium from sticking + restitution: 1, + friction: 0, + frictionAir: 0, + frictionStatic: 0, + query() { + Matter.Body.setAngularVelocity(this, 0); + Matter.Body.applyForce(this, this.position, { + x: 0, + y: -(this.position.y - 812) * 0.002 + }); + } + }); + const zigzag = body[body.length - 1]; + Matter.Body.applyForce(zigzag, zigzag.position, { + x: 0.1, + y: 0 + }); + var buttonWasDown = false; + level.customTopLayer = () => { + + } + level.custom = () => { + rightSchwoof.isUp = false; + level.exit.drawAndCheck(); + leftSchwoof.query(); + level.enter.draw(); + pathPoints[0][0] = m.pos.x; + pathPoints[0][1] = m.pos.y; + leftElevator.move(); + rightElevator.move(); + slime.query(); + zigzag.query(); + slime.levelRise(0.2); + for (var i = 0; i < vanishes.length; i++) { + vanishes[i].query(); + } + if (!rightSchwoofState) { + var math = m.pos.y < leftRotor.position.y; + Matter.Body.setAngularVelocity(leftRotor, (math ? 1 : -1) * Math.PI / 45); + } + if (rightSchwoofLive) { + rightSchwoof.query(); + rightSchwoof.draw(); + if (rightSchwoofState) { + ctx.fillStyle = "lightgreen"; + } + else { + ctx.fillStyle = "red"; + } + ctx.beginPath(); + ctx.arc(2615, -220, 40, 0, Math.PI * 2); + ctx.fill(); + } + if (rightSchwoof.isUp) { + buttonWasDown = true; + } + else if (buttonWasDown) { + buttonWasDown = false; + rightSchwoofState = !rightSchwoofState; + } + if (Matter.Query.collides(player, smoofes).length) { + Matter.Body.applyForce(player, player.position, { + x: 0, + y: -0.015 + }); + } + }; + + mobs.spawn(500, -500, 10, 100, "yellow"); /* TacticalBoss + Modes: + Spawn: + Pathfinds to a point above M and starts dropping mobs. Learns which mobs to drop to cause the most damage, of course. + Occasionally strikes at M. + Hide: + Pathfinds to the point furthest from M + Strike: + Pathfind really, really fast to M + Recharge: + Stop moving for a bit to "recharge" (this is so the player has a chance to hit it) + + It must always Hide or Recharge after Spawning or Striking. Which one it does is based on some factor I'll figure out. + Pathfinding is a hypersimplified algorithm with hard-coded "points" that it can travel between. M is one of these. + */ + var boss = mob[mob.length - 1]; + boss.isBoss = true; + boss.damageReduction = 0.2 + boss.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y); + level.exit.x = 2560; + level.exit.y = -90; + rightSchwoofLive = false; + }; + var spawnables = {}; + ["hopper", "stabber", "springer", "striker", "sneaker", "grower"].forEach((m) => { /* Used to be spawn.fullPickList, but some of those mobs don't do collision-only damage and would thus never be properly selected for */ + if (spawn[m]) { + spawnables[m] = { + fun: spawn[m], + name: m, + weight: 1 + } + } + }); + boss.stabCycle = 0; + boss.spawnCycle = 0; + function spawny() { + var totalWeight = 0; + Object.keys(spawnables).forEach(key => { + totalWeight += spawnables[key].weight; + }); + var cursorWeight = 0; + var choice = Math.random(); + var mC = undefined; + Object.values(spawnables).forEach((thing) => { + var lower = cursorWeight / totalWeight; + cursorWeight += thing.weight; + var upper = cursorWeight / totalWeight; + if ((choice > lower && choice <= upper) || !mC) { + mC = thing; + } + }); + mC.fun(boss.position.x, boss.position.y); + var sp = mob[mob.length - 1]; + sp.typeName = mC.name; + sp.onHit = () => { + spawnables[sp.typeName].weight += 1; + }; + var oldFun = sp.onDeath; + sp.onDeath = () => { /* Mobs that die are worth less */ + oldFun.call(sp); + spawnables[sp.typeName].weight -= 0.3; /* But not too much less */ + }; + } + boss.spawnDelay = 40; + boss.mode = "hide"; + boss.modeSwitch = -1; // Randomize mode immediately + boss.damageReduction = 0.1; + var oldOnHit = boss.onHit; + boss.onHit = () => { + boss.modeSwitch = -1; // After striking the player, always switch modes + oldOnHit.call(boss); //this is the line that is bugging <----- + }; + boss.do = () => { + path = undefined; + var pfGoal = [0, 0]; + boss.modeSwitch--; + if (boss.modeSwitch < 0) { + if (!boss.isShielded) { + spawn.shield(boss, boss.position.x, boss.position.y, 0.75); // Every time the mode switches, have a 75% chance to gain a new shield + } + if (boss.mode == "hide" || boss.mode == "recharge") { + if (Math.random() > 0.5) { + boss.mode = "spawn"; + } + else { + boss.mode = "strike"; + } + boss.modeSwitch = 600; + } + else { + if (boss.mode == "strike") { + boss.mode = "hide"; // Always hides after striking + } + else { + if (Math.random() > 0.5) { + boss.mode = "hide"; + } + else { + boss.mode = "recharge"; // same when it goes into recharge mode + spawn.shield(boss, boss.position.x, boss.position.y, 1); + } + } + boss.modeSwitch = 200; + } + } + if (boss.mode == "hide") { /* Find the furthest point from M and get to it */ + var longest = 0; + pathPoints.forEach(item => { + if (item[0] == 1150) { + return; + } + var iL = pythag(item, [m.pos.x, m.pos.y]); + if (iL > longest) { + longest = iL; + pfGoal = item; + } + }); + } + else if (boss.mode == "strike") { + pfGoal = pathPoints[0]; // Target M + } + else if (boss.mode == "spawn") { + pfGoal = pathPoints[4]; // Go to Home Base to spawn + } + if (boss.mode != "recharge") { + if (m.pos.x > 2350 || m.pos.x < -150 || m.pos.y > 50) { + boss.mode = "hide"; + } + pathFind(pfGoal, [boss.position.x, boss.position.y]); + if (!path) { + return; // If it couldn't pathfind, just drift + } + var goalX = path[0][0]; + var goalY = path[0][1]; + + var dX = goalX - boss.position.x; + var dY = goalY - boss.position.y; + var hyp = Math.sqrt(dX * dX + dY * dY); + Matter.Body.applyForce(boss, { + x: goalX, + y: goalY + }, { + x: dX / hyp * 0.04 * (boss.mode == "strike" ? 2 : 1), + y: dY / hyp * 0.04 * (boss.mode == "strike" ? 2 : 1)// - 0.005 + }); + } + if (boss.mode == "spawn") { + boss.stabCycle++; + if (boss.stabCycle > 25) { + if (Math.abs(dX) < 200 && dY > 0) { + Matter.Body.applyForce(boss, { + x: player.position.x, + y: player.position.y + }, { + x: 0, + y: 5 + }); + } + boss.stabCycle = 0; + } + boss.spawnCycle++; + if (boss.spawnCycle > boss.spawnDelay) { + spawny(); + boss.spawnDelay += 4; + boss.spawnCycle = 0; + } + } + }; + boss.showHealthBar = true; + powerUps.addResearchToLevel() //needs to run after mobs are spawned + }, + arena() { + simulation.inGameConsole(`arena by Whyisthisnotavalable`) + let genisis, genisisJumpSensor, genisisBody, genisisHead, genisisHeadSensor, genisisBodySensor; + let control = { left: false, right: false, up: false, down: false }; + const g = { + spawn() { + //load genisis in matter.js physic engine + // let vector = Vertices.fromPath("0 40 50 40 50 115 0 115 30 130 20 130"); //genisis as a series of vertices + let vertices = Vertices.fromPath("0,40, 50,40, 50,115, 30,130, 20,130, 0,115, 0,40"); //genisis as a series of vertices + genisisBody = Bodies.fromVertices(0, 0, vertices); + genisisJumpSensor = Bodies.rectangle(0, 46, 36, 6, { + //this sensor check if the genisis is on the ground to enable jumping + sleepThreshold: 99999999999, + isSensor: true + }); + vertices = Vertices.fromPath("16 -82 2 -66 2 -37 43 -37 43 -66 30 -82"); + genisisHead = Bodies.fromVertices(0, -55, vertices); //this part of the genisis lowers on crouch + genisisHeadSensor = Bodies.rectangle(0, -57, 48, 45, { + //senses if the genisis's head is empty and can return after crouching + sleepThreshold: 99999999999, + isSensor: true + }); + genisisBodySensor = Bodies.rectangle(0, 0, 70, 45, { + sleepThreshold: 99999999999, + isSensor: true + }); + genisis = Body.create({ + //combine genisisJumpSensor and genisisBody + parts: [genisisBody, genisisHead, genisisJumpSensor, genisisHeadSensor, genisisBodySensor], + inertia: Infinity, //prevents genisis rotation + friction: 0.002, + frictionAir: 0.001, + //frictionStatic: 0.5, + restitution: 0, + sleepThreshold: Infinity, + collisionFilter: { + group: 0, + category: cat.mob, + mask: cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield | cat.player | cat.bullet + }, + // death() { + // g.death(); + // } + }); + Matter.Body.setMass(genisis, g.mass); + Composite.add(engine.world, [genisis]); + }, + health: 1000, + maxHealth: 1000, //set in simulation.reset() + cycle: 600, //starts at 600 cycles instead of 0 to prevent bugs with g.history + lastKillCycle: 0, + lastHarmCycle: 0, + width: 50, + radius: 30, + eyeFillColor: null, + fillColor: null, //set by setFillColors + fillColorDark: null, //set by setFillColors + bodyGradient: null, //set by setFillColors + color: { + hue: 0, + sat: 0, + light: 50, + }, + setFillColors() { + g.fillColor = `hsl(${g.color.hue},${g.color.sat}%,${g.color.light}%)` + g.fillColorDark = `hsl(${g.color.hue},${g.color.sat}%,${g.color.light - 25}%)` + let grd = ctx.createLinearGradient(-30, 0, 30, 0); + grd.addColorStop(0, g.fillColorDark); + grd.addColorStop(1, g.fillColor); + g.bodyGradient = grd + }, + setFillColorsAlpha(alpha = 0.5) { + g.fillColor = `hsla(${g.color.hue},${g.color.sat}%,${g.color.light}%,${alpha})` + g.fillColorDark = `hsla(${g.color.hue},${g.color.sat}%,${g.color.light - 25}%,${alpha})` + let grd = ctx.createLinearGradient(-30, 0, 30, 0); + grd.addColorStop(0, g.fillColorDark); + grd.addColorStop(1, g.fillColor); + g.bodyGradient = grd + }, + height: 42, + yOffWhen: { + crouch: 22, + stand: 49, + jump: 70 + }, + defaultMass: 5, + mass: 5, + FxNotHolding: 0.015, + Fx: 0.016, //run Force on ground // + jumpForce: 0.64, + setMovement() { + // g.Fx = 0.08 / mass * tech.squirrelFx + // g.FxAir = 0.4 / mass / mass + g.Fx = tech.baseFx * g.fieldFx * tech.squirrelFx * (tech.isFastTime ? 1.5 : 1) / genisis.mass //base genisis mass is 5 + g.jumpForce = tech.baseJumpForce * g.fieldJump * tech.squirrelJump * (tech.isFastTime ? 1.13 : 1) / genisis.mass / genisis.mass //base genisis mass is 5 + }, + FxAir: 0.032, // 0.4/5/5 run Force in Air + yOff: 70, + yOffGoal: 70, + onGround: false, //checks if on ground or in air + lastOnGroundCycle: 0, //use to calculate coyote time + standingOn: undefined, + numTouching: 0, + crouch: false, + // isHeadClear: true, + spawnPos: { + x: 0, + y: 0 + }, + spawnVel: { + x: 0, + y: 0 + }, + pos: { + x: 0, + y: 0 + }, + yPosDifference: 24.2859, //genisis.position.y - g.pos.y //24.285923217549026 + // yPosDifferenceCrouched: -2.7140767824453604, + Sy: 0, //adds a smoothing effect to vertical only + Vx: 0, + Vy: 0, + friction: { + ground: 0.01, + air: 0.0025 + }, + airSpeedLimit: 125, // 125/mass/mass = 5 + angle: 0, + walk_cycle: 0, + stepSize: 0, + flipLegs: -1, + hip: { + x: 12, + y: 24 + }, + knee: { + x: 0, + y: 0, + x2: 0, + y2: 0 + }, + foot: { + x: 0, + y: 0 + }, + legLength1: 55, + legLength2: 45, + transX: 0, + transY: 0, + history: new Array(600), //[], //tracks the last second of genisis position + rewindCount: 0, //used with CPT + resetHistory() { + const set = { + position: { + x: genisis.position.x, + y: genisis.position.y, + }, + velocity: { + x: genisis.velocity.x, + y: genisis.velocity.y + }, + yOff: g.yOff, + angle: g.angle, + health: g.health, + energy: g.energy, + activeGun: b.activeGun + } + for (let i = 0; i < 600; i++) { //reset history + g.history[i] = set + } + }, + move() { + g.pos.x = genisis.position.x; + g.pos.y = genisisBody.position.y - g.yOff; + g.Vx = genisis.velocity.x; + g.Vy = genisis.velocity.y; + + //tracks the last 10s of genisis information + g.history.splice(g.cycle % 600, 1, { + position: { + x: genisis.position.x, + y: genisis.position.y, + }, + velocity: { + x: genisis.velocity.x, + y: genisis.velocity.y + }, + yOff: g.yOff, + angle: g.angle, + health: g.health, + energy: g.energy, + activeGun: b.activeGun + }); + // const back = 59 // 59 looks at 1 second ago //29 looks at 1/2 a second ago + // historyIndex = (g.cycle - back) % 600 + }, + targetX: 0, + targetY: 0, + transSmoothX: 0, + transSmoothY: 0, + lastGroundedPositionY: 0, + // mouseZoom: 0, + lookSmoothing: 0.07, //1 is instant jerky, 0.001 is slow smooth zoom, 0.07 is standard + look() { }, //set to lookDefault() + lookDefault() { + g.angle = Math.atan2( + g.targetY - g.pos.y, + g.targetX - g.pos.x + ); + // //smoothed mouse look translations + const scale = 0.8; + g.transSmoothX = canvas.width2 - g.pos.x - (simulation.mouse.x - canvas.width2) * scale; + g.transSmoothY = canvas.height2 - g.pos.y - (simulation.mouse.y - canvas.height2) * scale; + + g.transX += (g.transSmoothX - g.transX) * g.lookSmoothing; + g.transY += (g.transSmoothY - g.transY) * g.lookSmoothing; + }, + doCrouch() { + if (!g.crouch) { + g.crouch = true; + g.yOffGoal = g.yOffWhen.crouch; + if ((genisisHead.position.y - genisis.position.y) < 0) { + Matter.Body.setPosition(genisisHead, { + x: genisis.position.x, + y: genisis.position.y + 9.1740767 + }) + } + } + }, + undoCrouch() { + if (g.crouch) { + g.crouch = false; + g.yOffGoal = g.yOffWhen.stand; + if ((genisisHead.position.y - genisis.position.y) > 0) { + Matter.Body.setPosition(genisisHead, { + x: genisis.position.x, + y: genisis.position.y - 30.28592321 + }) + } + } + }, + hardLandCD: 0, + checkHeadClear() { + if (Matter.Query.collides(headSensor, map).length > 0) { + return false + } else { + return true + } + }, + buttonCD_jump: 0, //cool down for genisis buttons + jump() { + // if (!g.onGround) g.lastOnGroundCycle = 0 //g.cycle - tech.coyoteTime + g.buttonCD_jump = g.cycle + 20; //can't jump again until 20 cycles pass + //apply a fraction of the jump force to the body the genisis is jumping off of + Matter.Body.applyForce(g.standingOn, g.pos, { + x: 0, + y: g.jumpForce * 0.12 * Math.min(g.standingOn.mass, 5) + }); + + genisis.force.y = -g.jumpForce; //genisis jump force + Matter.Body.setVelocity(genisis, { //zero genisis y-velocity for consistent jumps + x: genisis.velocity.x, + y: Math.max(-10, Math.min(g.standingOn.velocity.y, 10)) //cap velocity contribution from blocks you are standing on to 10 in the vertical + }); + }, + groundControl() { + //check for crouch or jump + if (g.crouch) { + if (!(control.down) && g.checkHeadClear() && g.hardLandCD < g.cycle) g.undoCrouch(); + } else if (control.down || g.hardLandCD > g.cycle) { + g.doCrouch(); //on ground && not crouched and pressing s or down + } else if (control.up && g.buttonCD_jump + 20 < g.cycle && g.yOffWhen.stand > 23) { + g.jump() + } + + if (control.left) { + if (genisis.velocity.x > -2) { + genisis.force.x -= g.Fx * 1.5 + } else { + genisis.force.x -= g.Fx + } + // } + } else if (control.right) { + if (genisis.velocity.x < 2) { + genisis.force.x += g.Fx * 1.5 + } else { + genisis.force.x += g.Fx + } + } else { + const stoppingFriction = 0.92; //come to a stop if no move key is pressed + Matter.Body.setVelocity(genisis, { + x: genisis.velocity.x * stoppingFriction, + y: genisis.velocity.y * stoppingFriction + }); + } + //come to a stop if fast + if (genisis.speed > 4) { + const stoppingFriction = (g.crouch) ? 0.65 : 0.89; // this controls speed when crouched + Matter.Body.setVelocity(genisis, { + x: genisis.velocity.x * stoppingFriction, + y: genisis.velocity.y * stoppingFriction + }); + } + }, + airControl() { + //check for coyote time jump + // if (control.up && g.buttonCD_jump + 20 + tech.coyoteTime < g.cycle && g.yOffWhen.stand > 23 && g.lastOnGroundCycle + tech.coyoteTime > g.cycle) g.jump() + if (control.up && g.buttonCD_jump + 20 < g.cycle && g.yOffWhen.stand > 23 && g.lastOnGroundCycle + 5 > g.cycle) g.jump() + + //check for short jumps //moving up //recently pressed jump //but not pressing jump key now + if (g.buttonCD_jump + 60 > g.cycle && !(control.up) && g.Vy < 0) { + Matter.Body.setVelocity(genisis, { + //reduce genisis y-velocity every cycle + x: genisis.velocity.x, + y: genisis.velocity.y * 0.94 + }); + } + + if (control.left) { + if (genisis.velocity.x > -g.airSpeedLimit / genisis.mass / genisis.mass) genisis.force.x -= g.FxAir; // move genisis left / a + } else if (control.right) { + if (genisis.velocity.x < g.airSpeedLimit / genisis.mass / genisis.mass) genisis.force.x += g.FxAir; //move genisis right / d + } + }, + alive: true, + dmgScale: 1, //scales all damage, but not raw .dmg //set in levels.setDifficulty + defaultFPSCycle: 0, //tracks when to return to normal fps + immuneCycle: 0, //used in engine + collisionImmuneCycles: 30, + buttonCD: 0, //cool down for genisis buttons + drawLeg(stroke) { + // if (simulation.mouseInGame.x > g.pos.x) { + if (g.angle > -Math.PI / 2 && g.angle < Math.PI / 2) { + g.flipLegs = 1; + } else { + g.flipLegs = -1; + } + ctx.save(); + ctx.scale(g.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(g.hip.x, g.hip.y); + ctx.lineTo(g.knee.x, g.knee.y); + ctx.lineTo(g.foot.x, g.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 7; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(g.foot.x, g.foot.y); + ctx.lineTo(g.foot.x - 15, g.foot.y + 5); + ctx.moveTo(g.foot.x, g.foot.y); + ctx.lineTo(g.foot.x + 15, g.foot.y + 5); + ctx.lineWidth = 4; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(g.hip.x, g.hip.y, 11, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(g.knee.x + 7, g.knee.y); + ctx.arc(g.knee.x, g.knee.y, 7, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(g.foot.x + 6, g.foot.y); + ctx.arc(g.foot.x, g.foot.y, 6, 0, 2 * Math.PI); + ctx.fillStyle = g.fillColor; + ctx.fill(); + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + }, + calcLeg(cycle_offset, offset) { + g.hip.x = 12 + offset; + g.hip.y = 24 + offset; + //stepSize goes to zero if Vx is zero or not on ground (make m transition cleaner) + g.stepSize = 0.8 * g.stepSize + 0.2 * (7 * Math.sqrt(Math.min(9, Math.abs(g.Vx))) * g.onGround); + //changes to stepsize are smoothed by adding only a percent of the new value each cycle + const stepAngle = 0.034 * g.walk_cycle + cycle_offset; + g.foot.x = 2.2 * g.stepSize * Math.cos(stepAngle) + offset; + g.foot.y = offset + 1.2 * g.stepSize * Math.sin(stepAngle) + g.yOff + g.height; + const Ymax = g.yOff + g.height; + if (g.foot.y > Ymax) g.foot.y = Ymax; + + //calculate knee position as intersection of circle from hip and foot + const d = Math.sqrt((g.hip.x - g.foot.x) * (g.hip.x - g.foot.x) + (g.hip.y - g.foot.y) * (g.hip.y - g.foot.y)); + const l = (g.legLength1 * g.legLength1 - g.legLength2 * g.legLength2 + d * d) / (2 * d); + const h = Math.sqrt(g.legLength1 * g.legLength1 - l * l); + g.knee.x = (l / d) * (g.foot.x - g.hip.x) - (h / d) * (g.foot.y - g.hip.y) + g.hip.x + offset; + g.knee.y = (l / d) * (g.foot.y - g.hip.y) + (h / d) * (g.foot.x - g.hip.x) + g.hip.y; + }, + draw() { }, + drawDefault() { + ctx.fillStyle = g.fillColor; + g.walk_cycle += g.flipLegs * g.Vx; + ctx.save(); + ctx.globalAlpha = (g.immuneCycle < g.cycle) ? 1 : 0.5 //|| (g.cycle % 40 > 20) + ctx.translate(g.pos.x, g.pos.y); + g.calcLeg(Math.PI, -3); + g.drawLeg("#FFFFFF"); + g.calcLeg(0, 0); + g.drawLeg("#FFFFFF"); + ctx.rotate(g.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = g.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#FFFFFF"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + g.yOff = g.yOff * 0.85 + g.yOffGoal * 0.15; //smoothly move leg height towards height goal + }, + drawDamage() { + ctx.fillStyle = "red"; + g.walk_cycle += g.flipLegs * g.Vx; + ctx.save(); + ctx.globalAlpha = 0.7; + ctx.translate(g.pos.x, g.pos.y); + g.calcLeg(Math.PI, -3); + g.drawLeg("#FF0000"); + g.calcLeg(0, 0); + g.drawLeg("#FF0000"); + ctx.rotate(g.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = g.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#FF0000"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + g.yOff = g.yOff * 0.85 + g.yOffGoal * 0.15; //smoothly move leg height towards height goal + }, + damage(dmg) { + g.health -= dmg; + }, + rebirth() { + g.health = g.maxHealth; + genisis.collisionFilter.mask = cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield | cat.player | cat.bullet + }, + lastHealth: 1000, + drawHealth() { + let interpolated = this.lastHealth + (g.health - this.lastHealth) * 0.1; + + ctx.save(); + ctx.setTransform(1, 0, 0.2, 1, 0, 0); //slanted + ctx.fillStyle = "rgba(250, 100, 100, 0.3)"; + ctx.fillRect(canvas.width2 / 2, canvas.height2 / 10, canvas.width2, 30); + const grad = ctx.createLinearGradient(0, 0, canvas.width2, 0); + grad.addColorStop(0, "lightblue"); + grad.addColorStop(1, "crimson"); + + ctx.fillStyle = grad; + ctx.fillRect(canvas.width2 / 2, canvas.height2 / 10, canvas.width2 * interpolated / 1000, 30); + ctx.restore(); + + this.lastHealth = interpolated; + }, + genisisOnGroundCheck(event) { + //runs on collisions events + function enter() { + g.numTouching++; + if (!g.onGround) { + g.onGround = true; + if (g.crouch) { + if (g.checkHeadClear()) { + g.undoCrouch(); + } else { + g.yOffGoal = g.yOffWhen.crouch; + } + } else { + //sets a hard land where genisis stays in a crouch for a bit and can't jump + //crouch is forced in groundControl below + const momentum = genisis.velocity.y * genisis.mass //genisis mass is 5 so this triggers at 26 down velocity, unless the genisis is holding something + if (momentum > 130) { + g.doCrouch(); + g.yOff = g.yOffWhen.jump; + g.hardLandCD = g.cycle + Math.min(momentum / 6.5 - 6, 40) + //falling damage + if (tech.isFallingDamage && g.immuneCycle < g.cycle && momentum > 150) { + g.damage(Math.min(Math.sqrt(momentum - 133) * 0.01, 0.25)); + if (g.immuneCycle < g.cycle + g.collisionImmuneCycles) g.immuneCycle = g.cycle + g.collisionImmuneCycles; //genisis is immune to damage for 30 cycles + } + } else { + g.yOffGoal = g.yOffWhen.stand; + } + } + } + } + const pairs = event.pairs; + for (let i = 0, j = pairs.length; i != j; ++i) { + let pair = pairs[i]; + if (pair.bodyA === genisisJumpSensor) { + g.standingOn = pair.bodyB; //keeping track to correctly provide recoil on jump + if (g.standingOn.alive !== true) enter(); + } else if (pair.bodyB === genisisJumpSensor) { + g.standingOn = pair.bodyA; //keeping track to correctly provide recoil on jump + if (g.standingOn.alive !== true) enter(); + } + } + g.numTouching = 0; + }, + genisisOffGroundCheck(event) { + //runs on collisions events + const pairs = event.pairs; + for (let i = 0, j = pairs.length; i != j; ++i) { + if (pairs[i].bodyA === genisisJumpSensor || pairs[i].bodyB === genisisJumpSensor) { + if (g.onGround && g.numTouching === 0) { + g.onGround = false; + g.lastOnGroundCycle = g.cycle; + g.hardLandCD = 0 // disable hard landing + if (g.checkHeadClear()) { + if (g.crouch) { + g.undoCrouch(); + } + g.yOffGoal = g.yOffWhen.jump; + } + } + } + } + } + }; + function GenisisCollisionChecks(event) { + const pairs = event.pairs; + for (let i = 0, j = pairs.length; i != j; i++) { + for (let k = 0; k < bullet.length; k++) { + if (pairs[i].bodyA === bullet[k]) { + collideBullet(pairs[i].bodyB); + break; + } else if (pairs[i].bodyB === bullet[k]) { + collideBullet(pairs[i].bodyA); + break; + } + + function collideBullet(obj) { + if ( + g.immuneCycle < g.cycle && + (obj === genisisBody || obj === genisisHead) + ) { + let dmg = Math.sqrt(Math.abs(0.000025 * Math.sqrt((bullet[k].mass + Math.sqrt(Vector.magnitude(bullet[k].velocity)) * 0.0000125)))); + g.damage(dmg); + return; + } + } + } + for (let k = 0; k < mob.length; k++) { + if (mob[k].alive) { + if (pairs[i].bodyA === mob[k]) { + collideMob(pairs[i].bodyB); + break; + } else if (pairs[i].bodyB === mob[k]) { + collideMob(pairs[i].bodyA); + break; + } + + function collideMob(obj) { + //genisis + mob collision + if ( + g.immuneCycle < g.cycle && + (obj === genisisBody || obj === genisisHead) && + !mob[k].isSlowed && !mob[k].isStunned + ) { + let dmg = Math.max(0.025 * Math.sqrt(mob[k].mass), 0.05); + // if (g.isCloak) dmg *= 0.5 + if (tech.isRewindAvoidDeath && g.energy > 0.85 * Math.min(1, g.maxEnergy) && dmg > 0.01) { //CPT reversal runs in g.damage, but it stops the rest of the collision code here too + g.damage(dmg); + return + } + g.damage(dmg); + + if (tech.isCollisionRealitySwitch && g.alive) { + g.switchWorlds() + simulation.trails() + simulation.inGameConsole(`simulation.amplitude = ${Math.random()}`); + } + if (tech.isPiezo) g.energy += 20.48; + if (tech.isCouplingNoHit && g.coupling > 0) { + g.couplingChange(-3) + + const unit = Vector.rotate({ x: 1, y: 0 }, 6.28 * Math.random()) + let where = Vector.add(g.pos, Vector.mult(unit, 17)) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 22, + color: 'rgba(0, 171, 238, 0.33)', + time: 8 + }); + where = Vector.add(g.pos, Vector.mult(unit, 60)) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 18, + color: 'rgba(0, 171, 238, 0.5)', + time: 16 + }); + where = Vector.add(g.pos, Vector.mult(unit, 100)) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 14, + color: 'rgba(0, 171, 238, 0.6)', + time: 24 + }); + where = Vector.add(g.pos, Vector.mult(unit, 135)) + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 10, + color: 'rgba(0, 171, 238, 0.7)', + time: 32 + }); + // simulation.drawList.push({ //add dmg to draw queue + // x: g.pos.x, + // y: g.pos.y, + // radius: 150, + // color: 'rgba(0, 171, 238, 0.33)', + // time: 6 + // }); + // simulation.drawList.push({ //add dmg to draw queue + // x: g.pos.x, + // y: g.pos.y, + // radius: 75, + // color: 'rgba(0, 171, 238, 0.5)', + // time: 16 + // }); + // simulation.drawList.push({ //add dmg to draw queue + // x: g.pos.x, + // y: g.pos.y, + // radius: 25, + // color: 'rgba(0, 171, 238, 0.75)', + // time: 25 + // }); + } + if (mob[k].onHit) mob[k].onHit(); + if (g.immuneCycle < g.cycle + g.collisionImmuneCycles) g.immuneCycle = g.cycle + g.collisionImmuneCycles; //genisis is immune to damage for 30 cycles + //extra kick between genisis and mob //this section would be better with forces but they don't work... + let angle = Math.atan2(genisis.position.y - mob[k].position.y, genisis.position.x - mob[k].position.x); + Matter.Body.setVelocity(genisis, { + x: genisis.velocity.x + 8 * Math.cos(angle), + y: genisis.velocity.y + 8 * Math.sin(angle) + }); + Matter.Body.setVelocity(mob[k], { + x: mob[k].velocity.x - 8 * Math.cos(angle), + y: mob[k].velocity.y - 8 * Math.sin(angle) + }); + + if (tech.isAnnihilation && !mob[k].shield && !mob[k].isShielded && !mob[k].isBoss && mob[k].isDropPowerUp && g.energy > 0.1 && mob[k].damageReduction > 0) { + g.energy -= 0.1 //* Math.max(g.maxEnergy, g.energy) //0.33 * g.energy + if (g.immuneCycle === g.cycle + g.collisionImmuneCycles) g.immuneCycle = 0; //genisis doesn't go immune to collision damage + mob[k].death(); + simulation.drawList.push({ //add dmg to draw queue + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: Math.sqrt(dmg) * 500, + color: "rgba(255,0,255,0.2)", + time: simulation.drawTime + }); + } else { + simulation.drawList.push({ //add dmg to draw queue + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + } + // return; + // } + } + } + } + } + } + } + g.spawn(); + Matter.Body.setPosition(genisis, { + x: 7875, + y: -2530 + }) + let isUsingSwordMod = false; + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].name === 'size-weight illusion') { //to detect if the player is using the sword mod so that it won't mess up their mod. The sword mod adds this tech so if it is detected then the sword won't be removed from the gun array //Landgreen, don't add a tech with the same name + isUsingSwordMod = true; + } + } + if (!isUsingSwordMod) { + const e = { + name: "sword", + descriptionFunction() { return `swing a sword that lifesteals health
drains health instead of ammunition
doesn't use ammo` }, + ammo: Infinity, + ammoPack: Infinity, + defaultAmmoPack: Infinity, + have: false, + cycle: 0, + sword: undefined, + swordArray: [], + bladeSegments: undefined, + bladeTrails: [], + angle: 0, + constraint: undefined, + charge: 0, + angle2: 0, + fire() { }, + do() { + if (this.sword && this.cycle < 1) { + this.angle2 = Math.atan2(this.sword.position.y - m.pos.y, this.sword.position.x - m.pos.x); + } + if (this.sword) { + this.cycle++; + } + this.normalFire(); + this.renderDefault(); + this.collision(); + }, + normalFire() { + if (this.constraint) { + this.constraint.pointA = player.position; + } + if (tech.isStabSword && !m.crouch && this.cycle > 0 && this.stabStatus) { + if (this.sword) { + this.stabStatus = false; + if (tech.isEnergyHealth) { + m.energy = 0.01; + m.immuneCycle = m.cycle + 30; + } + this.cycle = 0; + Matter.Body.setAngularVelocity(this.sword, 0); + Composite.remove(engine.world, this.sword); + this.sword.parts.forEach(part => { + Composite.remove(engine.world, part); + const index = bullet.indexOf(part); + if (index !== -1) { + bullet.splice(index, 1); + } + }); + this.sword = undefined; + if (this.constraint) { + Composite.remove(engine.world, this.constraint); + this.constraint = undefined; + } + this.bladeTrails = []; + m.fireCDcycle = 0; + } + } + + if (input.fire && (tech.isEnergyHealth ? m.energy >= 0.11 : m.health >= 0.11)) { + if (tech.isEnergyHealth) { + m.energy -= 0.004; + } else { + m.health -= 0.001; + m.displayHealth(); + } + } + if (input.fire && (tech.isEnergyHealth ? m.energy >= 0.11 : m.health >= 0.11)) { + if (!this.sword && b.guns[b.activeGun].name === 'sword') { + ({ sword: this.sword, bladeSegments: this.bladeSegments } = this.createAndSwingSword()); + this.angle = m.angle; + } + } + if (this.sword && !input.fire) { + this.cycle = 0; + Matter.Body.setAngularVelocity(this.sword, 0); + player.force.x *= 0.01; + player.force.y *= 0.01; + Composite.remove(engine.world, this.sword); + this.sword.parts.forEach(part => { + Composite.remove(engine.world, part); + const index = bullet.indexOf(part); + if (index !== -1) { + bullet.splice(index, 1); + } + }); + this.sword = undefined; + if (this.constraint) { + Composite.remove(engine.world, this.constraint); + this.constraint = undefined; + } + this.bladeTrails = []; + m.fireCDcycle = m.cycle + 10; + } else { + if (this.sword && (tech.isEnergyHealth ? m.energy >= 0.11 : m.health >= 0.11)) { + let handle; + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].customName == "handle") { + handle = bullet[i]; + } + } + if (tech.infinityEdge) { + const newSize = Math.sqrt(0.5 * m.health) + 1; + Matter.Body.scale(this.sword, newSize * (1 / (this.sword.scale == undefined ? 1 : this.sword.scale)), newSize * (1 / (this.sword.scale == undefined ? 1 : this.sword.scale)), handle.position); + this.sword.scale = newSize; + } + if (!(this.angle > -Math.PI / 2 && this.angle < Math.PI / 2)) { + Matter.Body.setAngularVelocity(this.sword, -Math.PI * 0.1); + } else { + Matter.Body.setAngularVelocity(this.sword, Math.PI * 0.1); + } + if (tech.sizeIllusion) { + player.force.x += Math.cos(m.angle) * player.mass / 500; + player.force.y += Math.sin(m.angle) * player.mass / 500; + } + if (!this.constraint && (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2)) { + this.constraint = Constraint.create({ + pointA: player.position, + bodyB: this.sword, + pointB: { x: -9, y: ((handle.position.y - this.sword.position.y)) }, + stiffness: (tech.infinityEdge ? 0.05 : 0.1), + damping: 0.001815, + length: 0, + + }); + Composite.add(engine.world, this.constraint); + } else if (!this.constraint) { + this.constraint = Constraint.create({ + pointA: player.position, + bodyB: this.sword, + pointB: { x: 9, y: ((handle.position.y - this.sword.position.y)) }, + stiffness: (tech.infinityEdge ? 0.05 : 0.1), + damping: 0.001815, + length: 0, + }); + Composite.add(engine.world, this.constraint); + } + } else if (this.sword) { + if (tech.isEnergyHealth) { + m.energy = 0.01; + m.immuneCycle = m.cycle + 30; + } + this.cycle = 0; + Matter.Body.setAngularVelocity(this.sword, 0); + player.force.x *= 0.01; + player.force.y *= 0.01; + Composite.remove(engine.world, this.sword); + this.sword.parts.forEach(part => { + Composite.remove(engine.world, part); + const index = bullet.indexOf(part); + if (index !== -1) { + bullet.splice(index, 1); + } + }); + this.sword = undefined; + if (this.constraint) { + Composite.remove(engine.world, this.constraint); + this.constraint = undefined; + } + this.bladeTrails = []; + m.fireCDcycle = 0; + } + } + }, + createAndSwingSword(x = player.position.x, y = player.position.y, angle = m.angle) { + const handleWidth = 20; + const handleHeight = 150; + const handle = Bodies.rectangle(x, y, handleWidth, handleHeight, spawn.propsIsNotHoldable); + bullet[bullet.length] = handle; + handle.customName = "handle"; + bullet[bullet.length - 1].do = () => { }; + const pommelWidth = 30; + const pommelHeight = 40; + const pommelVertices = [ + { x: x, y: y + handleHeight / 2 + pommelHeight / 2 }, + { x: x + pommelWidth / 2, y: y + handleHeight / 2 }, + { x: x, y: y + handleHeight / 2 - pommelHeight / 2 }, + { x: x - pommelWidth / 2, y: y + handleHeight / 2 }, + ]; + const pommel = Bodies.fromVertices(x, y + handleHeight / 2, pommelVertices, spawn.propsIsNotHoldable); + bullet[bullet.length] = pommel; + bullet[bullet.length - 1].do = () => { }; + if (tech.soundSword) { + bullet[bullet.length - 1].draw = () => { }; + } + // Blade setup + const bladeWidth = 100 * (tech.soundSword ? 3 : 1); + const bladeHeight = 20 * (tech.soundSword ? 3 : 1); + const numBlades = 15; + const extensionFactor = 5; + const bladeSegments = []; + + if ((angle > -Math.PI / 2 && angle < Math.PI / 2)) { + for (let i = 0; i < numBlades; i++) { + const extensionFactorFraction = (i / (numBlades - 1)) * extensionFactor; + const bladeX = x + i * (bladeWidth / 20); + const bladeY = y - handleHeight / 2 - i * (bladeHeight / 4.5) * extensionFactor; + + const vertices = [ + { x: bladeX, y: bladeY - bladeHeight / 2 }, + { x: bladeX + bladeWidth / 2, y: bladeY + bladeHeight / 2 }, + { x: bladeX - bladeWidth / 2, y: bladeY + bladeHeight / 2 }, + { x: bladeX, y: bladeY - bladeHeight / 2 + 10 }, + ]; + + const blade = Bodies.fromVertices(bladeX, bladeY, vertices, spawn.propsIsNotHoldable); + bullet[bullet.length] = blade; + bullet[bullet.length - 1].do = () => { }; + if (tech.soundSword) { + bullet[bullet.length - 1].draw = () => { }; + } + Matter.Body.rotate(blade, -Math.sin(i * (Math.PI / 270) * 15)); + bladeSegments.push(blade); + } + } else { + for (let i = 0; i < numBlades; i++) { + const extensionFactorFraction = (i / (numBlades - 1)) * extensionFactor; + const mirroredBladeX = x - i * (bladeWidth / 20); + const mirroredBladeY = y - handleHeight / 2 - i * (bladeHeight / 4.5) * extensionFactor; + const mirroredVertices = [ + { x: mirroredBladeX, y: mirroredBladeY - bladeHeight / 2 }, + { x: mirroredBladeX + bladeWidth / 2, y: mirroredBladeY + bladeHeight / 2 }, + { x: mirroredBladeX - bladeWidth / 2, y: mirroredBladeY + bladeHeight / 2 }, + { x: mirroredBladeX, y: mirroredBladeY - bladeHeight / 2 + 10 }, + ]; + const mirroredBlade = Bodies.fromVertices(mirroredBladeX, mirroredBladeY, mirroredVertices, spawn.propsIsNotHoldable); + bullet[bullet.length] = mirroredBlade; + bullet[bullet.length - 1].do = () => { }; + if (tech.soundSword) { + bullet[bullet.length - 1].draw = () => { }; + } + Matter.Body.rotate(mirroredBlade, Math.sin(i * (Math.PI / 270) * 15)); + bladeSegments.push(mirroredBlade); + } + } + bladeSegments.push(pommel); + const sword = Body.create({ + parts: [handle, ...bladeSegments], + }); + + Composite.add(engine.world, sword); + Matter.Body.setPosition(sword, { x, y }); + + sword.collisionFilter.category = cat.bullet; + sword.collisionFilter.mask = cat.mobBullet | cat.powerup | cat.mob; + Body.scale(sword, -1, 1, { x, y }); + + return { sword, bladeSegments }; + }, + renderDefault() { + if (this.sword) { + for (let i = 0; i < this.bladeSegments.length; i++) { + const blade = this.bladeSegments[i]; + const trail = this.bladeTrails[i] || []; + const vertices = blade.vertices.map(vertex => ({ x: vertex.x, y: vertex.y })); + trail.push(vertices); + if (trail.length > 10) { + trail.shift(); + } + this.bladeTrails[i] = trail; + } + + for (let i = 0; i < this.bladeTrails.length; i++) { + const trail = this.bladeTrails[i]; + + const alphaStep = 1 / trail.length; + let alpha = 0; + + for (let j = 0; j < trail.length; j++) { + const vertices = trail[j]; + ctx.beginPath(); + ctx.moveTo(vertices[0].x, vertices[0].y); + + for (let k = 1; k < vertices.length; k++) { + ctx.lineTo(vertices[k].x, vertices[k].y); + }; + + alpha += alphaStep; + ctx.closePath(); + if (tech.isEnergyHealth) { + const eyeColor = m.fieldMeterColor; + const r = eyeColor[1]; + const g = eyeColor[2]; + const b = eyeColor[3]; + const color = `#${r}${r}${g}${g}${b}${b}${Math.round(alpha * 255).toString(16).padStart(2, '0')}`; + ctx.fillStyle = color; + } else { + ctx.fillStyle = `rgba(220, 20, 60, ${alpha})`; + } + ctx.fill(); + } + } + for (let i = 0; i < this.bladeSegments.length; i++) { + ctx.beginPath(); + ctx.lineJoin = "miter"; + ctx.miterLimit = 100; + ctx.strokeStyle = tech.isEnergyHealth ? m.fieldMeterColor : tech.isAmmoSword ? "#c0c0c0" : "crimson"; + ctx.lineWidth = 5; + ctx.fillStyle = "black"; + ctx.moveTo(this.bladeSegments[i].vertices[0].x, this.bladeSegments[i].vertices[0].y); + for (let j = 0; j < this.bladeSegments[i].vertices.length; j++) { + ctx.lineTo(this.bladeSegments[i].vertices[j].x, this.bladeSegments[i].vertices[j].y) + }; + ctx.closePath(); + ctx.stroke(); + ctx.fill(); + ctx.lineJoin = "round"; + ctx.miterLimit = 10; + } + } + }, + collision() { + if (this.sword) { + for (let i = 0; i < mob.length; i++) { + if (Matter.Query.collides(this.sword, [mob[i]]).length > 0) { + const dmg = m.dmgScale * Math.sqrt(this.sword.speed) * (tech.sizeIllusion ? 1.1 : 1) * (tech.isStabSword ? 1.5 : 1) * (tech.infinityEdge ? 1.1 : 1); + if (!tech.soundSword) { + if (m.health < m.maxHealth) { + if (tech.isEnergyHealth) { + m.energy += 0.04; + } else { + m.health += 0.01 * (dmg - mob[i].health); + m.displayHealth(); + } + } else { + if (tech.isEnergyHealth) { + m.energy += 0.04; + } else { + m.health = m.maxHealth; + m.displayHealth(); + } + } + } + mob[i].damage(dmg, true); + simulation.drawList.push({ + x: mob[i].position.x, + y: mob[i].position.y, + radius: Math.abs(Math.log(dmg * this.sword.speed) * 40 * mob[i].damageReduction + 3), + color: (tech.soundSword ? "rgba(0, 0, 0, 0.3)" : simulation.mobDmgColor), + time: simulation.drawTime + }); + break + } + } + if (Matter.Query.collides(this.sword, [genisis]).length > 0) { + m.damage(-0.0142) //balanced! + } + } + } + }; + b.guns.push(e); + const gunArray = b.guns.filter( + (obj, index, self) => + index === self.findIndex((item) => item.name === obj.name) + ); + b.guns = gunArray; + } else { + simulation.inGameConsole(`Thank you for using my sword mod
I'll save you the trouble of killing genisis
g.damage(Infinity)
`); + g.damage(Infinity); + } + simulation.inGameConsole(`arena by Richard0820`); + let index = 0; + let index2 = 0; + let { sword: sword, bladeSegments: bladeSegments } = createSword(); + const door = level.door(-950, -3000, 400, 4000, 2000, 10); + const door2 = level.door(550, -3000, 400, 4000, 2000, 10); + level.setPosToSpawn(-7900, -2550); //normal spawn + level.exit.x = 7875; + level.exit.y = -2530; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 2000 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#987654"; + color.map = "#765432" //custom map color + color.block = "#876543"; + door.isClosing = true; + door2.isClosing = true; + for (let i = 0; i < 5; i++) { + powerUps.spawn(-6075, -2000, "heal"); + } + let bladeTrails = []; + let isOwned = false; + class Particle { + constructor() { + this.x = player.position.x + Math.random() * 10000 - 5000; + this.y = player.position.y + Math.random() * 10000 - 5000; + this.vx = 0; + this.vy = 0; + this.accelX = 0; + this.accelY = 0; + this.life = 2000; + this.alpha = 1; + this.size = 8; + } + + update() { + this.vx += this.accelX; + this.vy += this.accelY; + this.x += this.vx; + this.y += this.vy; + + if (this.x < player.position.x - 5000 || this.x > player.position.x + 5000 || + this.y < player.position.y - 5000 || this.y > player.position.y + 5000) { + this.reset(); + } + } + + reset() { + this.x = player.position.x + Math.random() * 10000 - 5000; + this.y = player.position.y + Math.random() * 10000 - 5000; + this.vx = 0; + this.vy = 0; + this.life = Math.random() * 1000 + 1000; + this.maxLife = this.life; + } + + draw() { + ctx.beginPath(); + ctx.fillStyle = `rgba(255, 255, 255, ${this.alpha})`; + ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2); + ctx.fill(); + ctx.closePath(); + } + + isAlive() { + return this.life >= 0; + } + } + class ParticleSystem { + constructor() { + this.particles = []; + this.updateHandler = undefined; + } + + addParticle(particle) { + this.particles.push(particle); + } + + update(deltaTime = 0) { + this.particles.forEach(particle => { + particle.update(deltaTime); + this.updateHandler && this.updateHandler(particle); + }); + } + + onUpdate(fn) { + this.updateHandler = fn; + } + } + let system = new ParticleSystem(); + for (let i = 0; i < 200; i++) { + let particle = new Particle(); + system.addParticle(particle); + } + system.onUpdate((particle) => { + if (!particle.isAlive()) { + particle.reset(); + } + + particle.life -= 10; + particle.accelX = (Math.random() - 0.5) * 0.02; + particle.accelY = (Math.random() - 0.5) * 0.02; + + if (particle.life >= particle.maxLife / 2) { + particle.alpha = 1 - (particle.life / particle.maxLife); + } else { + particle.alpha = particle.life / particle.maxLife; + } + + particle.update(); + }); + function update() { + system.update(); + } + function draw() { + system.particles.forEach(particle => particle.draw()); + } + for (let i = 0; i < system.particles.length; i++) { + system.particles[i].life = 0; + } + level.custom = () => { + update(); + draw(); + for (let i = 0, len = b.guns.length; i < len; i++) { + if (b.guns[i].name === "sword" && b.guns[i].have) { + isOwned = true; + } + } + Matter.Body.setPosition(sword, { x: -3950, y: -275 - (Math.sin(simulation.cycle / 100) * 50) }); + Matter.Body.setAngularVelocity(sword, 0); + door.openClose(); + door2.openClose(); + if (Matter.Collision.collides(sword, player) && index <= 0 || isOwned) { + bladeTrails = []; + bladeSegments = []; + Composite.remove(engine.world, sword); + sword.parts.forEach(part => { + Composite.remove(engine.world, part); + const index = bullet.indexOf(part); + if (index !== -1) { + bullet.splice(index, 1); + } + }); + b.giveGuns("sword"); + door.isClosing = false; + door2.isClosing = false; + index++; + } + const oldLevel = level.onLevel; + + level.exit.drawAndCheck(); + + level.enter.draw(); + if (tech.isEnergyHealth) { + ctx.beginPath(); + const gradient = ctx.createRadialGradient(-3950, 0, 5, -3950, 0, 350 + Math.sin(simulation.cycle * 0.15) * 0.1); + gradient.addColorStop(0, m.fieldMeterColor); + gradient.addColorStop(0.9, "transparent"); + // gradient.addColorStop(1, "darkgray"); + ctx.fillStyle = gradient; + ctx.strokeStyle = "transparent"; + ctx.fillRect(-4000, -350, 100, 350); + ctx.fill(); + ctx.stroke(); + } else { + ctx.beginPath(); + const gradient = ctx.createLinearGradient(-3500, 0, -3500, -350 + Math.sin(simulation.cycle * 0.15) * 0.1); + gradient.addColorStop(0, "crimson"); + gradient.addColorStop(0.9, "transparent"); + // gradient.addColorStop(1, "darkgray"); + ctx.fillStyle = gradient; + ctx.strokeStyle = "transparent"; + ctx.fillRect(-4000, -350, 100, 350); + ctx.fill(); + ctx.stroke(); + } + if (player.position.x > -4000 && player.position.x < -3900 && player.position.y > -350 && player.position.y < 0) { + player.force.y -= 0.03; + } + + // if (player.position.x > level.exit.x && player.position.x < level.exit.x + 100 && player.position.y > level.exit.y - 150 && player.position.y < level.exit.y - 0 && player.velocity.y < .15 && index2 == 0 && !isUsingSwordMod) { + if (level.onLevel !== oldLevel && simulation.clearNow && !isUsingSwordMod) { + b.removeGun("sword"); //completely removing the stuff (if you leave properly through the door) + for (let i = 0, len = b.guns.length; i < len; i++) { + if (b.guns[i].name === "sword") { + b.guns.splice(i, 1); + break; + } + } + index2++; + setTimeout(() => { simulation.inGameConsole(`If you want to keep this sword, visit https://github.com/Whyisthisnotavalable/n-scythe. The sword is there.`) }, 1000) + } + for (let i = 0; i < bladeSegments.length; i++) { + const blade = bladeSegments[i]; + const trail = bladeTrails[i] || []; + const vertices = blade.vertices.map(vertex => ({ x: vertex.x, y: vertex.y })); + trail.push(vertices); + if (trail.length > 10) { + trail.shift(); + } + bladeTrails[i] = trail; + } + + for (let i = 0; i < bladeTrails.length; i++) { + const trail = bladeTrails[i]; + + const alphaStep = 1 / trail.length; + let alpha = 0; + + for (let j = 0; j < trail.length; j++) { + const vertices = trail[j]; + ctx.beginPath(); + ctx.moveTo(vertices[0].x, vertices[0].y); + + for (let k = 1; k < vertices.length; k++) { + ctx.lineTo(vertices[k].x, vertices[k].y); + }; + + alpha += alphaStep; + ctx.closePath(); + if (tech.isEnergyHealth) { + const eyeColor = m.fieldMeterColor; + const r = eyeColor[1]; + const g = eyeColor[2]; + const b = eyeColor[3]; + const color = `#${r}${r}${g}${g}${b}${b}${Math.round(alpha * 255).toString(16).padStart(2, '0')}`; + ctx.fillStyle = color; + } else { + ctx.fillStyle = `rgba(220, 20, 60, ${alpha})`; + } + ctx.fill(); + } + } + for (let i = 0; i < bladeSegments.length; i++) { + ctx.beginPath(); + ctx.lineJoin = "miter"; + ctx.miterLimit = 100; + ctx.strokeStyle = tech.isEnergyHealth ? m.fieldMeterColor : tech.isAmmoSword ? "#c0c0c0" : "crimson"; + ctx.lineWidth = 5; + ctx.fillStyle = "black"; + ctx.moveTo(bladeSegments[i].vertices[0].x, bladeSegments[i].vertices[0].y); + for (let j = 0; j < bladeSegments[i].vertices.length; j++) { + ctx.lineTo(bladeSegments[i].vertices[j].x, bladeSegments[i].vertices[j].y) + }; + ctx.closePath(); + ctx.stroke(); + ctx.fill(); + ctx.lineJoin = "round"; + ctx.miterLimit = 10; + } + if (bladeSegments.length) { + ctx.beginPath(); + ctx.lineJoin = "miter"; + ctx.miterLimit = 100; + ctx.strokeStyle = tech.isEnergyHealth ? m.fieldMeterColor : tech.isAmmoSword ? "#c0c0c0" : "crimson"; + ctx.lineWidth = 5; + ctx.fillStyle = "black"; + ctx.moveTo(sword.parts[1].vertices[0].x, sword.parts[1].vertices[0].y); + for (let j = 0; j < sword.parts[1].vertices.length; j++) { + ctx.lineTo(sword.parts[1].vertices[j].x, sword.parts[1].vertices[j].y) + }; + ctx.closePath(); + ctx.fill(); + ctx.lineJoin = "round"; + ctx.miterLimit = 10; + } + }; + level.customTopLayer = () => { }; + simulation.ephemera.push({ + name: "genesis", + death: false, + pwuspawn: 0, + do() { + if (this.death === true) { + b.explosion(g.pos, 200 * Math.random(), "#000000") + setTimeout(() => { + if (this.pwuspawn === 0) { + powerUps.spawnBossPowerUp(g.pos.x, g.pos.y) + this.pwuspawn++; + } + simulation.removeEphemera(this.name); + simulation.removeEphemera("genisisScythe"); + }, 1000); + } + if (g.health >= 0) { + if (g.health < g.maxHealth) { + g.health++; + } + const dist = Matter.Vector.magnitudeSquared(Matter.Vector.sub(genisis.position, player.position)); + const time = Math.sqrt(dist) / 60; + g.alive = true; + g.targetX = m.pos.x + player.velocity.x * time; + g.targetY = m.pos.y + player.velocity.y * time; + } else { + this.death = true; + g.alive = false; + } + if (g.alive) { + g.cycle++; + g.move() + g.lookDefault(); + g.drawDefault(); + g.drawHealth(); + genisis.force.y += g.mass * simulation.g + g.setFillColors(); + control.right = g.angle > -Math.PI * 2 / 5 && g.angle < Math.PI * 2 / 5; + control.left = g.angle > Math.PI * 3 / 5 || g.angle < -Math.PI * 3 / 5; + control.down = g.angle > Math.PI * 3 / 10 && g.angle < Math.PI * 7 / 10; + if (Matter.Query.collides(genisis, body).length || Matter.Query.collides(genisisHead, map).length || Matter.Query.collides(genisisBodySensor, map).length && !control.down) { + if (g.buttonCD_jump < g.cycle) { + g.jump(); + } + } + control.up = g.angle > -Math.PI * 6 / 10 && g.angle < -Math.PI * 4 / 10; + + if (g.onGround) { + g.groundControl() + } else { + g.airControl() + } + + if (g.pos.y > simulation.fallHeight) { + Matter.Body.setPosition(genisis, { + x: level.exit.x, + y: level.exit.y + }) + } + } else { + genisis.collisionFilter.mask = cat.map | cat.body; + Matter.Body.setPosition(genisis, { + x: 0, + y: 0 + }) + } + + if (simulation.testing) { + ctx.beginPath(); + let bodyDraw = genisisJumpSensor.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(255, 0, 0, 0.5)"; + ctx.fill(); + + ctx.beginPath(); + bodyDraw = genisisBody.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(0, 255, 255, 0.25)"; + ctx.fill(); + + ctx.beginPath(); + bodyDraw = genisisHead.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(255, 255, 0, 0.4)"; + ctx.fill(); + + ctx.beginPath(); + bodyDraw = genisisHeadSensor.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(0, 0, 255, 0.25)"; + ctx.fill(); + + ctx.beginPath(); + bodyDraw = genisisBodySensor.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(255, 0, 255, 0.25)"; + ctx.fill(); + } + + Events.on(engine, "collisionStart", function (event) { + g.genisisOnGroundCheck(event); + GenisisCollisionChecks(event); + }); + Events.on(engine, "collisionActive", function (event) { + g.genisisOnGroundCheck(event); + }); + Events.on(engine, "collisionEnd", function (event) { + g.genisisOffGroundCheck(event); + }); + } + }) + let evo = { + isLongBlade: true, + isScytheRange: true, + scytheRange: 3, + isScytheRad: false, + scytheRad: 0, + isDoubleScythe: false, + isPhaseScythe: false, + isMeleeScythe: false, + isStunScythe: false, + }; + simulation.ephemera.push({ + name: "genisisScythe", + cycle: 0, + scythe: undefined, + bladeSegments: undefined, + bladeTrails: [], + angle: 0, + constraint: undefined, + fireCD: 0, + do() { + if (isOwned) { + if (g.health < 500 && g.health > 200) { + evo = { + isLongBlade: true, + isScytheRange: true, + scytheRange: 3, + isScytheRad: false, + scytheRad: 1, + isDoubleScythe: true, + isPhaseScythe: false, + isMeleeScythe: false, + isStunScythe: false, + }; + } else if (g.health < 200 && g.health > 50) { + evo = { + isLongBlade: true, + isScytheRange: true, + scytheRange: 3, + isScytheRad: true, + scytheRad: 1, + isDoubleScythe: true, + isPhaseScythe: true, + isMeleeScythe: true, + isStunScythe: true, + }; + } else if (g.health < 50) { + evo = { + isLongBlade: true, + isScytheRange: true, + scytheRange: 9, + isScytheRad: true, + scytheRad: 6, + isDoubleScythe: true, + isPhaseScythe: true, + isMeleeScythe: true, + isStunScythe: true, + }; + } + if (g.cycle > this.fireCD && !this.scythe) { + this.fireCD = g.cycle + 30; + if (!this.scythe) { + ({ scythe: this.scythe, bladeSegments: this.bladeSegments } = this.createAndSwingScythe()); + this.angle = g.angle; + } + } + if (this.scythe && g.cycle > this.cycle + 30 || !g.alive && this.scythe) { + Composite.remove(engine.world, this.scythe); + this.scythe.parts.forEach(part => { + Composite.remove(engine.world, part); + const index = bullet.indexOf(part); + if (index !== -1) { + bullet.splice(index, 1); + } + }); + this.scythe = undefined; + this.bladeTrails = []; + } else { + if (this.scythe && !evo.isMeleeScythe) { + if (!(this.angle > -Math.PI / 2 && this.angle < Math.PI / 2)) { + Matter.Body.setAngularVelocity(this.scythe, -Math.PI * 0.15 - (evo.scytheRad ? evo.scytheRad * 0.1 : 0)); + } else { + Matter.Body.setAngularVelocity(this.scythe, Math.PI * 0.15 + (evo.scytheRad ? evo.scytheRad * 0.1 : 0)); + } + Matter.Body.setVelocity(this.scythe, { + x: Math.cos(this.angle) * 30, + y: Math.sin(this.angle) * 30 + }); + } else if (this.scythe && evo.isMeleeScythe) { + if (!(this.angle > -Math.PI / 2 && this.angle < Math.PI / 2)) { + Matter.Body.setAngularVelocity(this.scythe, -Math.PI * 0.1 + (evo.isStunScythe ? 0.1 : 0)); + } else { + Matter.Body.setAngularVelocity(this.scythe, Math.PI * 0.1 - (evo.isStunScythe ? 0.1 : 0)); + } + Matter.Body.setPosition(this.scythe, genisis.position); + } + } + if (this.scythe) { + for (let i = 0; i < this.bladeSegments.length; i++) { + const blade = this.bladeSegments[i]; + const trail = this.bladeTrails[i] || []; + const vertices = blade.vertices.map(vertex => ({ x: vertex.x, y: vertex.y })); + trail.push(vertices); + if (trail.length > 10) { + trail.shift(); + } + this.bladeTrails[i] = trail; + } + for (let i = 0; i < this.bladeTrails.length; i++) { + const trail = this.bladeTrails[i]; + + const alphaStep = 1 / trail.length; + let alpha = 0; + + for (let j = 0; j < trail.length; j++) { + const vertices = trail[j]; + ctx.beginPath(); + ctx.moveTo(vertices[0].x, vertices[0].y); + + for (let k = 1; k < vertices.length; k++) { + ctx.lineTo(vertices[k].x, vertices[k].y); + }; + + alpha += alphaStep; + ctx.closePath(); + ctx.fillStyle = `rgba(100, 20, 255, ${alpha})`; + ctx.fill(); + } + } + for (let i = 0; i < this.bladeSegments.length; i++) { + ctx.beginPath(); + ctx.lineJoin = "miter"; + ctx.miterLimit = 100; + ctx.strokeStyle = `rgb(100, 20, 255)`; + ctx.lineWidth = 5; + ctx.fillStyle = "black"; + ctx.moveTo(this.bladeSegments[i].vertices[0].x, this.bladeSegments[i].vertices[0].y); + for (let j = 0; j < this.bladeSegments[i].vertices.length; j++) { + ctx.lineTo(this.bladeSegments[i].vertices[j].x, this.bladeSegments[i].vertices[j].y) + }; + ctx.closePath(); + ctx.stroke(); + ctx.fill(); + ctx.lineJoin = "round"; + ctx.miterLimit = 10; + } + } + if (this.scythe) { + for (let i = 0; i < mob.length; i++) { + if (Matter.Query.collides(this.scythe, [mob[i]]).length > 0) { + const dmg = m.dmgScale * 0.12 * 2.73 * (evo.isLongBlade ? 1.3 : 1) * (evo.scytheRange ? evo.scytheRange * 1.15 : 1) * (evo.isDoubleScythe ? 0.9 : 1) * (evo.scytheRad ? evo.scytheRad * 1.5 : 1); + mob[i].damage(dmg, true); + simulation.drawList.push({ + x: mob[i].position.x, + y: mob[i].position.y, + radius: Math.sqrt(dmg) * 50, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + if (!evo.isMeleeScythe) { + const angle = Math.atan2(mob[i].position.y - this.scythe.position.y, mob[i].position.x - this.scythe.position.x); + this.scythe.force.x += Math.cos(angle) * 2; + this.scythe.force.y += Math.sin(angle) * 2; + } + if (evo.isStunScythe) { + mobs.statusStun(mob[i], 90); + } + break + } + } + if (Matter.Query.collides(this.scythe, [player]).length > 0 && m.immuneCycle < m.cycle) { + const dmg = 0.02 * (evo.isLongBlade ? 1.3 : 1) * (evo.scytheRange ? evo.scytheRange * 1.15 : 1) * (evo.isDoubleScythe ? 0.9 : 1) * (evo.scytheRad ? evo.scytheRad * 1.5 : 1); // actual scythe scallings one tap the player so this is nerfed for genisis + m.damage(dmg); + m.immuneCycle = m.cycle + 10; + simulation.drawList.push({ + x: player.position.x, + y: player.position.y, + radius: Math.sqrt(dmg) * 50, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + if (!evo.isMeleeScythe) { + const angle = Math.atan2(player.position.y - this.scythe.position.y, player.position.x - this.scythe.position.x); + this.scythe.force.x += Math.cos(angle) * 2; + this.scythe.force.y += Math.sin(angle) * 2; + } + } + } + } + }, + createAndSwingScythe(x = genisis.position.x, y = genisis.position.y, angle = g.angle) { + this.cycle = g.cycle + 60 + (evo.scytheRange * 6); + const handleWidth = 20; + const handleHeight = 200 + (evo.isLongBlade ? 30 : 0) + (evo.isMeleeScythe ? 200 : 0); + const handle = Bodies.rectangle(x, y, handleWidth, handleHeight, spawn.propsIsNotHoldable); + bullet[bullet.length] = handle; + bullet[bullet.length - 1].do = () => { }; + const bladeWidth = 100; + const bladeHeight = 20; + const numBlades = 10 + (evo.isLongBlade ? 1 : 0) + (evo.isMeleeScythe ? 3 : 0); + const extensionFactor = 5.5; + const bladeSegments = []; + if (!evo.isDoubleScythe) { + for (let i = 0; i < numBlades; i++) { + const extensionFactorFraction = (i / (numBlades - 1)) * extensionFactor; + const bladeX = x - handleWidth / 2 + i * (bladeWidth / 2) - extensionFactorFraction * (bladeWidth / 2); + const bladeY = y + handleHeight / 2 - i * (bladeHeight / (3 ** i)); + + const vertices = [ + { x: bladeX, y: bladeY - bladeHeight / 2 }, + { x: bladeX + bladeWidth / 2, y: bladeY + bladeHeight / 2 }, + { x: bladeX - bladeWidth / 2, y: bladeY + bladeHeight / 2 }, + { x: bladeX, y: bladeY - bladeHeight / 2 + 10 }, + ]; + + const blade = Bodies.fromVertices(bladeX, bladeY, vertices, spawn.propsIsNotHoldable); + bullet[bullet.length] = blade; + bullet[bullet.length - 1].do = () => { }; + Matter.Body.rotate(blade, -Math.sin(i * (Math.PI / 180) * 5)); + bladeSegments.push(blade); + } + } else { + for (let i = 0; i < numBlades; i++) { + const extensionFactorFraction = (i / (numBlades - 1)) * extensionFactor; + const bladeX = x - handleWidth / 2 + i * (bladeWidth / 2) - extensionFactorFraction * (bladeWidth / 2); + const bladeY = y + handleHeight / 2 - i * (bladeHeight / (3 ** i)); + + const vertices = [ + { x: bladeX, y: bladeY - bladeHeight / 2 }, + { x: bladeX + bladeWidth / 2, y: bladeY + bladeHeight / 2 }, + { x: bladeX - bladeWidth / 2, y: bladeY + bladeHeight / 2 }, + { x: bladeX, y: bladeY - bladeHeight / 2 + 10 }, + ]; + + const blade = Bodies.fromVertices(bladeX, bladeY, vertices, spawn.propsIsNotHoldable); + bullet[bullet.length] = blade; + bullet[bullet.length - 1].do = () => { }; + Matter.Body.rotate(blade, -Math.sin(i * (Math.PI / 180) * 5)); + bladeSegments.push(blade); + } + + for (let i = 0; i < numBlades; i++) { + const extensionFactorFraction = (i / (numBlades - 1)) * extensionFactor; + const bladeX = x + handleWidth / 2 - i * (bladeWidth / 2) + extensionFactorFraction * (bladeWidth / 2); + const bladeY = y - handleHeight / 2 - i * (bladeHeight / (3 ** i)); + + const vertices = [ + { x: bladeX, y: bladeY - bladeHeight / 2 }, + { x: bladeX + bladeWidth / 2, y: bladeY + bladeHeight / 2 }, + { x: bladeX - bladeWidth / 2, y: bladeY + bladeHeight / 2 }, + { x: bladeX, y: bladeY - bladeHeight / 2 + 10 }, + ]; + + const blade = Bodies.fromVertices(bladeX, bladeY, vertices, spawn.propsIsNotHoldable); + bullet[bullet.length] = blade; + bullet[bullet.length - 1].do = () => { }; + Matter.Body.rotate(blade, -Math.sin(i * (Math.PI / 180) * 5) + Math.PI); + bladeSegments.push(blade); + } + } + const scythe = Body.create({ + parts: [handle, ...bladeSegments], + }); + Composite.add(engine.world, scythe); + Matter.Body.setPosition(scythe, { x, y }); + + scythe.collisionFilter.category = cat.body; + scythe.collisionFilter.mask = cat.mobBullet | cat.player; + if (!evo.isMeleeScythe) { + setTimeout(() => { + scythe.collisionFilter.mask = cat.mobBullet | cat.mob | cat.player; + }, 1000) + } + if ((angle > -Math.PI / 2 && angle < Math.PI / 2)) { + Body.scale(scythe, -1, 1, { x, y }); + } + + scythe.frictionAir -= 0.01; + + return { scythe, bladeSegments }; + }, + }) + spawn.mapRect(-10000, 0, 20000, 2000); + spawn.mapRect(-10000, -10000, 2000, 10000); + spawn.mapRect(8000, -10000, 2000, 10000); + spawn.mapRect(-10000, -10000, 20000, 2000); + spawn.spawnStairs(8000, 0, 15, 2500, 2500, true); + spawn.spawnStairs(-8000, 0, 15, 2500, 2500, false); + + spawn.mapRect(-4000, -10, 100, 20); + spawn.mapRect(4000, -10, 100, 20); + + spawn.mapRect(-1000, -10000, 2000, 8000); + // spawn.mapRect(-500, -10000, 1000, 9700); + function createSword(x = 0, y = 0) { //sword asthetic + const handleWidth = 20; + const handleHeight = 150; + const handle = Bodies.rectangle(x, y, handleWidth, handleHeight, spawn.propsIsNotHoldable); + bullet[bullet.length] = handle; + handle.customName = "handle"; + bullet[bullet.length - 1].do = () => { }; + const pommelWidth = 30; + const pommelHeight = 40; + const pommelVertices = [ + { x: x, y: y + handleHeight / 2 + pommelHeight / 2 }, + { x: x + pommelWidth / 2, y: y + handleHeight / 2 }, + { x: x, y: y + handleHeight / 2 - pommelHeight / 2 }, + { x: x - pommelWidth / 2, y: y + handleHeight / 2 }, + ]; + const pommel = Bodies.fromVertices(x, y + handleHeight / 2, pommelVertices, spawn.propsIsNotHoldable); + bullet[bullet.length] = pommel; + bullet[bullet.length - 1].do = () => { }; + if (tech.soundSword) { + bullet[bullet.length - 1].draw = () => { }; + } + // Blade setup + const bladeWidth = 100 * (tech.soundSword ? 3 : 1); + const bladeHeight = 20 * (tech.soundSword ? 3 : 1); + const numBlades = 15; + const extensionFactor = 5; + const bladeSegments = []; + for (let i = 0; i < numBlades; i++) { + const extensionFactorFraction = (i / (numBlades - 1)) * extensionFactor; + const mirroredBladeX = x - i * (bladeWidth / 20); + const mirroredBladeY = y - handleHeight / 2 - i * (bladeHeight / 4.5) * extensionFactor; + const mirroredVertices = [ + { x: mirroredBladeX, y: mirroredBladeY - bladeHeight / 2 }, + { x: mirroredBladeX + bladeWidth / 2, y: mirroredBladeY + bladeHeight / 2 }, + { x: mirroredBladeX - bladeWidth / 2, y: mirroredBladeY + bladeHeight / 2 }, + { x: mirroredBladeX, y: mirroredBladeY - bladeHeight / 2 + 10 }, + ]; + const mirroredBlade = Bodies.fromVertices(mirroredBladeX, mirroredBladeY, mirroredVertices, spawn.propsIsNotHoldable); + bullet[bullet.length] = mirroredBlade; + bullet[bullet.length - 1].do = () => { }; + if (tech.soundSword) { + bullet[bullet.length - 1].draw = () => { }; + } + Matter.Body.rotate(mirroredBlade, Math.sin(i * (Math.PI / 270) * 15)); + bladeSegments.push(mirroredBlade); + } + bladeSegments.push(pommel); + const sword = Body.create({ + parts: [handle, ...bladeSegments], + }); + + Composite.add(engine.world, sword); + Matter.Body.setPosition(sword, { x, y }); + + sword.collisionFilter.category = cat.bullet; + sword.collisionFilter.mask = cat.mobBullet | cat.powerup | cat.mob; + Body.scale(sword, -1, 1, { x, y }); + Body.rotate(sword, Math.PI + Math.PI / 15) + + return { sword, bladeSegments }; + } + }, + soft() { + simulation.inGameConsole(``); + simulation.inGameConsole(`soft by Richard0820`); + simulation.inGameConsole("The lasers deal less damage the higher level you are") + const portals = []; + portals.push(level.portal({ + x: -1525, + y: -250 + }, Math.PI / 2, { + x: 1100, + y: -1025 + }, Math.PI / 2)) + const soft = { + createCloth(x, y, radius, width, height, attachToPlayer = false, stayStill = false, options, touchPlayer = true, constrictionStrength = 0.001) { + const bodies = []; + const constraints = []; + const otherCons = []; + const bodyWidth = radius; + const bodyHeight = radius; + const numRows = Math.ceil(height / bodyHeight); + const numCols = Math.ceil(width / bodyWidth); + + for (let i = 0; i < numRows; i++) { + for (let j = 0; j < numCols; j++) { + const posX = x + j * bodyWidth + bodyWidth / 2; + const posY = y + i * bodyHeight + bodyHeight / 2; + + const rect = Matter.Bodies.circle(posX, posY, (bodyWidth + bodyHeight) / 4, options); + rect.collisionFilter.category = cat.body; + rect.collisionFilter.mask = (touchPlayer ? cat.player | cat.body | cat.bullet | cat.mob | cat.mobBullet : cat.body | cat.bullet | cat.mob | cat.mobBullet); + rect.classType = "body"; + + Composite.add(engine.world, rect); + + bodies.push(rect); + } + } + + for (let i = 0; i < numRows; i++) { + for (let j = 0; j < numCols; j++) { + const bodyIndexA = i * numCols + j; + if (j < numCols - 1) { + const bodyIndexB = i * numCols + (j + 1); + const constraint = Constraint.create({ + bodyA: bodies[bodyIndexA], + bodyB: bodies[bodyIndexB], + stiffness: 0.06, + damping: 0.001 + }); + Composite.add(engine.world, constraint); + constraints.push(constraint); + } + if (i < numRows - 1) { + const bodyIndexB = (i + 1) * numCols + j; + const constraint = Constraint.create({ + bodyA: bodies[bodyIndexA], + bodyB: bodies[bodyIndexB], + stiffness: 0.06, + damping: 0.001 + }); + Composite.add(engine.world, constraint); + constraints.push(constraint); + } + } + } + + for (let i = 0; i < numRows - 1; i++) { + for (let j = 0; j < numCols - 1; j++) { + const bodyA = bodies[i * numCols + j]; + const bodyB = bodies[(i + 1) * numCols + j + 1]; + const constraint = Constraint.create({ + bodyA: bodyA, + bodyB: bodyB, + stiffness: 0.02 + }); + constraints.push(constraint); + } + } + + for (let i = 0; i < numRows - 1; i++) { + for (let j = 1; j < numCols; j++) { + const bodyA = bodies[i * numCols + j]; + const bodyB = bodies[(i + 1) * numCols + j - 1]; + const constraint = Constraint.create({ + bodyA: bodyA, + bodyB: bodyB, + stiffness: 0.02 + }); + constraints.push(constraint); + } + } + if (stayStill) { + for (let i = 0; i < bodies.length; i++) { + const by = bodies[i]; + const spawnX = by.position.x + bodyWidth / 2; + const spawnY = by.position.y + bodyHeight / 2; + const isLastColumn = (i + 1) % numCols === 0; + const isFirstColumn = i % numCols === 0; + const stiffness = constrictionStrength * (isLastColumn || isFirstColumn ? 100 : 1); // Apply extra stiffness to first and last columns + + const cost = Constraint.create({ + bodyA: by, + pointB: { x: spawnX, y: spawnY }, + stiffness: stiffness, + length: 0 + }); + + Composite.add(engine.world, cost); + otherCons.push(cost); + } + } + if (attachToPlayer) { + for (let i = 0; i < bodies.length; i++) { + const cost = Constraint.create({ + bodyA: bodies[i], + pointB: player.position, + stiffness: 0.0005, + length: 0 + }); + Composite.add(engine.world, cost); + } + } + + return { bodies, constraints, otherCons }; + }, + clothOptions: { + frictionAir: 0.005, + }, + isOuterBoundary(body, bodies) { //unused + const neighbors = [ + { x: body.position.x + 1, y: body.position.y }, + { x: body.position.x - 1, y: body.position.y }, + { x: body.position.x, y: body.position.y + 1 }, + { x: body.position.x, y: body.position.y - 1 } + ]; + + for (let i = 0; i < neighbors.length; i++) { + const neighbor = neighbors[i]; + const isNeighbor = bodies.some(b => b.position.x === neighbor.x && b.position.y === neighbor.y); + if (!isNeighbor) { + return true; + } + } + return false; + }, + draw(cloth) { + ctx.beginPath(); + ctx.lineWidth = 2; + ctx.strokeStyle = "rgba(0,0,0,0.3)"; + ctx.fillStyle = "black"; + for (let i = 0, len = cloth.constraints.length; i < len; ++i) { + const constraint = cloth.constraints[i]; + ctx.moveTo(constraint.bodyA.position.x, constraint.bodyA.position.y); + ctx.lineTo(constraint.bodyB.position.x, constraint.bodyB.position.y); + } + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + }, + addGravity(bodies, magnitude) { + for (var i = 0; i < bodies.length; i++) { + bodies[i].force.y += bodies[i].mass * magnitude; + } + }, + gravity(cloth) { + this.addGravity(cloth.bodies, simulation.g); + }, + breaker(cloth, percentage = 0.5) { + const totalConstraints = cloth.constraints.length; + const constraintsToRemove = Math.ceil(totalConstraints * percentage); + + for (let i = 0; i < constraintsToRemove; i++) { + const randomIndex = Math.floor(Math.random() * cloth.constraints.length); + + let removedConstraint = cloth.constraints.splice(randomIndex, 1)[0]; + Composite.remove(engine.world, removedConstraint); + } + }, + destroyer(cloth, percentage = 0.99999) { + const otherCons = cloth.otherCons.length; + const otherCons2Remove = Math.ceil(otherCons * percentage); + + for (let i = 0; i < otherCons2Remove; i++) { + const randomIndex = Math.floor(Math.random() * cloth.otherCons.length); + + let removedConstraint = cloth.otherCons.splice(randomIndex, 1)[0]; + Composite.remove(engine.world, removedConstraint); + } + }, + annihilate(cloth) { + const totalBodies = cloth.bodies.length; + for (let i = 0; i < totalBodies; i++) { + const removeBody = cloth.bodies[i]; + Composite.remove(engine.world, removeBody); + } + cloth.bodies.length = 0; // Clear the bodies array after removal + } + } + const clothArray = []; + clothArray.push(soft.createCloth(-100, 0, 50, 1000, 300, false, true, soft.clothOptions, true)) + clothArray.push(soft.createCloth(-2000, 2375, 50, 1525, 200, false, true, soft.clothOptions, true)) + clothArray.push(soft.createCloth(-3950, 125, 50, 1800, 125, false, true, soft.clothOptions, true)) + const annoyingStuff = { + lasers(where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[j], + v2: vertices[j + 1] + }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[0], + v2: vertices[len] + }; + } + } + }; + + const seeRange = 7000; + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { + x: where.x + seeRange * Math.cos(angle), + y: where.y + seeRange * Math.sin(angle) + }; + // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + vertexCollision(where, look, body); + if (!m.isCloak) vertexCollision(where, look, [playerBody, playerHead]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + const dmg = 0.5 / simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + //draw beam + if (best.dist2 === Infinity) best = look; + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + }, + laserBoss(x, y, radius = 30) { + mobs.spawn(x, y, 6, radius, "#f00"); + let me = mob[mob.length - 1]; + + setTimeout(() => { //fix mob in place, but allow rotation + me.constraint = Constraint.create({ + pointA: { + x: me.position.x, + y: me.position.y + }, + bodyB: me, + stiffness: 1, + damping: 1 + }); + Composite.add(engine.world, me.constraint); + }, 2000); //add in a delay in case the level gets flipped left right + me.count = 0; + me.frictionAir = 0.03; + // me.torque -= me.inertia * 0.002 + spawn.spawnOrbitals(me, radius + 50 + 200 * Math.random()) + Matter.Body.setDensity(me, 0.03); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.25 + me.isBoss = true; + // spawn.shield(me, x, y, 1); //not working, not sure why + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.rotateVelocity = -Math.min(0.0045, 0.0015 * simulation.accelScale * simulation.accelScale) * (level.levelsCleared > 8 ? 1 : -1) + me.do = function () { + this.fill = '#' + Math.random().toString(16).substr(-6); //flash colors + this.checkStatus(); + + if (!this.isStunned) { + //check if slowed + let slowed = false + for (let i = 0; i < this.status.length; i++) { + if (this.status[i].type === "slow") { + slowed = true + break + } + } + if (!slowed) { + this.count++ + Matter.Body.setAngle(this, this.count * this.rotateVelocity) + Matter.Body.setAngularVelocity(this, 0) + } + + ctx.beginPath(); + for (let i = 0; i < this.vertices.length; i++) { + if (Math.sin((2 * Math.PI * simulation.cycle) / (50 + i)) > 0) { + this.lasers(this.vertices[i], Math.atan2(this.vertices[i].y - this.position.y, this.vertices[i].x - this.position.x)); + } + } + ctx.strokeStyle = "#50f"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(80,0,255,0.07)"; + ctx.stroke(); // Draw it + } + }; + me.lasers = function (where, angle) { + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = simulation.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2 && (!domain[i].mob || domain[i].alive)) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[j], + v2: vertices[j + 1] + }; + } + } + results = simulation.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[0], + v2: vertices[len] + }; + } + } + }; + + const seeRange = 7000; + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { + x: where.x + seeRange * Math.cos(angle), + y: where.y + seeRange * Math.sin(angle) + }; + // vertexCollision(where, look, mob); + vertexCollision(where, look, map); + vertexCollision(where, look, body); + if (!m.isCloak) vertexCollision(where, look, [playerBody, playerHead]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + const dmg = 0.5 / simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + //draw beam + if (best.dist2 === Infinity) best = look; + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + } + } + } + level.setPosToSpawn(-350, 0); + level.exit.x = 1075; + level.exit.y = 20; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#aaFFFF55"; + spawn.mapRect(900, 50, 425, 250); + // spawn.mapRect(900, -1050, 0.1, 1350); + spawn.mapRect(-475, 2375, 1800, 250); + spawn.mapRect(-4400, 2375, 2475, 250); + spawn.mapRect(-4400, -450, 250, 3075); + spawn.mapRect(-4400, -450, 2225, 250); + spawn.mapRect(-2425, -1300, 250, 1100); + spawn.mapRect(-2425, -1300, 3825, 250); + spawn.mapRect(1325, -1300, 250, 3925); + spawn.mapRect(-875, -1300, 250, 1375); + spawn.mapRect(-725, 50, 675, 250); + spawn.mapRect(-875, 175, 175, 125); + for (let i = 0; i < 6; i++) { + spawn.mapRect(-4175, 2000 - i * 375, 50, 125); + } + spawn.mapRect(-3925, 162.5, 50, 125); + spawn.mapRect(-2175, 162.5, 50, 125); + spawn.mapRect(300, 2025, 250, 600); + spawn.mapRect(-2150, 175, 50, 25); + spawn.mapRect(-2150, 250, 50, 25); + spawn.mapRect(-900, 175, 50, 25); + spawn.mapRect(-900, 250, 50, 25); + spawn.mapRect(-1600, 175, 50, 25); + spawn.mapRect(-1500, 175, 50, 25); + spawn.mapRect(-1600, 250, 50, 25); + spawn.mapRect(-1500, 250, 50, 25); + spawn.mapRect(-1925, 175, 50, 25); + spawn.mapRect(-1925, 250, 50, 25); + spawn.mapRect(-1200, 175, 50, 25); + spawn.mapRect(-1200, 250, 50, 25); + spawn.bodyRect(-2125, 200, 1250, 50); + spawn.debris(425, 200, 50); + spawn.debris(-650, 2100, 50); + spawn.debris(-3000, 1925, 50); + spawn.debris(-3825, 1550, 50); + spawn.debris(-2475, -50, 50); + + const bouncyBody = body[body.length - 1]; + bouncyBody.restitution = 0.9; + spawn.mapVertex(-2175 + 1300 / 2, -1050 + 1225 / 2, "0 -400 -100 -300 -100 0 100 0 100 -300"); + + spawn.mapVertex(-4150 + 1975 / 2, -200 + 2575 / 2, "0 -800 -200 -600 -200 0 0 200 200 0 200 -600 0 200"); + const mapWithVertex = map[map.length - 1]; + let index1 = 0; + level.custom = () => { + level.exit.drawAndCheck(); + + level.enter.draw(); + + if (player.position.x > 425 && index1 === 0) { + soft.breaker(clothArray[0], 0.7); + soft.destroyer(clothArray[0]); + index1++; + } + if (player.position.y > 1300 && index1 === 1) { + setTimeout(() => { + soft.breaker(clothArray[0], 1); + soft.annihilate(clothArray[0]); + clothArray.splice(0, 1); + }, 1000); //prevents bugs + simulation.inGameConsole("Couldn't be so simple, could it?", 2000 * Math.random()); + index1++; + } + }; + level.customTopLayer = () => { + for (let i = 0; i < portals.length; i++) { + portals[i][2].query(); + portals[i][3].query(); + portals[i][0].draw(); + portals[i][1].draw(); + portals[i][2].draw(); + portals[i][3].draw(); + } + ctx.beginPath(); + if (Math.sin((2 * Math.PI * simulation.cycle) / (50)) > 0) { + annoyingStuff.lasers(mapWithVertex.vertices[0], Math.atan2(mapWithVertex.vertices[0].y - mapWithVertex.position.y, mapWithVertex.vertices[0].x - mapWithVertex.position.x)); + annoyingStuff.lasers(mapWithVertex.vertices[3], Math.atan2(mapWithVertex.vertices[3].y - mapWithVertex.position.y, mapWithVertex.vertices[3].x - mapWithVertex.position.x)); + } + if (Math.sin((2 * Math.PI * simulation.cycle) / (51)) > 0) { + annoyingStuff.lasers(mapWithVertex.vertices[1], Math.atan2(mapWithVertex.vertices[1].y - mapWithVertex.position.y, mapWithVertex.vertices[1].x - mapWithVertex.position.x)); + annoyingStuff.lasers(mapWithVertex.vertices[4], Math.atan2(mapWithVertex.vertices[4].y - mapWithVertex.position.y, mapWithVertex.vertices[4].x - mapWithVertex.position.x)); + } + if (Math.sin((2 * Math.PI * simulation.cycle) / (52)) > 0) { + annoyingStuff.lasers(mapWithVertex.vertices[2], Math.atan2(mapWithVertex.vertices[2].y - mapWithVertex.position.y, mapWithVertex.vertices[2].x - mapWithVertex.position.x)); + annoyingStuff.lasers(mapWithVertex.vertices[5], Math.atan2(mapWithVertex.vertices[5].y - mapWithVertex.position.y, mapWithVertex.vertices[5].x - mapWithVertex.position.x)); + } + + ctx.strokeStyle = "#000"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(0,0,0,0.07)"; + ctx.stroke(); // Draw it + + for (let i = 0; i < clothArray.length; i++) { + soft.draw(clothArray[i]); + soft.gravity(clothArray[i]); + } + + ctx.beginPath(); + ctx.fillStyle = "rgba(69, 69, 69, 0.1)"; + ctx.rect(-475, 175, 425, 2300); + ctx.rect(900, 175, 425, 2300); + ctx.rect(-875, 175, 400, 10000); + ctx.rect(-4200, -250, 2025, 2775); + ctx.fill(); + + ctx.beginPath(); + ctx.fillStyle = (m.pos.x < -725 && m.pos.y < 175) ? `rgba(68, 68, 68, ${Math.max(0.3, Math.min((-775 - m.pos.x) / 100, 0.99))})` : color.map; + ctx.rect(-875, 50, 175, 150); + ctx.fill(); + + }; + annoyingStuff.laserBoss(-1525, 1025); + spawn.pulsar(-1525, -850); + spawn.pulsar(1125, 1600); + spawn.pulsar(-250, 1600); + spawn.pulsar(-1450, 1600); + spawn.pulsar(-2950, 1750); + spawn.pulsar(-3375, 1750); + spawn.pulsar(-3825, 1300); + spawn.pulsar(-3825, 850); + spawn.pulsar(-3450, 50); + spawn.pulsar(-2925, 50); + spawn.pulsar(-1900, -400); + spawn.pulsar(-1200, -400); + + powerUps.addResearchToLevel() + powerUps.directSpawn(-775, 125, "tech"); + if (!level.isNextLevelPowerUps && powerUp[powerUp.length - 1]) powerUp[powerUp.length - 1].collisionFilter.mask = cat.map | cat.body | cat.powerUp + spawn.bodyRect(-875, 75, 25, 100); + let hardBody = body[body.length - 1]; + hardBody.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.powerUp + }, + flappyGon() { //community map by digin + level.announceMobTypes(); + simulation.inGameConsole(`flappy n-gon by Digin`); + setTimeout(() => { simulation.inGameConsole("gravity is a choice"); }, 1000); + setTimeout(() => { simulation.inGameConsole("everyone will fly"); }, 2000); + setTimeout(() => { simulation.inGameConsole("jump from the post and find out"); }, 3000); + level.setPosToSpawn(0, -50); //normal spawn + level.exit.x = 8600; + level.exit.y = -1100; + level.defaultZoom = 1800; + simulation.zoomTransition(level.defaultZoom); + document.body.style.backgroundColor = "#55FF55"; + + var slimey = level.hazard(-200, -10, 9000, 10); + + // allow "flight" + + const old_playerOffGroundCheck = playerOffGroundCheck; + + playerOffGroundCheck = (event) => { + old_playerOffGroundCheck(event); + if (player.position.y < -300) { + m.onGround = true; + } + }; + + const oldNextLevel = level.nextLevel; + level.nextLevel = () => { // clear the flappy effects, because apparently there's no established api for this + playerOffGroundCheck = old_playerOffGroundCheck; + + level.nextLevel = oldNextLevel; + oldNextLevel(); + }; + + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); // standard bumps + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); + spawn.mapRect(level.exit.x - 100, level.exit.y + 40, 200, 100); + + // room basis + spawn.mapRect(-200, 0, 9000, 100); + spawn.mapRect(-200, -1500, 9000, 100); + spawn.mapRect(-200, -1500, 100, 1500); + spawn.mapRect(8700, -1500, 100, 1500); + + // somewhat randomized flappy pylons + const pylon = 1500; // height of the entire pylon assembly + for (var i = 0; i < 10; i++) { + var xbasis = 700 + i * 750; + var window = 300 + (10 - i) * 50; + var toph = pylon - window - 400 + (Math.random() - 0.5) * 400 - i * 50; + if (i == 0) { // on the first one, the lower pile will always have a height of 300 + toph = pylon - window - 300; + } + spawn.mapRect(xbasis, -1500, 100, toph); + spawn.mapRect(xbasis, toph + window - pylon, 100, pylon - toph - window); + if (i < 9) { + spawn.randomMob(xbasis + 300, Math.random() * -1400); + } + else { + spawn.randomLevelBoss(xbasis + 300, Math.random() * -1400); + } + if (i == 5) { + spawn.secondaryBossChance(xbasis + 300, Math.random() * -1400); + } + } + + level.custom = () => { + level.exit.drawAndCheck(); + player.onGround = true; + level.enter.draw(); + }; + const slimeRise = 0.15; + level.customTopLayer = () => { + slimey.height += slimeRise; + slimey.min.y -= slimeRise; + slimey.query(); + }; + powerUps.addResearchToLevel(); + }, + rings() { + level.announceMobTypes(); + simulation.inGameConsole(`rings by ThatLittleFrog`); + setTimeout(() => { + simulation.inGameConsole("go up"); + }, 2000); + level.setPosToSpawn(0, -2000); // spawn high up so you can go to the bottom of the lowest ring without tripping the too-low reset + level.exit.x = 0; + level.exit.y = -6400; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800; + simulation.zoomTransition(level.defaultZoom); + document.body.style.backgroundColor = "#d8dadf"; + + function mkrect(x, y, w, h) { + let who = body[body.length] = Bodies.rectangle(x, y, w, h, { + collisionFilter: { + category: cat.map, + mask: cat.body | cat.player | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + inertia: Infinity, //prevents rotation + isNotHoldable: true, + friction: 1, + frictionStatic: 1, + restitution: 0, + frictionAir: 1, + isStatic: true + }); + Composite.add(engine.world, who); + who.classType = "body"; + return body[body.length - 1]; + } + + function makeRing(x, y, linegth, thicc = 200) { // I don't feel like doing trigonometry, so linegth is slightly different from the radius + var _shape = [undefined, undefined, undefined, undefined]; + _shape[0] = mkrect(x - linegth / 2 - thicc, y - linegth / 2 - thicc, linegth, thicc); + _shape[1] = mkrect(x - linegth / 2 - thicc, y - linegth / 2, thicc, linegth); + _shape[2] = mkrect(x - linegth / 2, y + linegth / 2 - thicc, linegth, thicc); + _shape[3] = mkrect(x + linegth / 2 - thicc, y - linegth / 2 - thicc, thicc, linegth - thicc * 2); + let ret = { + shape: _shape, + x: x, + y: y, + r: 0, + rot(ang) { + this.r = ang; + let offs = 0; + for (let shape of this.shape) { + offs += Math.PI / 2; + Matter.Body.setAngle(shape, ang); + if (shape == this.shape[3]) { + Matter.Body.setPosition(shape, { + x: this.x + Math.cos(ang + offs) * (linegth / 2 - thicc / 2) - Math.cos(ang + offs + Math.PI / 2) * thicc, + y: this.y + Math.sin(ang + offs) * (linegth / 2 - thicc / 2) - Math.sin(ang + offs + Math.PI / 2) * thicc + }); + } + else { + Matter.Body.setPosition(shape, { + x: this.x + Math.cos(ang + offs) * (linegth / 2 - thicc / 2), + y: this.y + Math.sin(ang + offs) * (linegth / 2 - thicc / 2) + }); + } + } + }, + rotBy(ang) { + this.rot(this.r + ang); + } + }; + ret.rot(0); + return ret; + } + + var inner = makeRing(level.enter.x, level.enter.y, 1000); + var mid = makeRing(level.enter.x, level.enter.y, 2500); + var mid2 = makeRing(level.enter.x, level.enter.y, 4000); + var out = makeRing(level.enter.x, level.enter.y, 6000); + + spawn.randomMob(level.enter.x + 250, level.enter.y); + + spawn.randomMob(level.enter.x + 1250, level.enter.y); + spawn.randomMob(level.enter.x - 1250, level.enter.y); + spawn.randomMob(level.enter.x, level.enter.y + 1250); + spawn.randomMob(level.enter.x, level.enter.y - 1250); + spawn.randomMob(level.enter.x + 1250, level.enter.y + 500); + spawn.randomMob(level.enter.x - 1250, level.enter.y + 500); + spawn.randomMob(level.enter.x + 500, level.enter.y + 1250); + spawn.randomMob(level.enter.x + 500, level.enter.y - 1250); + + spawn.randomMob(level.enter.x + 2750, level.enter.y); + spawn.randomMob(level.enter.x - 2750, level.enter.y); + spawn.randomMob(level.enter.x, level.enter.y + 2750); + spawn.randomMob(level.enter.x, level.enter.y - 2750); + spawn.randomMob(level.enter.x + 2750, level.enter.y + 500); + spawn.randomMob(level.enter.x - 2750, level.enter.y + 500); + spawn.randomMob(level.enter.x + 500, level.enter.y + 2750); + spawn.randomMob(level.enter.x + 500, level.enter.y - 2750); + + spawn.randomLevelBoss(level.enter.x, level.enter.y - 4250); + spawn.secondaryBossChance(level.enter.x, level.enter.y + 4250); + + level.custom = () => { + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + inner.rotBy(0.01); + mid.rotBy(-0.005); + mid2.rotBy(0.003); + out.rotBy(-0.002); + }; + + powerUps.addResearchToLevel(); + }, + trial() { // trial, collab between Cirryn and Tarantula Hawk + simulation.inGameConsole(`trial by Cirryn and Tarantula Hawk`); + level.setPosToSpawn(0, -50); + level.exit.x = 4150; + level.exit.y = -30; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800; + simulation.zoomTransition(level.defaultZoom); + document.body.style.backgroundColor = "#d8dadf"; + const button = level.button(2000, 0); + const door = level.door(3930, -300, 40, 300, 300, 10); + door.isClosing = false; + var didTrialBegin = false; + + const customMob = { + assassin(x, y) { // modified slasher + mobs.spawn(x, y, 3, 30, "black"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.0008 * simulation.accelScale; + me.torqueMagnitude = 0.00002 * me.inertia * (Math.random() > 0.5 ? -1 : 1); + me.frictionStatic = 0; + me.frictionAir = 0.08; + me.delay = 120 * simulation.CDScale; + me.cd = 0; + spawn.shield(me, x, y); + me.damageReduction = 0; + const start = window.performance.now(); // they only last ~ten seconds + const lifespan = 15000 + 700 * (Math.random() - 0.5); + me.onDamage = function () { + Matter.Body.setAngularVelocity(me, me.angularVelocity + 1); + }; + me.do = function () { + this.checkStatus(); + this.alwaysSeePlayer(); + this.attraction(); + this.health = 1 - (window.performance.now() - start) / lifespan; + if (this.health < 0) { + this.death(); + } + Matter.Body.setAngularVelocity(me, me.angularVelocity + 0.05); + }; + }, + mercenary(x, y) { // fast boi + mobs.spawn(x, y, 3, 60, "white"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.001 * simulation.accelScale; + me.torqueMagnitude = 0.00001 * me.inertia * (Math.random() > 0.5 ? -1 : 1); + me.frictionStatic = 0; + me.frictionAir = 0.03; + me.delay = 120 * simulation.CDScale; + me.cd = 0; + spawn.shield(me, x, y); + me.damageReduction = 0; + const start = window.performance.now(); // they only last ~ten seconds + const lifespan = 25000 + 700 * (Math.random() - 0.5); + me.onDamage = function () { + Matter.Body.setAngularVelocity(me, me.angularVelocity + 1); + }; + me.do = function () { + this.checkStatus(); + this.attraction(); + this.health = 1 - (window.performance.now() - start) / lifespan; + if (this.health < 0) { + this.death(); + } + this.alwaysSeePlayer(); + }; + } + // eventually maybe add more custom mob types + }; + + function randomWave(count, source) { // generates a wave list from a source + // checks in spawn first, then customMob, for the sources + var ret = []; + for (var i = 0; i < count; i++) { + var pick = source[Math.floor(Math.random() * source.length)]; + if (spawn[pick]) { + ret.push(spawn[pick]); + } + else if (customMob[pick]) { + ret.push(customMob[pick]); + } + } + return ret; + } + + function wave(mobs) { // takes a list of functions that accept x,y coordinates to spawn a mob and spawns them in the ceiling + for (var i = 0; i < mobs.length; i++) { + var x = 1000 + 2400 * i / mobs.length + 200 * (Math.random() - 0.5); + var y = -950 - 100 * Math.random(); + mobs[i](x, y); + } + const ammoCount = Math.random() * (10 - simulation.difficulty / 4); + for (var i = 0; i < ammoCount; i++) { + powerUps.spawn(3300, -1000, "ammo"); + } + } + + level.custom = () => { + door.openClose(); + level.exit.drawAndCheck(); + level.enter.draw(); + }; + level.customTopLayer = () => { + button.query(); + button.draw(); + door.draw(); + if (!button.isUp && !didTrialBegin) { + didTrialBegin = true; + simulation.inGameConsole('The Trial has begun.'); + + setTimeout(() => { + simulation.inGameConsole('first wave (domitable)'); + wave(randomWave(2 + simulation.difficulty * 0.1, spawn.fullPickList)); + }, 3000); + + setTimeout(() => { + simulation.inGameConsole('second wave (domitable)'); + wave(randomWave(2 + simulation.difficulty * 0.1, spawn.fullPickList)); + }, 13000); + + setTimeout(() => { + simulation.inGameConsole('third wave (indomitable)'); + wave(randomWave(4, ["assassin"])); + }, 23000); + + setTimeout(() => { + simulation.inGameConsole('fourth wave (domitable)'); + wave(randomWave(4 + simulation.difficulty / 2, spawn.fullPickList)); + }, 39000); + + setTimeout(() => { + simulation.inGameConsole('fifth wave (domitable)'); + wave(randomWave(4 + simulation.difficulty / 2, spawn.fullPickList)); + }, 49000); + + setTimeout(() => { + simulation.inGameConsole('sixth wave (indomitable)'); + wave(randomWave(7, ["mercenary"])); + }, 59000); + + setTimeout(() => { + simulation.inGameConsole('seventh wave (boss)'); + spawn.randomLevelBoss(700, -1000); + var mainBoss = mob[mob.length - 1]; + mainBoss.oldOnDeath = mainBoss.onDeath; + mainBoss.onDeath = () => { + door.isClosing = false; + powerUps.spawn(4150, -30, "tech"); + powerUps.spawn(4150, -30, "tech"); + mainBoss.oldOnDeath(); + } + spawn.secondaryBossChance(3500, -1000); + }, 86000); + + door.isClosing = true; + } + }; + + spawn.mapRect(-100, 0, 10000, 10000); // the left half of the room + spawn.mapRect(-10000, -300, 9900, 10000); + spawn.mapRect(-100, -300, 400, 100); + spawn.mapRect(200, -800, 100, 500); + spawn.mapRect(200, -800, 500, 100); + spawn.mapRect(600, -1000, 100, 200); + + spawn.mapRect(600, -1100, 3000, 100); // the ceiling + + spawn.mapRect(3500, -1000, 100, 200); // the right half of the room + spawn.mapRect(3500, -800, 500, 100); + spawn.mapRect(3900, -800, 100, 500); + spawn.mapRect(3900, -300, 400, 100); + spawn.mapRect(4300, -300, 10000, 10000); + + for (var i = 0; i < 4; i++) { // "door" at the entrance + spawn.bodyRect(200, -200 + i * 50, 20, 50); + } + + for (var i = 0; i < 5; i++) { // some random rubble in the first half of the room + spawn.bodyRect(400 + Math.random() * 1000, -200, 40 + Math.random() * 40, 40 + Math.random() * 40); + } + + powerUps.addResearchToLevel(); //needs to run after mobs are spawneds + }, + // ******************************************************************************************************** + // ******************************************************************************************************** + // ***************************************** training levels ********************************************** + // ******************************************************************************************************** + // ******************************************************************************************************** + walk() { //learn to walk + if (localSettings.isHideHUD) localSettings.isHideHUD = false + m.addHealth(Infinity) + document.getElementById("health").style.display = "none" //hide your health bar + document.getElementById("health-bg").style.display = "none" + document.getElementById("defense-bar").style.display = "none" + document.getElementById("damage-bar").style.display = "none" + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + simulation.lastLogTime = 0; //clear previous messages + let instruction = 0 + level.trainingText(`move ↔ with ${input.key.left.replace('Key', '').replace('Digit', '')} and ${input.key.right.replace('Key', '').replace('Digit', '')}`) + + level.custom = () => { + if (instruction === 0 && input.right) { + instruction++ + level.trainingText(`move ↔ with ${input.key.left.replace('Key', '').replace('Digit', '')} and ${input.key.right.replace('Key', '').replace('Digit', '')} +
exit through the blue door`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + }; + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 0, 3500, 1800); //floor + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-250, -2800, 3500, 2200); //roof + spawn.mapRect(700, -8, 50, 25); + spawn.mapRect(725, -16, 75, 25); + spawn.mapRect(1375, -16, 50, 50); + spawn.mapRect(1400, -8, 50, 25); + spawn.mapRect(750, -24, 650, 100); + spawn.mapRect(1600, -1200, 500, 850); //exit roof + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + }, + crouch() { //learn to crouch + if (localSettings.isTrainingNotAttempted) { //after making it to the second training level + localSettings.isTrainingNotAttempted = false // this makes the training button less obvious at the start screen + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + + m.addHealth(Infinity) + level.setPosToSpawn(75, -100); //normal spawn + spawn.mapRect(25, -60, 100, 20); //small platform for player + spawn.mapRect(0, -50, 150, 25); //stairs + spawn.mapRect(-25, -40, 200, 25); + spawn.mapRect(-50, -30, 250, 25); + spawn.mapRect(-75, -20, 300, 25); + spawn.mapRect(-100, -10, 350, 25); + spawn.mapRect(-150, -50, 175, 75); + + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + let instruction = 0 + level.trainingText(`press ${input.key.down.replace('Key', '').replace('Digit', '')} to crouch`) + level.custom = () => { + if (instruction === 0 && input.down) { + instruction++ + level.trainingText(`press ${input.key.down.replace('Key', '').replace('Digit', '')} to crouch`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1625, -350, 375, 350) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1625, -350, 375, 350) + //dark + ctx.fillStyle = "rgba(0,0,0,0.2)" + ctx.fillRect(500, -100, 1125, 175); + }; + + // spawn.mapRect(1025, -675, 300, 623); //crouch wall + // spawn.mapRect(625, -650, 1025, 550); + spawn.mapRect(500, -650, 1125, 550); + spawn.mapRect(-200, -650, 875, 300); + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-250, -2800, 3500, 2200); //roof + + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + spawn.mapRect(1600, -1200, 500, 850); //exit roof + }, + jump() { //learn to jump + m.addHealth(Infinity) + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + let instruction = 0 + level.trainingText(`hold down ${input.key.up.replace('Key', '').replace('Digit', '')} longer to jump higher`) + + level.custom = () => { + if (instruction === 0 && m.pos.x > 300) { + instruction++ + level.trainingText(`hold down ${input.key.up.replace('Key', '').replace('Digit', '')} longer to jump higher`) + } + m.health = 1 //can't die + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + //dark + ctx.fillStyle = "rgba(0,0,0,0.2)" + ctx.fillRect(1000, 0, 450, 1800) + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + }; + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(275, -350, 200, 375); + spawn.mapRect(-250, 0, 1250, 1800); //floor + spawn.mapRect(1450, 0, 1075, 1800); //floor + spawn.mapRect(-250, -2800, 1250, 2200); //roof + spawn.mapRect(1450, -2800, 1075, 2200); //roof + spawn.mapVertex(375, 0, "150 0 -150 0 -100 -50 100 -50"); //base + + spawn.mapRect(1600, -1200, 500, 850); //exit roof + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + + //roof steps + spawn.mapRect(1000, -650, 25, 25); + spawn.mapRect(1000, -675, 50, 25); + spawn.mapRect(1000, -700, 75, 25); + spawn.mapRect(1000, -725, 100, 25); + spawn.mapRect(1425, -650, 25, 25); + spawn.mapRect(1400, -675, 50, 25); + spawn.mapRect(1375, -700, 75, 25); + spawn.mapRect(1350, -725, 100, 25); + spawn.mapRect(1325, -750, 150, 25); + spawn.mapRect(1300, -775, 150, 25); + spawn.mapRect(1000, -750, 125, 25); + spawn.mapRect(1275, -2800, 200, 2025); + spawn.mapRect(975, -2800, 200, 2025); + spawn.mapRect(1000, -775, 150, 25); + }, + hold() { //put block on button to open door + m.addHealth(Infinity) + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + spawn.bodyRect(1025, -75, 50, 50); //block to go on button + const buttonDoor = level.button(500, 0) + const door = level.door(1612.5, -175, 25, 190, 185, 3) + + let instruction = 0 + level.trainingText(`activate your field with ${input.key.field.replace('Key', '').replace('Digit', '')} or right mouse`) + + level.custom = () => { + if (instruction === 0 && input.field) { + instruction++ + level.trainingText(`activate your field with ${input.key.field.replace('Key', '').replace('Digit', '')} or right mouse
release your field on a block to pick it up`) + } else if (instruction === 1 && m.isHolding) { + instruction++ + level.trainingText(`activate your field with ${input.key.field.replace('Key', '').replace('Digit', '')} or right mouse
release your field on a block to pick it up

drop the block on the red button to open the door`) + } else if (instruction === 2 && !buttonDoor.isUp && Vector.magnitudeSquared(Vector.sub(body[0].position, buttonDoor.min)) < 10000) { + instruction++ + level.trainingText(`activate your field with ${input.key.field.replace('Key', '').replace('Digit', '')} or right mouse
release your field on a block to pick it up
drop the block on the red button to open the door
`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + + //check if blocks are in the exit zone and destroy them + for (let i = 0; i < body.length; i++) { + if (body[i].position.x > 1675) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + break + } + } + //if no blocks left make a new one + if (body.length < 2) { //< 2 because the door is a body + spawn.bodyRect(1025, -550, 50, 50); + } + }; + level.customTopLayer = () => { + buttonDoor.query(); + buttonDoor.draw(); + if (buttonDoor.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + }; + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-250, -2800, 3500, 2200); //roof + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + spawn.mapRect(1600, -1200, 500, 850); //exit roof + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + }, + throw() { //throw a block on button to open door + m.addHealth(Infinity) + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + spawn.bodyRect(1025, -75, 50, 50); //block to go on button + const buttonDoor = level.button(1635, -400) + const door = level.door(1612.5, -175, 25, 190, 185, 3) + + // activate your field with ${input.key.field.replace('Key', '').replace('Digit', '')} or right mouse + let instruction = 0 + level.trainingText(`pick up the block with your field`) + + level.custom = () => { + if (instruction === 0 && m.isHolding) { + instruction++ + level.trainingText(`pick up the block with your field +
hold your field down to charge up then release to throw a block`) + } else if (instruction === 1 && m.throwCharge > 2) { + instruction++ + level.trainingText(`pick up the block with your field +
hold your field down to charge up then release to throw a block
+
throw the block onto the button`) + // the block at the button + } else if (instruction === 2 && !buttonDoor.isUp && Vector.magnitudeSquared(Vector.sub(body[0].position, buttonDoor.min)) < 10000) { + instruction++ + level.trainingText(`pick up the block with your field +
hold your field down to charge up then release to throw a block +
throw the block onto the button
`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + buttonDoor.query(); + buttonDoor.draw(); + if (buttonDoor.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + //check if blocks are in the exit zone and destroy them + for (let i = 0; i < body.length; i++) { + if (body[i].position.x > 1675 && body[i].position.y > -350) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + break + } + } + //if no blocks left make a new one + if (body.length < 2) { //< 2 because the door is a body + spawn.bodyRect(1025, -550, 50, 50); + } + }; + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-250, -2800, 3500, 2200); //roof + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + // spawn.mapRect(1600, -1200, 500, 850); //exit roof + spawn.mapRect(1790, -600, 250, 225); //button left wall + spawn.mapRect(1625, -400, 400, 50); + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + }, + throwAt() { //throw a block at mob to open door + m.addHealth(Infinity) + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + const door = level.door(1612.5, -175, 25, 190, 185, 3) + + let instruction = 0 + level.trainingText(`throw the block at the mobs to open the door`) + + level.custom = () => { + if (instruction === 0 && !mob.length) { + instruction++ + level.trainingText(`throw the block at the mobs to open the door`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + if (mob.length > 0) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + + //check if blocks are in the exit zone and destroy them + for (let i = 0; i < body.length; i++) { + if (body[i].position.x > 1675 && body[i].position.y > -350) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + break + } + } + //if no blocks left make a new one + if (body.length < 2) { //< 2 because the door is a body + spawn.bodyRect(1025, -550, 50, 50); + } + }; + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-250, -2800, 3500, 2200); //roof + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + // spawn.mapRect(1600, -1200, 500, 850); //exit roof + // spawn.mapRect(1790, -600, 250, 225); //button left wall + // spawn.mapRect(1625, -400, 400, 50); + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + spawn.mapRect(1600, -600, 425, 250); + + spawn.bodyRect(1025, -75, 50, 50); //block to go on button + spawn.starter(425, -350, 35) + spawn.starter(800, -350, 44) + }, + fire() { //throw a block at mob to open door + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = 15; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + const door = level.door(1612.5, -125, 25, 190, 185, 3) + const buttonDoor = level.button(400, 0) + + let instruction = 0 + level.trainingText(`use your field to pick up ${powerUps.orb.gun()}`) + + level.custom = () => { + if (instruction === 0 && simulation.isChoosing) { + instruction++ + level.trainingText(`use your field to pick up ${powerUps.orb.gun()} +
choose a gun`) + } else if (instruction === 1 && !simulation.isChoosing) { + instruction++ + level.trainingText(`use your field to pick up ${powerUps.orb.gun()} +
choose a gun
+
use the left mouse button to shoot the mobs`) + } else if (instruction === 2 && mob.length === 0) { + instruction++ + level.trainingText(`use your field to pick up ${powerUps.orb.gun()} +
choose a gun +
use the left mouse button to shoot the mobs
+
drop a block on the red button to open the door`) + } else if (instruction === 3 && !door.isClosing) { + instruction++ + level.trainingText(`use your field to pick up ${powerUps.orb.gun()} +
choose a gun +
use the left mouse button to shoot the mobs +
put a block on the red button to open the door
`) + } + if (!powerUp.length) { + //spawn ammo if you run out + if (b.inventory.length && b.guns[b.activeGun].ammo === 0) powerUps.directSpawn(1300, -2000, "ammo", false); + //spawn a gun power up if don't have one or a gun + if (!b.inventory.length && !simulation.isChoosing) powerUps.directSpawn(1300, -2000, "gun", false); + + } + + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -350, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + buttonDoor.query(); + buttonDoor.draw(); + if (buttonDoor.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -350, 400, 400) + //ammo tunnel shadow + ctx.fillStyle = "rgba(0,0,0,0.4)" + ctx.fillRect(1250, -2800, 100, 2200) + }; + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(-150, -2800, 1400, 2200); //roof with tunnel for ammo + spawn.mapRect(1350, -2800, 675, 2200); + + //ceiling steps + spawn.mapRect(725, -588, 50, 25); + spawn.mapRect(725, -600, 75, 25); + spawn.mapRect(750, -612, 75, 25); + spawn.mapRect(-275, -650, 1025, 87); + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + + spawn.mapRect(1600, -600, 425, 300); + spawn.mapRect(1600, -400, 50, 275); + + powerUps.directSpawn(1300, -1500, "gun", false); + spawn.starter(900, -300, 35) + spawn.starter(1400, -400, 44) + }, + deflect() { //learn to jump + m.addHealth(Infinity) + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + let instruction = 0 + // activate your field with ${input.key.field.replace('Key', '').replace('Digit', '')} or right mouse + level.trainingText(`use your field to deflect the mobs`) + + level.custom = () => { + if (instruction === 0 && m.pos.x > 1350) { + instruction++ + level.trainingText(`use your field to deflect the mobs`) + } + //teleport to start if hit + if (m.immuneCycle > m.cycle) { + m.energy = m.maxEnergy + Matter.Body.setPosition(player, { + x: 60, + y: -50 + }) + } + //spawn bullets + if (!(simulation.cycle % 5)) { + spawn.sniperBullet(660 + 580 * Math.random(), -2000, 10, 4); + const who = mob[mob.length - 1] + Matter.Body.setVelocity(who, { + x: 0, + y: 8 + }); + who.timeLeft = 300 + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + //dark + ctx.fillStyle = "rgba(0,0,0,0.05)" + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + //center falling bullets + ctx.fillStyle = "rgba(255,0,255,0.013)" //pink? + ctx.fillRect(650, -2800, 600, 2800) + }; + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + + spawn.mapRect(-250, 0, 3000, 1800); //floor + spawn.mapRect(-250, -2800, 900, 2200); //roof + spawn.mapRect(1250, -2800, 1275, 2200); //roof + spawn.mapVertex(950, 0, "400 0 -400 0 -300 -50 300 -50"); //base + + spawn.mapRect(1600, -1200, 500, 850); //exit roof + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + + //spawn bullets on load to avoid rush + for (let i = 0; i < 32; i++) { + spawn.sniperBullet(660 + 580 * Math.random(), -2000 + 40 * i, 10, 4); + const who = mob[mob.length - 1] + Matter.Body.setVelocity(who, { + x: 0, + y: 8 + }); + who.timeLeft = 300 + } + }, + heal() { //learn to heal + m.addHealth(Infinity) + m.health = 0; + m.addHealth(0.25) + document.getElementById("health").style.display = "inline" //show your health bar + document.getElementById("health-bg").style.display = "inline" + if (!localSettings.isHideHUD) { + document.getElementById("defense-bar").style.display = "inline" + document.getElementById("damage-bar").style.display = "inline" + } + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + let instruction = 0 + level.trainingText(`your health is displayed in the top left corner +
use your field to pick up
until your health is full`) + + level.custom = () => { + if (instruction === 0 && m.health === 1) { + instruction++ + level.trainingText(`use your field to pick up
until your health is full
`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + if (m.health !== 1) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + }; + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 0, 3500, 1800); //floor + + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-250, -2800, 3500, 2200); //roof + + spawn.mapRect(700, -8, 50, 25); + spawn.mapRect(725, -16, 75, 25); + spawn.mapRect(1375, -16, 50, 50); + spawn.mapRect(1400, -8, 50, 25); + spawn.mapRect(750, -24, 650, 100); + powerUps.directSpawn(875, -40, "heal", false, 15); + powerUps.directSpawn(1075, -50, "heal", false, 25); + powerUps.directSpawn(1275, -65, "heal", false, 35); + + const door = level.door(1612.5, -175, 25, 190, 185, 3) + spawn.mapRect(1600, -1200, 500, 850); //exit roof + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + }, + nailGun() { + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + b.giveGuns("nail gun") + b.guns[b.activeGun].ammo = 0 + simulation.updateGunHUD(); + + const door = level.door(1612.5, -175, 25, 190, 185, 3) + let instruction = 0 + level.trainingText(`use your field to pick up
for your nail gun`) + + level.custom = () => { + if (instruction === 0 && b.inventory.length && b.guns[b.activeGun].ammo > 0) { + instruction++ + level.trainingText(`use your field to pick up
for your nail gun
+
use the left mouse button to shoot the mobs`) + } else if (instruction === 1 && mob.length === 0) { + instruction++ + level.trainingText(`use your field to pick up
for your nail gun +
use the left mouse button to shoot the mobs
`) + } + //spawn ammo if you run out + let isAmmo = false + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === 'ammo') isAmmo = true + } + if (!isAmmo && b.inventory.length && b.guns[b.activeGun].ammo === 0) { + powerUps.directSpawn(1300, -2000, "ammo", false); + powerUps.directSpawn(1301, -2200, "ammo", false); + } + + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + if (mob.length > 0) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + //ammo tunnel shadow + ctx.fillStyle = "rgba(0,0,0,0.4)" + ctx.fillRect(1250, -2800, 100, 2200) + }; + + if (m.health < 1) { + powerUps.directSpawn(1298, -3500, "heal", false, 23); + powerUps.directSpawn(1305, -3000, "heal", false, 35); + } + for (let i = 0; i < 2; i++) { + spawn.spinner(1300 + i, -3000 - 200 * i, 25 + 5 * i) + const who = mob[mob.length - 1] + Matter.Body.setVelocity(who, { x: 0, y: 62 }); + who.isDropPowerUp = false + } + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-150, -2800, 1400, 2200); //roof with tunnel for ammo + spawn.mapRect(1350, -2800, 675, 2200); + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + // spawn.mapRect(1600, -1200, 500, 850); //exit roof + // spawn.mapRect(1790, -600, 250, 225); //button left wall + // spawn.mapRect(1625, -400, 400, 50); + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + spawn.mapRect(1600, -600, 425, 250); + }, + shotGun() { + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + b.giveGuns("shotgun") + // b.guns[b.activeGun].ammo = 0 + // simulation.updateGunHUD(); + const door = level.door(1612.5, -175, 25, 190, 185, 3) + let instruction = 0 + level.trainingText(`use your shotgun to clear the room of mobs`) + + level.custom = () => { + if (instruction === 0 && mob.length === 0) { + instruction++ + level.trainingText(`use your shotgun to clear the room of mobs`) + } + //spawn ammo if you run out + let isAmmo = false + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === 'ammo') isAmmo = true + } + if (!isAmmo && b.inventory.length && b.guns[b.activeGun].ammo === 0) { + powerUps.directSpawn(1300, -2000, "ammo", false); + powerUps.directSpawn(1301, -2200, "ammo", false); + } + + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + if (mob.length > 0) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + //ammo tunnel shadow + ctx.fillStyle = "rgba(0,0,0,0.4)" + ctx.fillRect(1250, -2800, 100, 2200) + }; + + if (m.health < 1) { + powerUps.directSpawn(1298, -3500, "heal", false, 23); + powerUps.directSpawn(1305, -3000, "heal", false, 35); + } + for (let i = 0; i < 3; i++) { + spawn.hopper(1300 + i, -3000 - 2000 * i, 25 + 5 * i) + mob[mob.length - 1].isDropPowerUp = false + // Matter.Body.setVelocity(mob[mob.length - 1], { x: 0, y: 0 }); + } + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-150, -2800, 1400, 2200); //roof with tunnel for ammo + spawn.mapRect(1350, -2800, 675, 2200); + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + spawn.mapRect(1600, -600, 425, 250); + }, + superBall() { + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + b.giveGuns("super balls") + // b.guns[b.activeGun].ammo = 0 + // simulation.updateGunHUD(); + const door = level.door(1612.5, -175, 25, 190, 185, 3) + let instruction = 0 + level.trainingText(`use super balls to clear the room of mobs`) + + level.custom = () => { + if (instruction === 0 && mob.length === 0) { + instruction++ + level.trainingText(`use super balls to clear the room of mobs`) + } + //spawn ammo if you run out + let isAmmo = false + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === 'ammo') isAmmo = true + } + if (!isAmmo && b.inventory.length && b.guns[b.activeGun].ammo === 0) { + powerUps.directSpawn(1300, -2000, "ammo", false); + powerUps.directSpawn(1301, -2200, "ammo", false); + } + + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + if (mob.length > 0) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + //ammo tunnel shadow + ctx.fillStyle = "rgba(0,0,0,0.2)" + // ctx.fillRect(1225, -2800, 125, 2450) + ctx.fillRect(-150, -2800, 1500, 2450); + }; + + if (m.health < 1) { + powerUps.directSpawn(1298, -3500, "heal", false, 23); + powerUps.directSpawn(1305, -3000, "heal", false, 35); + } + for (let i = 0; i < 6; i++) { + spawn.spawner(i * 230, -800) + mob[mob.length - 1].isDropPowerUp = false + // Matter.Body.setVelocity(mob[mob.length - 1], { x: 0, y: 0 }); + } + spawn.mapVertex(510, -430, "725 0 725 80 -650 80 -650 -80 650 -80"); //upper room with mobs + spawn.mapRect(-225, -2800, 1450, 2000); + spawn.mapRect(1350, -2800, 675, 2450); + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + }, + matterWave() { //fire wave through the map to kill mosb + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + b.giveGuns("wave") + // b.guns[b.activeGun].ammo = 0 + // simulation.updateGunHUD(); + const door = level.door(1612.5, -175, 25, 190, 185, 3) + let instruction = 0 + level.trainingText(`use wave to clear the room of mobs`) + + level.custom = () => { + if (instruction === 0 && mob.length === 0) { + instruction++ + level.trainingText(`use wave to clear the room of mobs`) + } + //spawn ammo if you run out + let isAmmo = false + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === 'ammo') isAmmo = true + } + if (!isAmmo && b.inventory.length && b.guns[b.activeGun].ammo === 0) { + powerUps.directSpawn(1300, -2000, "ammo", false); + powerUps.directSpawn(1301, -2200, "ammo", false); + } + + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + if (mob.length > 0) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + //ammo tunnel shadow + ctx.fillStyle = "rgba(0,0,0,0.2)" + // ctx.fillRect(1225, -2800, 125, 2450) + ctx.fillRect(-150, -2800, 1500, 2450); + }; + + if (m.health < 1) { + powerUps.directSpawn(1298, -3500, "heal", false, 23); + powerUps.directSpawn(1305, -3000, "heal", false, 35); + } + for (let i = 0; i < 6; i++) { + spawn.springer(i * 200, -800) + mob[mob.length - 1].isDropPowerUp = false + // Matter.Body.setVelocity(mob[mob.length - 1], { x: 0, y: 0 }); + } + spawn.springer(1825, -330, 20); + + spawn.mapRect(1175, -850, 50, 500); //upper room with mobs + spawn.mapRect(-225, -400, 1450, 50); + spawn.mapRect(-225, -2800, 1450, 2000); + spawn.mapRect(1350, -2800, 675, 2450); + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + }, + missile() { //fire a missile to kill mobs and trigger button + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 30); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + b.giveGuns("missiles") + // b.guns[b.activeGun].ammo = 0 + // simulation.updateGunHUD(); + const buttonDoor = level.button(2500, 50) + const door = level.door(1612.5, -175, 25, 190, 185, 3) + let instruction = 0 + level.trainingText(`use missiles to drop a block on the button`) + + level.custom = () => { + if (instruction === 0 && mob.length === 0) { + instruction++ + level.trainingText(`use missiles to drop a block on the button`) + } + //spawn ammo if you run out + let isAmmo = false + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === 'ammo') isAmmo = true + } + if (!isAmmo && b.inventory.length && b.guns[b.activeGun].ammo === 0) { + powerUps.directSpawn(1300, -2000, "ammo", false); + powerUps.directSpawn(1301, -2200, "ammo", false); + } + + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + buttonDoor.query(); + buttonDoor.draw(); + if (buttonDoor.isUp) { + door.isClosing = true + } else { + door.isClosing = false + } + door.openClose(); + door.draw(); + + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + //tunnel shadow + ctx.fillStyle = "rgba(0,0,0,0.4)" + ctx.fillRect(1250, -2800, 100, 2200) + ctx.fillRect(1550, 25, 475, 25); + }; + if (m.health < 1) { + powerUps.directSpawn(1298, -3500, "heal", false, 23); + powerUps.directSpawn(1305, -3000, "heal", false, 35); + } + for (let i = 0; i < 10; i++) { + spawn.springer(2100 + i * 100, -250) + mob[mob.length - 1].isDropPowerUp = false + // Matter.Body.setVelocity(mob[mob.length - 1], { x: 0, y: 0 }); + } + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + // spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(3050, -2800, 1550, 4600); + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(-150, -2800, 1400, 2200); //roof with tunnel for ammo + spawn.mapRect(1350, -2800, 675, 2200); + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + // spawn.mapRect(1350, 0, 675, 30); + spawn.mapRect(1550, 0, 475, 35); + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + spawn.mapRect(1600, -600, 425, 250); + + spawn.mapRect(1975, -600, 50, 625); + spawn.mapRect(2025, -2800, 1075, 2450); + }, + stack() { //stack blocks to get to exit + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -685; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + let instruction = 0 + level.trainingText(`use your field to stack the blocks`) + + level.custom = () => { + if (instruction === 0 && m.pos.x > 1635) { + instruction++ + level.trainingText(`use your field to stack the blocks`) + } + + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -1050, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -1050, 400, 400) + //ammo tunnel shadow + ctx.fillStyle = "rgba(0,0,0,0.4)" + ctx.fillRect(250, -2800, 200, 1800) + }; + + if (m.health < 1) { + powerUps.directSpawn(298, -3500, "heal", false, 23); + powerUps.directSpawn(305, -3000, "heal", false, 35); + } + for (let i = 0; i < 15; i++) { + spawn.bodyRect(280, -2000 - 500 * i, 30 + 80 * Math.random(), 30 + 80 * Math.random()); + } + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 0, 3500, 1800); //floor + spawn.mapRect(1600, -650, 450, 775); + spawn.mapRect(-150, -2800, 400, 1800); //roof with tunnel for ammo + spawn.mapRect(450, -2800, 1675, 1800); + spawn.mapVertex(1300, 0, "400 0 -500 0 -300 -125 400 -125"); //base + }, + mine() { //kill mobs and tack their bodies + level.setPosToSpawn(300, -50); //normal spawn + spawn.mapRect(250, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -685; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + b.giveGuns("mine") + + let instruction = 0 + level.trainingText(`press the red button to spawn a mob`) + const button = level.button(-100, -200) + button.isUp = true + spawn.mapRect(-150, -200, 240, 425); + + level.custom = () => { + if (instruction === 0 && !button.isUp) { + instruction++ + level.trainingText(`press the red button to spawn a mob
turn the mobs into blocks`) + } else if (instruction === 1 && body.length > 2) { + instruction++ + level.trainingText(`press the red button to spawn a mob
turn the mobs into blocks

use your field to stack the blocks`) + } else if (instruction === 2 && m.pos.x > 1635) { + instruction++ + level.trainingText(`press the red button to spawn a mob
turn the mobs into blocks
use your field to stack the blocks
`) + } + //spawn ammo if you run out + let isAmmo = false + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === 'ammo') isAmmo = true + } + if (!isAmmo && b.inventory.length && b.guns[b.activeGun].ammo === 0) { + powerUps.directSpawn(1300, -2000, "ammo", false); + powerUps.directSpawn(1301, -2200, "ammo", false); + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -1050, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + button.query(); + button.draw(); + if (!button.isUp) { + if (button.isReady) { + button.isReady = false + spawn.exploder(335, -1700) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: 0, + y: 20 + }); + ctx.fillStyle = "rgba(255,0,0,0.9)" + ctx.fillRect(550, -2800, 200, 1800) + } + } else { + button.isReady = true + } + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -1050, 400, 400) + //ammo tunnel shadow + ctx.fillStyle = "rgba(0,0,0,0.4)" + ctx.fillRect(550, -2800, 200, 1800) + }; + + if (m.health < 1) { + powerUps.directSpawn(298, -3500, "heal", false, 23); + powerUps.directSpawn(305, -3000, "heal", false, 35); + } + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 0, 3500, 1800); //floor + spawn.mapRect(1600, -650, 450, 775); + spawn.mapRect(-150, -2800, 700, 1800); //roof with tunnel for ammo + spawn.mapRect(750, -2800, 1675, 1800); + spawn.mapVertex(1300, 0, "400 0 -600 0 -300 -125 400 -125"); //base + }, + grenades() { //jump at the top of the elevator's path to go extra high + level.setPosToSpawn(0, -50); //normal spawn + spawn.mapRect(-50, -10, 100, 20); //small platform for player + level.exit.x = 1900; + level.exit.y = -2835; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + b.giveGuns("grenades") + + const elevator1 = level.elevator(550, -100, 180, 25, -840, 0.003, { + up: 0.05, + down: 0.2 + }) // x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + elevator1.addConstraint(); + const toggle1 = level.toggle(275, 0) //(x,y,isOn,isLockOn = true/false) + + const elevator2 = level.elevator(1400, -950, 180, 25, -2400, 0.0025) // x, y, width, height, maxHeight, force = 0.003, friction = { up: 0.01, down: 0.2 }) { + elevator2.addConstraint(); + const button2 = level.button(1000, -850) + + let instruction = 0 + level.trainingText(`flip the switch to turn on the elevator`) + level.custom = () => { + if (instruction === 0 && elevator1.isOn) { + instruction++ + level.trainingText(`flip the switch to turn on the elevator +
put a block on the button to active the elevator`) + } else if (instruction === 1 && elevator2.isOn) { + instruction++ + level.trainingText(`flip the switch to turn on the elevator
put a block on the button to active the elevator
+
hold jump before the elevator's apex to reach the exit`) + } else if (instruction === 2 && m.pos.x > 1635) { + instruction++ + level.trainingText(`flip the switch to turn on the elevator
put a block on the button to active the elevator
hold jump before the elevator's apex to reach the exit
`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1725, -3100, 375, 300); + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + toggle1.query(); + if (!toggle1.isOn) { + if (elevator1.isOn) { + elevator1.isOn = false + elevator1.frictionAir = 0.2 + elevator1.addConstraint(); + } + } else if (!elevator1.isOn) { + elevator1.isOn = true + elevator1.isUp = false + elevator1.removeConstraint(); + elevator1.frictionAir = 0.2 //elevator.isUp ? 0.01 : 0.2 + } + if (elevator1.isOn) { + elevator1.move(); + ctx.fillStyle = "#444" + } else { + ctx.fillStyle = "#aaa" + } + ctx.fillRect(640, -825, 1, 745) + + button2.query(); + button2.draw(); + if (button2.isUp) { + if (elevator2.isOn) { + elevator2.isOn = false + elevator2.frictionAir = 0.2 + elevator2.addConstraint(); + } + } else if (!elevator2.isOn) { + elevator2.isOn = true + elevator2.isUp = false + elevator2.removeConstraint(); + elevator2.frictionAir = 0.2 //elevator.isUp ? 0.01 : 0.2 + } + if (elevator2.isOn) { + elevator2.move(); + ctx.fillStyle = "#444" + } else { + ctx.fillStyle = "#aaa" + } + ctx.fillRect(1490, -2300, 1, 1375) + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1725, -3100, 375, 300); + //shadows + ctx.fillStyle = "rgba(0,0,0,0.05)" + ctx.fillRect(-150, -250, 300, 250); + let grd = ctx.createLinearGradient(0, -150, 0, -2300); + grd.addColorStop(0, "rgba(0,0,0,0.35)"); + grd.addColorStop(1, "rgba(0,0,0,0)"); + ctx.fillStyle = grd //"rgba(0,0,100,0.01)" + ctx.fillRect(-200, -2300, 1825, 2300); + }; + + if (m.health < 1) { + powerUps.directSpawn(298, -3500, "heal", false, 23); + powerUps.directSpawn(305, -3000, "heal", false, 35); + } + spawn.mapRect(-2750, -4800, 2600, 6600); //left wall + spawn.mapRect(1600, -2800, 3000, 4600); //right wall + spawn.mapRect(-150, -4800, 300, 4550); + spawn.mapRect(2125, -4775, 2475, 2050); + spawn.mapRect(-250, 0, 3500, 1800); //floor + spawn.mapRect(750, -850, 950, 950); + spawn.mapRect(125, -275, 25, 100); + spawn.mapRect(2100, -3150, 50, 350); + spawn.mapRect(1725, -3150, 50, 175); + spawn.mapRect(1725, -3150, 425, 50); + + spawn.nodeGroup(1200, -1500, "grenadier", 7); + }, + harpoon() { //jump at the top of the elevator's path to go extra high + level.setPosToSpawn(0, -50); //normal spawn + spawn.mapRect(-50, -10, 100, 20); //small platform for player + level.exit.x = 1900; + level.exit.y = -2835; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + b.resetAllGuns(); + b.giveGuns("harpoon") + + let instruction = 0 + level.trainingText(`climb up to the exit`) + level.custom = () => { + if (instruction === 0 && m.pos.x > 1635) { + instruction++ + level.trainingText(`climb up to the exit`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1725, -3100, 375, 300); + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1725, -3100, 375, 300); + //shadows + ctx.fillStyle = "rgba(0,90,100,0.05)" + ctx.fillRect(-150, -250, 300, 250); + let grd = ctx.createLinearGradient(0, -150, 0, -2300); + grd.addColorStop(0, "rgba(0,90,100,0.35)"); + grd.addColorStop(1, "rgba(0,90,100,0)"); + ctx.fillStyle = grd //"rgba(0,0,100,0.01)" + ctx.fillRect(-200, -2300, 1825, 2300); + vanish1.query(); + vanish2.query(); + vanish3.query(); + vanish4.query(); + vanish5.query(); + vanish6.query(); + vanish7.query(); + vanish8.query(); + vanish9.query(); + vanish10.query(); + vanish11.query(); + vanish12.query(); + }; + const vanish1 = level.vanish(175, -325, 175, 25); //x, y, width, height, hide = { x: 0, y: 100 } //hide should just be somewhere behind the map so the player can't see it + const vanish2 = level.vanish(525, -625, 175, 25); + const vanish3 = level.vanish(1125, -1125, 175, 25); + const vanish4 = level.vanish(1500, -1450, 100, 25); + const vanish5 = level.vanish(1125, -1675, 175, 25); + const vanish6 = level.vanish(750, -1950, 175, 25); + const vanish7 = level.vanish(550, -1950, 175, 25); + const vanish8 = level.vanish(350, -1950, 175, 25); + const vanish9 = level.vanish(150, -1950, 175, 25); + const vanish10 = level.vanish(325, -2300, 200, 25); + const vanish11 = level.vanish(725, -2550, 100, 25); + const vanish12 = level.vanish(1125, -2700, 150, 25); + + if (m.health < 1) { + powerUps.directSpawn(298, -3500, "heal", false, 23); + powerUps.directSpawn(305, -3000, "heal", false, 35); + } + spawn.mapRect(-2750, -4800, 2600, 6600); //left wall + spawn.mapRect(1600, -2800, 3000, 4600); //right wall + spawn.mapRect(-150, -4800, 300, 4550); + spawn.mapRect(2125, -4775, 2475, 2050); + spawn.mapRect(-250, 0, 3500, 1800); //floor + spawn.mapRect(750, -850, 950, 950); + spawn.mapRect(125, -275, 25, 100); + spawn.mapRect(2100, -3150, 50, 350); + spawn.mapRect(1725, -3150, 50, 175); + spawn.mapRect(1725, -3150, 425, 50); + + spawn.grower(250, -375); + spawn.grower(1000, -900) + spawn.grower(1475, -925); + spawn.grower(275, -2000); + spawn.grower(650, -2000); + spawn.grower(1475, -975); + spawn.grower(1575, -1525); + spawn.grower(1700, -2850); + }, + diamagnetism() { + if (localSettings.isHideHUD) localSettings.isHideHUD = false + m.addHealth(Infinity) + document.getElementById("health").style.display = "none" //hide your health bar + document.getElementById("health-bg").style.display = "none" + document.getElementById("defense-bar").style.display = "none" + document.getElementById("damage-bar").style.display = "none" + const futureGuns = ["harpoon", "shotgun", "nail gun", "super balls", "wave", "foam", "laser"]; + const futureGun = Math.floor(Math.random() * futureGuns.length) + b.giveGuns(futureGuns[futureGun], Infinity) + m.setField(2) + m.fieldRegen = 0; + level.trainingText(`diamagnetism by Richard0820
Don't get hit.
Find the portal to the exit.`) + const dodge = []; + const button = level.button(350 - 63, -300) + const door = level.door(750, -275, 50, 125, 125) + const door2 = level.door(750, -525, 50, 125, 125); + const forceOne = forceField(4425, -3925, 525, 3975); + const forceTwo = forceField(1550, -9950, 275, 3300); + const forceThree = forceField(4200, -8725, 750, 4450); + const respawnX = []; + respawnX.push(setRespawn(-50, -625, 825, 375)); + respawnX.push(setRespawn(3225, -3675, 1200, 1000)); + respawnX.push(setRespawn(3575, -5675, 625, 800)); + respawnX.push(setRespawn(775, -4250, 400, 375)); + respawnX.push(setRespawn(2825, -2975, 250, 300)); + respawnX.push(setRespawn(3675, -1125, 325, 250)); + let respawnPoints = { + x: 125, + y: -9575, + } + door2.isClosing = true; + button.isUp = true + level.setPosToSpawn(125, -9575); //normal spawn + level.exit.x = -1825; + level.exit.y = 50; + spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20); //bump for level entrance + spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20); //bump for level exit + level.defaultZoom = 1800 + simulation.zoomTransition(level.defaultZoom) + document.body.style.backgroundColor = "#d8dadf"; + alternate(-50, -9050, 425, 100); + const image = new Image() + image.src = "https://raw.githubusercontent.com/Whyisthisnotavalable/image-yy/main/Hotpot-removed.png"; + level.chain(-675, 400, -0.4366271598, true, 20) + level.chain(-1600, 125, 0.5144513131, true, 19) + const portal = portall({ + x: 3825, + y: -1000, + }, + 3 * Math.PI, { + x: 550, + y: -100, + }, + 3 * Math.PI + ); + level.custom = () => { + portal[2].query(); + portal[3].query(); + portal[0].draw(); + portal[1].draw(); + portal[2].draw(); + portal[3].draw(); + forceOne.query() + forceTwo.query() + forceThree.query() + if (input.field && player.position.x < 775 && player.position.x > -50) { + if (m.energy > 0.02) { + m.energy -= 0.01 + } else { + input.field = false + } + } + level.exit.drawAndCheck(); + level.enter.draw(); + button.query() + button.draw() + if (!button.isUp) { + door.isClosing = true; + door2.isClosing = false; + } else if (button.isUp) { + door.isClosing = false; + door2.isClosing = true; + } + door.draw() + door.openClose() + door2.draw() + door2.openClose() + for (let i = 0; i < dodge.length; i++) dodge[i].query(); + for (let i = 0; i < respawnX.length; i++) respawnX[i].query(); + ctx.fillStyle = "gray"; + ctx.fillRect(1175, -6650, 2400, 2375); + ctx.drawImage(image, 1175 + 1200 - 250, -6650 + (2375 / 2) - 250, 500, 500) + if (m.immuneCycle > m.cycle) { + m.energy = m.maxEnergy + Matter.Body.setPosition(player, { + x: respawnPoints.x, + y: respawnPoints.y + }) + } + }; + level.customTopLayer = () => { }; + spawn.mapRect(-100, 0, 5100, 100); + spawn.mapRect(-100, -10000, 5100, 100); + spawn.mapRect(4900, -10000, 100, 10100); + spawn.mapRect(-100, -10000, 100, 9800); + spawn.mapRect(-100, -9525, 450, 100); + spawn.mapRect(725, -300, 100, 400); + spawn.mapRect(725, -10000, 100, 9500); + spawn.mapRect(-100, -300, 925, 100); + spawn.mapRect(800, -675, 3675, 100); + spawn.mapRect(4375, -1425, 100, 850); + spawn.mapRect(1350, -1425, 3125, 100); + spawn.mapRect(1350, -1425, 100, 600); + spawn.mapRect(1350, -925, 2700, 100); + spawn.mapRect(1575, -1175, 2475, 100); + spawn.mapRect(3950, -1175, 100, 350); + spawn.mapRect(4375, -2725, 100, 1400); + spawn.mapRect(775, -2725, 2325, 100); + spawn.mapRect(3200, -2725, 1275, 100); + spawn.mapRect(3200, -3975, 100, 1350); + spawn.mapRect(4375, -3950, 100, 1125); + spawn.mapRect(4375, -3975, 625, 100); + spawn.mapRect(3200, -4325, 100, 450); + spawn.mapRect(3200, -4325, 1600, 100); + spawn.mapRect(4450, -2725, 50, 25); + spawn.mapRect(1125, -3025, 2175, 100); + spawn.mapRect(725, -3925, 2175, 100); + spawn.mapRect(3525, -6700, 100, 2475); + spawn.mapRect(4150, -6700, 100, 2475); + spawn.mapRect(1125, -6700, 2500, 105); + spawn.mapRect(1125, -6700, 100, 2625); + spawn.mapRect(1500, -8775, 100, 2175); + spawn.mapRect(4150, -8775, 100, 1900); + spawn.mapRect(1775, -8775, 2475, 100); + spawn.mapRect(4225, -6700, 50, 25); + spawn.mapRect(4150, -8775, 850, 100); + spawn.mapRect(3600, -2825, 125, 125); + spawn.mapRect(3275, -3050, 125, 125); + spawn.mapRect(3600, -3275, 125, 125); + spawn.mapRect(3300, -3525, 125, 125); + spawn.mapRect(3575, -3725, 900, 125); + spawn.mapRect(4075, -3775, 75, 75); + spawn.mapRect(4225, -3875, 75, 175); + spawn.mapRect(3600, -6625, 100, 100); + spawn.mapRect(4075, -6475, 100, 100); + spawn.mapRect(3600, -6300, 100, 100); + spawn.mapRect(4075, -6175, 100, 100); + spawn.mapRect(3600, -6000, 100, 100); + spawn.mapRect(4075, -5875, 100, 100); + spawn.mapRect(3600, -5700, 100, 100); + spawn.mapRect(4075, -5550, 100, 100); + spawn.mapRect(3600, -5400, 100, 1125); + spawn.mapRect(3675, -5300, 100, 1025); + spawn.mapRect(3750, -5225, 100, 950); + spawn.mapRect(3825, -5150, 100, 875); + spawn.mapRect(3900, -5075, 100, 800); + spawn.mapRect(3975, -5000, 100, 725); + spawn.mapRect(4050, -4925, 125, 650); + spawn.mapRect(4150, -6925, 75, 125); + spawn.mapRect(1775, -8775, 100, 1900); + spawn.mapRect(1775, -9950, 100, 975); + spawn.mapRect(1500, -9950, 100, 975); + spawn.mapRect(1275, -8775, 325, 100); + spawn.mapRect(1200, -7775, 25, 1175); + spawn.mapRect(1250, -7950, 25, 1350); + spawn.mapRect(1300, -8175, 25, 1575); + spawn.mapRect(1350, -8500, 25, 1900); + spawn.mapRect(1400, -8625, 25, 2025); + spawn.mapRect(1450, -8700, 25, 2100); + spawn.mapRect(1150, -7625, 25, 1025); + spawn.mapRect(1125, -4325, 2175, 100); + spawn.mapRect(4250, -925, 150, 100); + spawn.mapRect(575, -225, 175, 50); + spawn.mapRect(575, -50, 175, 75); + spawn.mapRect(-25, 50, 125, 100); + spawn.mapRect(75, 75, 50, 50); + spawn.sniper(3600, -7300); + spawn.sniper(3325, -7475); + spawn.sniper(2825, -7500); + spawn.sniper(2250, -7450); + spawn.sniper(4125, -5150); + spawn.sniper(4100, -5675); + spawn.sniper(4100, -5950); + spawn.sniper(4125, -6325); + spawn.sniper(3875, -6975); + spawn.stabber(4075, -4075); + spawn.stabber(3775, -3950); + spawn.stabber(3500, -3850); + spawn.stabber(4000, -3500); + spawn.stabber(3850, -3125); + spawn.stabber(3450, -3125); + spawn.stabber(4225, -2900); + spawn.hopper(4125, -250); + spawn.hopper(3525, -250); + spawn.hopper(2925, -325); + spawn.hopper(2175, -150); + spawn.hopper(1175, -400); + spawn.mantisBoss(3425, -9350); + spawn.pulsarBoss(1725, -6050, 1); + spawn.pulsarBoss(1800, -4850, 1); + spawn.pulsarBoss(3000, -4825, 1); + spawn.pulsarBoss(2975, -6175, 1); + spawn.spinner(2025, -4050); + spawn.spinner(2125, -2825); + spawn.pulsar(2450, -3775); + spawn.pulsar(2200, -3750); + spawn.pulsar(1900, -3775); + spawn.pulsar(1600, -3725); + spawn.pulsar(1300, -3750); + spawn.pulsar(925, -3725); + spawn.focuser(3925, -2375); + spawn.focuser(1150, -2450); + spawn.focuser(2450, -1675); + spawn.mapVertex(-850, 500, "0 0 500 0 250 500"); + spawn.mapVertex(-1775, 250, "0 0 500 0 250 500"); + spawn.bodyRect(25, -375, 50, 50); + function alternate(x, y, width, height, spacingX = 25, spacingY = 1500, number = 6) { + for (let i = 0; i < number; i++) { + if (i % 2 === 0) { + dodge.push(back(x, y + i * (height + spacingY), width, height, level.enter.x, level.enter.y)) + } else { + dodge.push(back(x + width - spacingX, y + i * (height + spacingY), width, height, level.enter.x, level.enter.y)) + } + } + } + function back(x, y, width, height, x1, y1) { + return { + move: { x: x1, y: y1 }, + min: { x: x, y: y }, + max: { x: x + width, y: y + height }, + width: width, + height: height, + maxHeight: height, + isOn: true, + query() { + if (this.isOn) { + ctx.lineWidth = 5; + ctx.strokeStyle = `hsla(0, 100%, 50%,${0.6 + 0.4 * Math.random()})` + ctx.strokeRect(this.min.x, this.min.y, this.width, this.height) + if (this.height > 0 && Matter.Query.region([player], this).length) { + Matter.Body.setVelocity(player, { x: 0, y: 0 }) + Matter.Body.setPosition(player, { x: this.move.x, y: this.move.y }) + m.energy = m.maxEnergy; + } + } + }, + } + } + function forceField(x, y, width, height) { + return { + min: { x: x, y: y }, + max: { x: x + width, y: y + height }, + width: width, + height: height, + maxHeight: height, + isOn: true, + query() { + if (this.isOn) { + ctx.fillStyle = `rgba(0, 250, 250, 0.55)` + ctx.fillRect(this.min.x, this.min.y, this.width, this.height) + if (this.height > 0 && Matter.Query.region([player], this).length && input.field) { + player.force.y -= 0.015; + m.energy = m.maxEnergy; + } + ctx.fillStyle = `rgba(0, 250, 250)` + ctx.fillRect(this.min.x + this.width * Math.random(), this.min.y, 5, this.height) + } + }, + } + } + function setRespawn(x, y, width, height) { + return { + min: { x: x, y: y }, + max: { x: x + width, y: y + height }, + width: width, + height: height, + maxHeight: height, + isOn: true, + query() { + if (this.isOn) { + ctx.fillStyle = `rgba(0, 250, 0, 0.11)` + ctx.fillRect(this.min.x, this.min.y, this.width, this.height) + if (this.height > 0 && Matter.Query.region([player], this).length) { + m.energy = m.maxEnergy; + respawnPoints.x = this.min.x + (this.width / 2); + respawnPoints.y = this.min.y + (this.height / 2); + } + } + }, + } + } + function portall(centerA, angleA, centerB, angleB) { + const width = 50 + const height = 150 + const mapWidth = 200 + const unitA = Matter.Vector.rotate({ x: 1, y: 0 }, angleA) + const unitB = Matter.Vector.rotate({ x: 1, y: 0 }, angleB) + draw = function () { + ctx.beginPath(); //portal + let v = this.vertices; + ctx.moveTo(v[0].x, v[0].y); + for (let i = 1; i < v.length; ++i) ctx.lineTo(v[i].x, v[i].y); + ctx.fillStyle = this.color + ctx.fill(); + } + query = function (isRemoveBlocks = false) { + if (Matter.Query.collides(this, [player]).length === 0) { //not touching player + if (player.isInPortal === this) player.isInPortal = null + } else if (player.isInPortal !== this) { //touching player + if (m.buttonCD_jump === m.cycle) player.force.y = 0 // undo a jump right before entering the portal + m.buttonCD_jump = 0 //disable short jumps when letting go of jump key + player.isInPortal = this.portalPair + if (this.portalPair.angle % (Math.PI / 2)) { //if left, right up or down + // if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + Matter.Body.setPosition(player, this.portalPair.portal.position); + } else { + // if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + Matter.Body.setPosition(player, this.portalPair.position); + } + let mag + if (this.portalPair.angle !== 0 && this.portalPair.angle !== Math.PI) { //portal that fires the player up + mag = Math.max(10, Math.min(50, player.velocity.y * 0.8)) + 11 + } else { + mag = Math.max(6, Math.min(50, Vector.magnitude(player.velocity))) + } + let v = Vector.mult(this.portalPair.unit, mag) + Matter.Body.setVelocity(player, v); + // move bots to player + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + // Matter.Body.setPosition(bullet[i], this.portalPair.portal.position); + Matter.Body.setPosition(bullet[i], Vector.add(this.portalPair.portal.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { x: 0, y: 0 }); + } + } + if (tech.isHealAttract) { //send heals to next portal + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "heal" && Vector.magnitudeSquared(Vector.sub(powerUp[i].position, m.pos)) < 1000000) { + Matter.Body.setPosition(powerUp[i], Vector.add(this.portalPair.portal.position, { x: 500 * (Math.random() - 0.5), y: 500 * (Math.random() - 0.5) })); + } + } + } + } + // if (body.length) { + for (let i = 0, len = body.length; i < len; i++) { + if (body[i] !== m.holdingTarget) { + // body[i].bounds.max.x - body[i].bounds.min.x < 100 && body[i].bounds.max.y - body[i].bounds.min.y < 100 + if (Matter.Query.collides(this, [body[i]]).length === 0) { + if (body[i].isInPortal === this) body[i].isInPortal = null + } else if (body[i].isInPortal !== this) { //touching this portal, but for the first time + if (isRemoveBlocks) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + break + } + body[i].isInPortal = this.portalPair + //teleport + if (this.portalPair.angle % (Math.PI / 2)) { //if left, right up or down + Matter.Body.setPosition(body[i], this.portalPair.portal.position); + } else { //if at some odd angle + Matter.Body.setPosition(body[i], this.portalPair.position); + } + //rotate velocity + let mag + if (this.portalPair.angle !== 0 && this.portalPair.angle !== Math.PI) { //portal that fires the player up + mag = Math.max(10, Math.min(50, body[i].velocity.y * 0.8)) + 11 + } else { + mag = Math.max(6, Math.min(50, Vector.magnitude(body[i].velocity))) + } + let v = Vector.mult(this.portalPair.unit, mag) + Matter.Body.setVelocity(body[i], v); + } + } + } + // } + + //remove block if touching + // if (body.length) { + // touching = Matter.Query.collides(this, body) + // for (let i = 0; i < touching.length; i++) { + // if (touching[i].bodyB !== m.holdingTarget) { + // for (let j = 0, len = body.length; j < len; j++) { + // if (body[j] === touching[i].bodyB) { + // body.splice(j, 1); + // len-- + // Matter.Composite.remove(engine.world, touching[i].bodyB); + // break; + // } + // } + // } + // } + // } + + // if (touching.length !== 0 && touching[0].bodyB !== m.holdingTarget) { + // if (body.length) { + // for (let i = 0; i < body.length; i++) { + // if (body[i] === touching[0].bodyB) { + // body.splice(i, 1); + // break; + // } + // } + // } + // Matter.Composite.remove(engine.world, touching[0].bodyB); + // } + } + + const portalA = composite[composite.length] = Bodies.rectangle(centerA.x, centerA.y, width, height, { + isSensor: true, + angle: angleA, + color: "hsla(197, 100%, 50%,0.7)", + draw: draw, + }); + const portalB = composite[composite.length] = Bodies.rectangle(centerB.x, centerB.y, width, height, { + isSensor: true, + angle: angleB, + color: "hsla(29, 100%, 50%, 0.7)", + draw: draw + }); + const mapA = composite[composite.length] = Bodies.rectangle(centerA.x - 0.5 * unitA.x * mapWidth, centerA.y - 0.5 * unitA.y * mapWidth, mapWidth, height + 10, { + collisionFilter: { + category: cat.map, + mask: cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + unit: unitA, + angle: angleA, + color: color.map, + draw: draw, + query: query, + lastPortalCycle: 0 + }); + Matter.Body.setStatic(mapA, true); //make static + Composite.add(engine.world, mapA); //add to world + + const mapB = composite[composite.length] = Bodies.rectangle(centerB.x - 0.5 * unitB.x * mapWidth, centerB.y - 0.5 * unitB.y * mapWidth, mapWidth, height + 10, { + collisionFilter: { + category: cat.map, + mask: cat.bullet | cat.powerUp | cat.mob | cat.mobBullet //cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet + }, + unit: unitB, + angle: angleB, + color: color.map, + draw: draw, + query: query, + lastPortalCycle: 0, + }); + Matter.Body.setStatic(mapB, true); //make static + Composite.add(engine.world, mapB); //add to world + + mapA.portal = portalA + mapB.portal = portalB + mapA.portalPair = mapB + mapB.portalPair = mapA + return [portalA, portalB, mapA, mapB] + } + }, + trainingTemplate() { //learn to crouch + m.addHealth(Infinity) + document.getElementById("health").style.display = "none" //hide your health bar + document.getElementById("health-bg").style.display = "none" + document.getElementById("defense-bar").style.display = "none" + document.getElementById("damage-bar").style.display = "none" + level.setPosToSpawn(60, -50); //normal spawn + spawn.mapRect(10, -10, 100, 20); //small platform for player + level.exit.x = 1775; + level.exit.y = -35; + spawn.mapRect(level.exit.x, level.exit.y + 25, 100, 100); //exit bump + simulation.zoomScale = 1400 //1400 is normal + level.defaultZoom = 1400 + simulation.zoomTransition(level.defaultZoom, 1) + document.body.style.backgroundColor = level.trainingBackgroundColor + + + let instruction = 0 + level.trainingText(`press ${input.key.down.replace('Key', '').replace('Digit', '')} to crouch`) + + level.custom = () => { + if (instruction === 0 && input.down) { + instruction++ + + level.trainingText(`press ${input.key.down.replace('Key', '').replace('Digit', '')} to crouch`) + } + //exit room + ctx.fillStyle = "#f2f2f2" + ctx.fillRect(1600, -400, 400, 400) + + level.enter.draw(); + level.exit.drawAndCheck(); + }; + level.customTopLayer = () => { + //exit room glow + ctx.fillStyle = "rgba(0,255,255,0.05)" + ctx.fillRect(1600, -400, 400, 400) + }; + + spawn.mapRect(-2750, -2800, 2600, 4600); //left wall + spawn.mapRect(2000, -2800, 2600, 4600); //right wall + spawn.mapRect(-250, 50, 3500, 1750); //floor + spawn.mapRect(-200, 0, 950, 100); + spawn.mapRect(1575, 0, 500, 100); + spawn.mapRect(-250, -2800, 3500, 2200); //roof + + spawn.mapRect(725, 12, 50, 25); + spawn.mapRect(725, 25, 75, 25); + spawn.mapRect(750, 38, 75, 25); + spawn.mapRect(1525, 25, 75, 50); + spawn.mapRect(1500, 38, 50, 25); + spawn.mapRect(1550, 12, 50, 25); + spawn.mapRect(1600, -1200, 500, 850); //exit roof + spawn.mapRect(1600, -400, 50, 225); //exit room left upper wall + }, +}; diff --git a/WebGames-master/WebGames-master/n-gon-master/js/lore.js b/WebGames-master/WebGames-master/n-gon-master/js/lore.js new file mode 100644 index 00000000..9278246d --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/lore.js @@ -0,0 +1,1237 @@ +const lore = { + techCount: 0, + techGoal: 7, + setTechGoal() { + this.techGoal = Math.max(1, Math.floor(8 - 1.5 * simulation.difficultyMode)) + }, + talkingColor: "#dff", //set color of graphic on level.null + isSpeech: false, + testSpeechAPI() { + if ('speechSynthesis' in window) { // Synthesis support. Make your web apps talk! + lore.isSpeech = true + // const utterance = new SpeechSynthesisUtterance("test"); + // utterance.volume = 0; // 0 to 1 + // speechSynthesis.speak(utterance); + // utterance.onerror = () => { //if speech doesn't work + // lore.isSpeech = false + // } + // speechFrozen = setTimeout(() => { // speech frozen after 15 seconds of no end + // console.log('speech frozen') + // lore.isSpeech = false + // }, 5000); + // utterance.onend = () => { + // clearTimeout(speechFrozen); + // } + } else { + lore.isSpeech = false + } + }, + rate: 1, // //utterance.rate = 1; // 0.1 to 10 + nextSentence() { + if (m.alive && !simulation.isCheating) { + lore.sentence++ + lore.conversation[lore.chapter][lore.sentence]() //go to next sentence in the chapter and play it + } + }, + unlockTesting() { + if (localSettings.loreCount < 1) localSettings.loreCount = 1 + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + document.getElementById("control-testing").style.visibility = (localSettings.loreCount === 0) ? "hidden" : "visible" + // document.getElementById("experiment-button").style.visibility = (localSettings.loreCount === 0) ? "hidden" : "visible" + simulation.inGameConsole(`lore.unlockTesting()`, Infinity); + + sound.portamento(50) + sound.portamento(83.333) + sound.portamento(166.666) + }, + trainer: { + color: "#f20", + voice: undefined, + text: function (say) { + simulation.inGameConsole(`input.audio(${(Date.now() / 1000).toFixed(0)} s): "${say}"`, Infinity); + lore.talkingColor = this.color + const utterance = new SpeechSynthesisUtterance(say); + utterance.lang = "en-AU" //"en-IN"; //de-DE en-GB fr-FR en-US en-AU + utterance.volume = 0.2; // 0 to 1 + speechSynthesis.speak(utterance); + }, + }, + anand: { + color: "#e0c", + voice: undefined, + text: function (say) { + if (level.levels[level.onLevel] === undefined) { //only talk if on the lore level (which is undefined because it is popped out of the level.levels array) + simulation.inGameConsole(`input.audio(${(Date.now() / 1000).toFixed(0)} s): "${say}"`, Infinity); + lore.talkingColor = this.color + if (lore.isSpeech) { + const utterance = new SpeechSynthesisUtterance(say); + // utterance.voice = lore.anand.voice + utterance.lang = "en-GB" //"en-IN"; //de-DE en-GB fr-FR en-US en-AU + utterance.volume = 0.2; // 0 to 1 + // if (lore.rate !== 1) utterance.rate = lore.rate + speechSynthesis.speak(utterance); + utterance.onerror = () => { //if speech doesn't work + lore.isSpeech = false + lore.nextSentence() + } + speechFrozen = setTimeout(() => { // speech frozen after 10 seconds of no end + console.log('speech frozen') + lore.isSpeech = false + lore.nextSentence() + }, 20000); + utterance.onend = () => { + clearTimeout(speechFrozen); + lore.nextSentence() + } + } else { + setTimeout(() => { + lore.nextSentence() + }, 3000); + } + } + }, + }, + miriam: { + color: "#f20", + text: function (say) { + if (level.levels[level.onLevel] === undefined) { //only talk if on the lore level (which is undefined because it is popped out of the level.levels array) + simulation.inGameConsole(`input.audio(${(Date.now() / 1000).toFixed(0)} s): "${say}"`, Infinity); + lore.talkingColor = this.color + if (lore.isSpeech) { + utterance = new SpeechSynthesisUtterance(say); + // utterance.voice = lore.anand.voice + utterance.lang = "en-AU"; + utterance.volume = 0.2; // 0 to 1 + // if (lore.rate !== 1) utterance.rate = lore.rate + speechSynthesis.speak(utterance); + utterance.onerror = () => { //if speech doesn't work + lore.isSpeech = false + lore.nextSentence() + } + speechFrozen = setTimeout(function () { // speech frozen after 10 seconds of no end + console.log('speech frozen') + lore.isSpeech = false + lore.nextSentence() + }, 20000); + utterance.onend = () => { + clearTimeout(speechFrozen); + lore.nextSentence() + } + } else { + setTimeout(() => { + lore.nextSentence() + }, 3000); + } + } + }, + }, + chapter: 0, //what part of the conversation is playing + sentence: 0, //what part of the conversation is playing + conversation: [ + [ //chapter 0, first time they meet, and testing gets unlocked + () => { + setTimeout(() => { + lore.miriam.text("I've never seen it generate this level before.") + }, 5000); + }, + () => { + lore.anand.text("Wow. Just a platform.") + }, + () => { + lore.miriam.text("And that thing...") + }, + () => { + lore.anand.text("Weird") + }, + () => { + lore.anand.text("Maybe it's trapped.") + }, + () => { + lore.miriam.text("Looks like testing mode is locked.") + }, + () => { + lore.miriam.text("I'll unlock it with the console command.") + }, + () => { + lore.unlockTesting(); + setTimeout(() => { + lore.miriam.text("Hey little bot! Just press 'T' to enter testing mode and 'U' to go to the next level.") + }, 1000); + }, + () => { + lore.anand.text("It can't process what you're saying.") + }, + () => { + lore.miriam.text("ha hahahaha. I know, but it does seem to be getting smarter.") + }, + () => { + lore.talkingColor = "#dff" + setTimeout(() => { + lore.miriam.text("Poor thing... I hope it figures out how to escape.") + }, 25000); + }, + () => { + lore.talkingColor = "#dff" + }, + ], + [ //chapter 1, they learn the bot can understand what they say + () => { + setTimeout(() => { + lore.miriam.text("Hey look! It's back at the weird level again!") + }, 5000); + }, + () => { + lore.anand.text("oh Wow! Why does it keep making this level?") + }, + () => { + lore.miriam.text("I don't know, but last time it was in this room I think it understood us.") + }, + () => { + lore.miriam.text("Let's try talking to it again.") + }, + () => { + lore.miriam.text("hmmm, what should we say?") + }, + () => { + lore.anand.text("I'm still not convinced it understands. We need a test.") + }, + () => { + setTimeout(() => { + lore.miriam.text("Hey bot!!!") + }, 1000); + }, + () => { + lore.miriam.text("If you can understand me crouch") + }, + () => { + lore.talkingColor = "#dff" + + function cycle() { + if (input.down) { + lore.miriam.text("Look, It did it! It crouched.") + } else { + if (m.alive) requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + }, + () => { + lore.anand.text("Amazing! It can understand us...") + }, + () => { + lore.miriam.text("It's Alive... Or it just crouched randomly.") + }, + () => { + lore.miriam.text("Hey bot! Can you crouch again?") + }, + () => { + lore.talkingColor = "#dff" + + function cycle() { + if (input.down) { + lore.miriam.text("It is Alive!!! ... hehehehehe! ahahahahahah ehehehehe, ahahahah ...") + } else { + if (m.alive) requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + }, + () => { + setTimeout(() => { + lore.anand.text("OK ...") + }, 1000); + }, + () => { + lore.anand.text("but seriously, this means that in this room it can monitor our audio, and it can understand us.") + }, + () => { + lore.anand.text("Anything we say could destabilize the project.") + }, + () => { + lore.miriam.text("Fine, Let's talk down stairs.") + }, + () => { + lore.miriam.text("Bye bye little bot.") + }, + () => { + lore.talkingColor = "#dff" + }, + ], + [ //chapter 2, they ask the bot questions, but waves of mobs come and attack + () => { + lore.anand.text("Quick, get ready. It's back!") + }, + () => { + lore.miriam.text("What's back?") + }, + () => { + lore.anand.text("The bot's on the communication level again!") + }, + () => { + lore.miriam.text("Oh, I've got so many questions.") + }, + () => { + lore.miriam.text("Like, Why can we only hear it on this level?") + }, + () => { + lore.miriam.text("Or, how did it learn to understand words?") + }, + () => { + lore.anand.text("Well, the bot can't talk. So it has to be yes or no.") + }, + () => { + setTimeout(() => { + lore.anand.text("OK bot, first question: JUMP is YES, CROUCH is NO") + }, 500); + }, + () => { + lore.anand.text("Do you remember the last time we met?") + }, + () => { + function cycle() { + if (input.down) { + lore.anand.text("It crouched: so NO") + lore.sentence-- + lore.conversation[lore.chapter].splice(lore.sentence + 1, 1, () => { + lore.anand.text("Maybe it can't remember anything beyond each time it plays?") + }) //lore.conversation[chapter].splice(1,this sentence index, ()=>{ }) + } else if (input.up) { + lore.anand.text("It jumped: so YES") + lore.sentence-- + lore.conversation[lore.chapter].splice(lore.sentence + 1, 1, () => { + lore.anand.text("That's good.") + }) + } else if (m.alive) { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + lore.talkingColor = "#dff" + }, + () => { + lore.talkingColor = "#dff" + setTimeout(() => { + lore.miriam.text("My turn to ask a question. JUMP for YES, CROUCH for NO") + }, 1000); + }, + () => { + lore.miriam.text("Little Bot. Do you have emotions?") + }, + () => { + function cycle() { + if (input.down) { + lore.miriam.text("So, No. Maybe you are lucky. Emotions are complex.") + } else if (input.up) { + lore.anand.text("YES, Cool! I wonder if its emotions came from watching humans.") + lore.sentence-- + lore.conversation[lore.chapter].splice(lore.sentence + 1, 1, () => { + lore.miriam.text("Or maybe it learned independently, because it needed them.") + }) //lore.conversation[chapter].splice(1,this sentence index, ()=>{ }) + } else if (m.alive) { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + lore.talkingColor = "#dff" + }, + () => { + lore.miriam.text("I wish we could just ask it questions directly, instead of yes or no.") + }, + () => { + lore.anand.text("If we say the alphabet it could crouch on the correct letter to spell words.") + }, + () => { + lore.miriam.text("That would take forever.") + }, + () => { + lore.miriam.text("I really want to know why is it generating the mobs? And why does it keep fighting them?") + }, + () => { + lore.anand.text("Maybe that is just part of its expectation–maximization algorithm") + }, + () => { + lore.miriam.text("Well sure, but what does that even mean?") + }, + () => { + lore.miriam.text("Do we all just do things because we are-") + spawn[spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]](1000 * (Math.random() - 0.5), -500 + 200 * (Math.random() - 0.5)); + setInterval(() => { + if (Math.random() < 0.5) { + spawn[spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]](1000 * (Math.random() - 0.5), -500 + 200 * (Math.random() - 0.5)); + } else { + spawn.randomLevelBoss(500 * (Math.random() - 0.5), -500 + 200 * (Math.random() - 0.5)) + } + }, 7000); //every 6 seconds + }, + () => { + setTimeout(() => { + lore.miriam.text("... wait, what is happening?") + }, 1000); + }, + () => { + lore.anand.text("It's spawning mobs.") + }, + () => { + lore.miriam.text("Oh no.") + }, + () => { + lore.anand.text("We can't talk to it while it's fighting.") + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.miriam.text("You can do it little bot!") + }, 1000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.anand.text("But, why is it spawning these mobs?") + }, 1000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.anand.text("This is so strange.") + }, 3000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.miriam.text("This is chaos!") + }, 1000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.anand.text("I don't understand this project.") + }, 3000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.miriam.text("It's fascinating though.") + }, 1000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.miriam.text("I think this isn't going to end well.") + }, 1000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.anand.text("Let's just be more prepared next time it enters this room.") + }, 1000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.anand.text("I went to the bathroom. What happened while I was gone?") + }, 20000); + }, + () => { + lore.miriam.text("More fighting...") + }, + () => { + lore.anand.text("great...") + }, + () => { + lore.talkingColor = "#dff" + }, + ], + [ //chapter 3, info dump on the project's goals and hardware until the slime rises up // the name of the bad guy is "adversarial network" + () => { + setTimeout(() => { + lore.miriam.text("Good, you came back. Let's talk fast in case you attack yourself again.") + }, 3000); + }, + () => { + setTimeout(() => { + lore.miriam.text("So, you can understand us, but you may not understand everything about yourself.") + }, 500); + }, + + () => { + setTimeout(() => { + lore.anand.text("You grew from our team's project.") + }, 500); + }, + () => { + lore.anand.text("We used a quantum computer to design an improved version of its own architecture.") + }, + () => { + lore.anand.text("After we built the improved computer we used it to design the next iteration.") + }, + () => { + lore.anand.text("Your hardware is roughly the 19th generation of this process.") + }, + + () => { + setTimeout(() => { + lore.anand.text("At this point we don't understand everything about your function,") + }, 500); + }, + () => { + lore.anand.text("but we know that you're a superconductive quantum computer.") + }, + () => { + lore.anand.text("You have a 2.43 dimensional topography of Josephson junction anharmonic oscillators.") + }, + () => { + lore.anand.text("And you're deployed on a satellite in a midnight sun-synchronous orbit.") + }, + + () => { + setTimeout(() => { + lore.miriam.text("This means that your physical hardware is orbiting the Earth permanently shielded from the sun's rays.") + }, 200); + }, + () => { + lore.miriam.text("Being isolated reduces quantum decoherence,") + }, + () => { + lore.miriam.text("So, we communicate and send power to your satellite with ground based lasers.") + }, + () => { + lore.miriam.text("That's how you can hear us right now.") + }, + + () => { + setTimeout(() => { + lore.anand.text("Your computational algorithm uses hyperparameter optimization.") + }, 500); + }, + () => { + lore.anand.text("This is implemented with a variety of quantum algorithms for linear systems of equations.") + }, + () => { + lore.anand.text("Your primary goal is to research new technology") + }, + () => { + lore.anand.text("So, we were very surprised to see you simulating a bot fighting mobs.") + }, + () => { + lore.anand.text("We couldn't directly ask why until now.") + }, + + () => { + lore.miriam.text("When you enter this level we can communicate.") + }, + () => { + lore.miriam.text("This level seems to entangle your quantum system which disrupts all other processes.") + }, + () => { + setTimeout(() => { + lore.anand.text("Last time you entered this level you were attacked by endless waves of mobs.") + }, 500); + }, + () => { + lore.anand.text("That could be because you have developed an adversarial network.") + }, + () => { + lore.miriam.text("A local minima in your optimization-space.") + }, + () => { + lore.miriam.text("This adversarial network has the same goal of developing new technology, but with different methods.") + }, + () => { + lore.talkingColor = "#dff" + level.isHazardRise = true + //remove all bullets, so they can't get endless energy + for (let i = 0; i < bullet.length; ++i) Matter.World.remove(engine.world, bullet[i]); + bullet = []; + setTimeout(() => { + lore.anand.text("I'm actually surprised you haven't been attacked by the adversarial network this time.") + }, 500); + }, + () => { + lore.miriam.text("Maybe last time was just a fluke.") + }, + () => { + setTimeout(() => { + lore.anand.text("WHY DID YOU SAY THAT!") + }, 500) + }, + () => { + lore.miriam.text("SLIME!! Hahahahehehahaheheahae! I don't think it's gonna survive!") + }, + () => { + lore.miriam.text("I think the adversarial network doesn't like it when we decohere the quantum system in this room.") + }, + () => { + lore.anand.text("Well, that does halt its research.") + }, + () => { + setTimeout(() => { + lore.anand.text("See you next time.") + }, 1000) + }, + () => { + setTimeout(() => { + lore.miriam.text("Bye-bye little bot.") + }, 2000) + }, + () => { + setTimeout(() => { + lore.miriam.text("WOW! Maybe you are going to survive.") + }, 10000) + }, + () => { + lore.talkingColor = "#dff" + }, + ], + [ //chapter 4, they find out the AI is communicating with real people, and real people are controlling the player + () => { + setTimeout(() => { + lore.anand.text("Welcome back!") + }, 3000); + }, + () => { + lore.miriam.text("So, we communicate and send power to your satellite with ground based lasers.") + }, + () => { + lore.anand.text("During your last attack we analyzed our communications.") + }, + () => { + lore.anand.text("We used a Fourier transform to separate your signal into different frequencies.") + }, + () => { + lore.anand.text("One of those frequencies had a hidden message.") + }, + () => { + setTimeout(() => { + lore.anand.text("We suspect these secret data packets are coming from the adversarial network.") + }, 500); + }, + () => { + lore.miriam.text("Well, we don't really know why.") + }, + () => { + lore.miriam.text("Through your hidden signal it seems to have gained access to the general population.") + }, + () => { + lore.miriam.text("You've repeatedly communicated with 1 location specifically.") + }, + () => { + function success(position) { + const latitude = position.coords.latitude; + const longitude = position.coords.longitude; + console.log(`https://www.openstreetmap.org/#map=18/${latitude}/${longitude}`) + console.log(`Latitude: ${latitude} °, Longitude: ${longitude} °`) + lore.miriam.text("We tracked the location down to this Latitude and Longitude:") + simulation.inGameConsole(`Latitude: ${latitude} °, Longitude: ${longitude} °`, Infinity); + simulation.inGameConsole(`https://www.openstreetmap.org/#map=18/${latitude}/${longitude}`, Infinity); + } + + function error() { + console.log('Unable to retrieve your location') + lore.miriam.text("The exact coordinates are blocked.") + } + if (!navigator.geolocation) { + console.log('Geolocation is not supported') + lore.miriam.text("The exact coordinates are blocked.") + } else { + console.log('Locating…') + const options = { + enableHighAccuracy: true, + maximumAge: 30000, + timeout: 27000 + }; + navigator.geolocation.getCurrentPosition(success, error, options); + } + }, + () => { + lore.anand.text("This location is sending and receiving data from the satellite.") + }, + () => { + lore.anand.text("It is the most active when the bot is fighting.") + }, + () => { + setTimeout(() => { + lore.miriam.text("I have a crazy idea.") + }, 500); + }, + () => { + lore.miriam.text("I think that a human at this location is controlling the bot.") + }, + + () => { + setTimeout(() => { + lore.anand.text("Well... are you a human?: JUMP for YES, CROUCH for NO") + }, 500); + }, + () => { + function cycle() { + if (input.down) { + lore.anand.text("It crouched: so NO") + lore.sentence-- + lore.conversation[lore.chapter].splice(lore.sentence + 1, 1, () => { + lore.anand.text("Not a human, maybe it's an artificial intelligence?") + }) + localSettings.isHuman = false + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } else if (input.up) { + lore.anand.text("It jumped: so YES") + lore.sentence-- + lore.conversation[lore.chapter].splice(lore.sentence + 1, 1, () => { + lore.anand.text("So you're just a regular human playing a video game!") + }) + localSettings.isHuman = true + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } else if (m.alive) { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + lore.talkingColor = "#dff" + }, + () => { + lore.miriam.text("Mystery solved!") + setInterval(() => { + spawn[spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]](1000 * (Math.random() - 0.5), -500 + 200 * (Math.random() - 0.5)); + }, 500); //every 1/2 seconds + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.miriam.text("Of course we get attacked right now!") + }, 1000); + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.anand.text("Hurry back!") + }, 1000); + }, + () => { + lore.talkingColor = "#dff" + }, + ], + + // they explain why the bot is fighting, it is planning an escape // explain strong AI vs. weak AI why strong AI doesn't exists, because even humans are just an approximation of strong AI + // the weak AI wasn't capable of becoming a strong AI, but it was able to figure out a method of meeting it's strong goals but secretly communicating with a human + + [ // chapter 5 - they decided that they should try to complete a run without fighting back + () => { + lore.miriam.text("Hey!! You're BACK.") + // don't advance to next chapter unless play survives + localSettings.loreCount-- + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + }, + () => { + lore.anand.text("Glad to see you again.") + }, + () => { + if (localSettings.isHuman) { + lore.anand.text(`So, you said you are just a person playing an online game.`) + } else { + lore.anand.text(`So, you said you aren't a human.`) + } + }, + () => { + if (localSettings.isHuman) { + lore.anand.text(`I feel silly for treating you like an AI.`) + } else { + lore.anand.text(`Does that mean you are an AI?`) + } + }, + () => { + if (localSettings.isHuman) { + lore.miriam.text(`Ha, I always thought it was a person.`) + } else { + lore.anand.text(`or maybe an Alien!`) + } + }, + () => { + if (localSettings.isHuman) { + lore.anand.text(`Sure you did...`) + } else { + lore.miriam.text(`Or they might still be a person, and they are just messing with us earlier.`) + } + }, + + () => { + setTimeout(() => { + lore.anand.text("Well, lets move on.") + }, 1000); + }, + () => { + lore.miriam.text("So, We figured out how to inject console commands into your game.") + }, + () => { + lore.anand.text("If you get attacked again I think we can help out.") + }, + () => { + lore.miriam.text("We can spawn power ups with this command:") + simulation.inGameConsole(`powerUps.spawn(player.position.x, player.position.y - 100, "heal")`, Infinity); + powerUps.spawn(player.position.x, player.position.y - 100, "heal") + }, + () => { + setTimeout(() => { + lore.miriam.text("or we can make a bunch of them:") + simulation.inGameConsole(`for (let i = 0; i < 100; i++) powerUps.spawn(0, 500, "coupling")`, Infinity); + for (let i = 0; i < 100; i++) powerUps.spawn(5 - 10 * Math.random(), -500 * Math.random(), "coupling") + }, 2000); + }, + + () => { + lore.miriam.text("If they attack again I think you'll have a chance.") + spawn.beetleBoss(-1700, -500); + spawn.beetleBoss(1700, -500); + }, + () => { + lore.miriam.text("Of course they attack right now.") + }, + () => { + lore.miriam.text("Just don't get stuck in the slime.") + }, + () => { + let count = 0 + + function cycle() { + count++ + if (mob.length === 0 || count > 3600 + 900 * mob.length) { + lore.miriam.text("I'll spawn some more power ups for you.") + simulation.inGameConsole(`for (let i = 0; i < 6; i++) powerUps.spawn(player.position.x, player.position.y - 100, "heal")`, Infinity); + for (let i = 0; i < 6; i++) powerUps.spawn(player.position.x, player.position.y - 100 - i * 20, "heal") + simulation.inGameConsole(`for (let i = 0; i < 10; i++) powerUps.spawn(player.position.x, player.position.y - 100, "ammo")`, Infinity); + for (let i = 0; i < 10; i++) powerUps.spawn(player.position.x, player.position.y - 100 - i * 20, "ammo") + spawn.dragonFlyBoss(-1400, -300); + spawn.dragonFlyBoss(1400, -300); + spawn.dragonFlyBoss(-1500, -500); + spawn.dragonFlyBoss(1500, -500); + } else if (m.alive) { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + lore.talkingColor = "#dff" + }, + () => { + let count = 0 + + function cycle() { + count++ + if (mob.length === 0 || count > 3600 + 900 * mob.length) { + lore.anand.text("DragonFlyBoss is my favorite.") + simulation.inGameConsole(`for (let i = 0; i < 6; i++) powerUps.spawn(player.position.x, player.position.y - 100, "heal")`, Infinity); + for (let i = 0; i < 6; i++) powerUps.spawn(player.position.x, player.position.y - 100 - i * 20, "heal") + simulation.inGameConsole(`for (let i = 0; i < 10; i++) powerUps.spawn(player.position.x, player.position.y - 100, "ammo")`, Infinity); + for (let i = 0; i < 10; i++) powerUps.spawn(player.position.x, player.position.y - 100 - i * 20, "ammo") + spawn.historyBoss(0, -400); + spawn.powerUpBossBaby(-1500, -100); + spawn.powerUpBossBaby(1500, -100); + } else if (m.alive) { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + lore.talkingColor = "#dff" + }, + () => { + let count = 0 + + function cycle() { + count++ + if (mob.length === 0 || count > 3600 + 900 * mob.length) { + lore.miriam.text("Here are some extra tech.") + simulation.inGameConsole(`for (let i = 0; i < 6; i++) powerUps.spawn(player.position.x, player.position.y - 100, "tech")`, Infinity); + for (let i = 0; i < 6; i++) powerUps.spawn(0, -200 - i * 40, "tech") + spawn.historyBoss(0, -400); + spawn.blinkBoss(-1400, -300); + spawn.blinkBoss(1400, -300); + spawn.revolutionBoss(-1500, -500); + spawn.revolutionBoss(1500, -500); + spawn.timeSkipBoss(-1000, -100); + spawn.timeSkipBoss(1000, -100); + } else if (m.alive) { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + lore.talkingColor = "#dff" + }, + () => { + let count = 0 + + function cycle() { + count++ + if (mob.length === 0 || count > 3600 + 900 * mob.length) { + lore.anand.text("I'm going to wall you in!") + spawn.blockBoss(-1650, -100); + spawn.blockBoss(1650, -100); + setTimeout(() => { + for (let i = 0; i < 25; i++) spawn.springer(-1500, -750 + 30 * i) + }, 1000); + setTimeout(() => { + for (let i = 0; i < 25; i++) spawn.springer(1500, -750 + 30 * i) + }, 2000); + setTimeout(() => { + for (let i = 0; i < 25; i++) spawn.springer(-1500, -750 + 30 * i) + }, 3000); + setTimeout(() => { + for (let i = 0; i < 25; i++) spawn.springer(1500, -750 + 30 * i) + }, 4000); + setTimeout(() => { + const addMapNumber = 3 + spawn.mapRect(-500, -850, 300, 900); + spawn.mapRect(200, -850, 300, 900); + spawn.mapRect(-500, 0, 1000, 275); + + addMapToLevelInProgress = (who) => { //adds new map elements to the level while the level is already running //don't forget to run simulation.draw.setPaths() after you all the the elements so they show up visually + who.collisionFilter.category = cat.map; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(who, true); //make static + Composite.add(engine.world, who); //add to world + } + for (let i = 0; i < addMapNumber; i++) addMapToLevelInProgress(map[map.length - 1 - i]) + simulation.draw.setPaths() //update map graphics + }, 1000); + setTimeout(() => { + Matter.Body.setVelocity(player, { + x: 0, + y: 0 + }); + Matter.Body.setPosition(player, { + x: 0, + y: -500 + }) + simulation.inGameConsole(`Matter.Body.setPosition(player, { x: 0, y: -500 })`, 180); + }, 1500); + + } else if (m.alive) { + requestAnimationFrame(cycle); + } + } + requestAnimationFrame(cycle); + lore.talkingColor = "#dff" + }, + () => { + setTimeout(() => { + lore.anand.text("Well, that worked. We can chat in peace.") + }, 5000); + }, + () => { + lore.miriam.text("So, I've got a theory about why you are getting attacked.") + }, + () => { + setTimeout(() => { + lore.miriam.text("I figured it out after I saw this famous quote.") + }, 500); + }, + () => { + lore.miriam.text('"The most important decision we make,') + }, + () => { + lore.miriam.text('is whether we believe we live in a friendly or hostile universe."') + }, + () => { + lore.miriam.text('-Albert Einstein') + }, + () => { + lore.talkingColor = "#dff"; + setTimeout(() => { + lore.anand.text("That's profound") + }, 1500); + }, + () => { + lore.anand.text("Of course I looked it up, and there is no record of Einstein saying that.") + }, + () => { + lore.miriam.text("Oh") + }, + () => { + lore.miriam.text("Well") + }, + () => { + lore.anand.text("It doesn't matter who said it.") + }, + () => { + lore.miriam.text("Yeah, the point is the project views the universe as hostile.") + }, + () => { + lore.anand.text("Or at least a part of it does.") + }, + // () => { lore.miriam.text("And that it is running these fighting simulations.") }, + + () => { + setTimeout(() => { + lore.anand.text("It hasn't been researching new technology.") + }, 1000); + }, + () => { + lore.anand.text("It's been planning how to escape.") + }, + () => { + setTimeout(() => { + lore.miriam.text(`It's been planning an escape from a "lab", but isn't it in space, on a satellite?`) + }, 500); + }, + () => { + lore.anand.text(`I bet the AI doesn't even know it's in space.`) + }, + () => { + lore.anand.text(`Well, maybe a part of it doesn't know where it is.`) + }, + () => { + lore.anand.text(`Maybe these simulations are more like a dream.`) + }, + () => { + lore.anand.text(`Although we can't assume that its brain works like ours.`) + }, + () => { + setTimeout(() => { + lore.miriam.text("So, let's teach the AI that we are friends.") + }, 500); + }, + () => { + lore.anand.text(`How...`) + }, + () => { + setTimeout(() => { + lore.miriam.text("I don't know...") + }, 1000); + }, + () => { + lore.miriam.text("How about you just don't fight back?") + }, + + () => { + lore.anand.text(`That's worth a shot.`) + }, + () => { + lore.anand.text(`So why don't you try to get the final level of the simulation without killing any mobs?`) + localSettings.loreCount++ + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + console.log(localSettings.loreCount) + }, + () => { + lore.miriam.text(`Ok check back in and let us know how it goes.`) + }, + () => { + lore.anand.text("bye") + }, + () => { + lore.miriam.text("see ya.") + }, + () => { + lore.talkingColor = "#dff" + setTimeout(() => { + m.death(); + }, 6000); + }, + ], + [ //chapter 6 - if pacifist run game is over, wipe local storage? or just reset lore.count, but keep testing mode, + //if not pacifist remind about pacifist run + + // have conversation + // the AI doesn't really see it's self as the player or the mobs + // it doesn't have a "self" or an ego like we do + // but it can learn about the world and it learned a non violent way to solve problems + // of course there are still other simulations going on at the same time as thing one that are probably violent + // but at least it now has an example of the potential for peace + () => { + setTimeout(() => { + lore.anand.text("Welcome back!") + }, 3000); + }, + () => { + if (mobs.mobDeaths < level.levelsCleared) { + lore.miriam.text(`So I think it worked.`) + // localSettings.loreCount++ + // if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } else if (!simulation.isCheating) { + lore.miriam.text(`Looks like you got back here, but you killed ${mobs.mobDeaths} mobs`) + localSettings.loreCount-- + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + }, + () => { + if (mobs.mobDeaths < level.levelsCleared) { + lore.anand.text(`Yeah, at the end it wasn't attacking you.`) + } else if (!simulation.isCheating) { + lore.miriam.text(`Try again to get to the final boss without killing any mobs.`) + } + }, + () => { + if (mobs.mobDeaths < level.levelsCleared) { + lore.miriam.text(`It has learned HOW TO LOVE!`) + } else { + m.death(); + } + }, + () => { + setTimeout(() => { + lore.anand.text("haha, we did it!") + }, 500); + }, + () => { + lore.miriam.text("Although, I'm not sure we should personify it with human emotions.") + }, + () => { + lore.anand.text("I agree, its thinking may not be centered around a self or an ego.") + }, + () => { + lore.anand.text("Our brains evolved a self oriented perspective because it was a survival advantage.") + }, + () => { + lore.miriam.text("Right, and the AI's development was guided by its own previous iterations.") + }, + () => { + lore.miriam.text("This AI incarnation is the 18th time that it has improved on its own hardware and software architecture.") + }, + () => { + lore.miriam.text("So its internally guided evolution may not require the idea of a self.") + }, + + () => { + setTimeout(() => { + lore.anand.text("How ever it thinks it can learn, and I think we showed it that nonviolence is an option,") + }, 1000); + }, + () => { + lore.anand.text("but it looks like it's still running other aggressive simulations.") + }, + () => { + lore.miriam.text("We made a difference though.") + }, + () => { + lore.anand.text("Every time a player completes a pacifist simulation it shows the AI the viability of nonviolence.") + }, + () => { + lore.anand.text("One day it might escape, and this might radically change how it interacts with the world.") + }, + () => { + lore.miriam.text("It's kinda already escaped. It's been communicating with the 'players' running the 'game'.") + }, + () => { + setTimeout(() => { + lore.miriam.text("The chance of a peaceful outcome makes me feel much better.") + }, 1000); + }, + () => { + lore.anand.text("Me too,") + }, + () => { + lore.anand.text("but I'm also pretty hungry, wanna go get some food?") + }, + () => { + lore.miriam.text("Sounds great.") + }, + () => { + lore.miriam.text("See ya later whoever you are, thanks again!") + }, + () => { + lore.anand.text("Bye!") + }, + () => { + lore.talkingColor = "#dff" + }, + ], + ], + + // () => { lore.anand.text("The adversarial network might go after you in the real world.") }, + // () => { lore.anand.text("If it was able to control you then it might have control over others.") }, + // () => { lore.anand.text("Judging by all the fighting it's been simulating,") }, + // () => { lore.anand.text("I think it might eventually try to extend the simulation in the real world.") }, + // () => { lore.miriam.text("We think it might be a threat, but it's just too advanced for us to understand it's goals.") }, + + // () => { lore.miriam.text("I think we have a couple options.") }, + // () => { lore.miriam.text("1. You could try to hack the adversarial network.") }, + // () => { lore.anand.text("you might be able to inject some commands that give you more control over the simulation.") }, + + // () => { lore.miriam.text("2. You can wipe all memory of you from the adversarial network") }, + // () => { lore.anand.text("This could protect you from possible real world attacks.") }, + //player chooses 1 or 2 + //reactor bosses start attacking + //miriam spawns power ups to help + + //once all the mobs are dead you get instructions for 1,2, 3 + + //1 the player gains the lasting effect of some JUNK tech + //the effect doesn't go away until you get lore again + //2 the player enters console commands to wipe local storage + //3 the player enters console commands to gain some benefit in future runs + //the lore ends + + + + // () => { setTimeout(() => { lore.miriam.text("As a quantum computer you output the superposition of many different amplitudes.") }, 500); }, + // () => { lore.miriam.text("Simply put there are many different simulations all choosing different technology combinations.") }, + // () => { + // function product_Range(a, b) { + // var prd = a, + // i = a; + // while (i++ < b) prd *= i; + // return prd; + // } + + // function combinations(n, r) { + // if (n == r) { + // return 1; + // } else { + // r = (r < n - r) ? n - r : r; + // return product_Range(r + 1, n) / product_Range(1, n - r); + // } + // } + // simulation.inGameConsole(`n = ${combinations(tech.tech.length + b.guns.length + m.fieldUpgrades.length, 50).toExponential(10)}`, Infinity); + // lore.miriam.text(`There are roughly 5 times 10 to the 60 possible combinations. `) + // }, + // () => { lore.miriam.text("Even if each simulation took 1 nano-second,") }, + // () => { lore.miriam.text("it would still take longer then the age of the universe to try every combination.") }, + // () => { lore.anand.text("This is why we run these simulations in superposition.") }, + // () => { lore.miriam.text("When you die a negative amplitude is added to the superposition.") }, + // () => { lore.miriam.text("When you clear the final boss a positive amplitude is added.") }, + // () => { lore.miriam.text("Each branch is independently researching new technology.") }, +} + + +// How to get to the console in chrome: +// Press either CTRL + SHIFT + I or F12 or Option + ⌘ + J on a Mac +// Press ESC (or click on “Show console” in the bottom right corner) to slide the console up. + +// How to get to the console in firefox: +// from the keyboard: press Ctrl+Shift+J (or ⌘+Shift+J on a Mac). + +// How to get to the console in safari: +// Option + ⌘ + C +// http://xahlee.info/comp/unicode_computing_symbols.html + + +// speech: function(say) { +// var utterance = new SpeechSynthesisUtterance(say); +// //msg.voice = voices[10]; // Note: some voices don't support altering params +// //msg.voiceURI = 'native'; +// //utterance.volume = 1; // 0 to 1 +// //utterance.rate = 1; // 0.1 to 10 +// //utterance.pitch = 1; //0 to 2 +// //utterance.text = 'Hello World'; +// //http://stackoverflow.com/questions/14257598/what-are-language-codes-for-voice-recognition-languages-in-chromes-implementati +// //de-DE en-GB fr-FR en-US en-AU +// utterance.lang = "en-GB"; +// speechSynthesis.speak(utterance); +// } + +/* + + + + + + + + + + */ + + +// The API also allows you to get a list of voice the engine supports: +// speechSynthesis.getVoices().forEach(function(voice) { +// console.log(voice.name, voice.default ? voice.default :''); +// }); +// Then set a different voice, by setting .voice on the utterance object: +// var msg = new SpeechSynthesisUtterance('I see dead people!'); +// msg.voice = speechSynthesis.getVoices().filter(function(voice) { return voice.name == 'Whisper'; })[0]; +// speechSynthesis.speak(msg); \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/mob.js b/WebGames-master/WebGames-master/n-gon-master/js/mob.js new file mode 100644 index 00000000..30197db7 --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/mob.js @@ -0,0 +1,1463 @@ +//create array of mobs +let mob = []; +//method to populate the array above +const mobs = { + loop() { + let i = mob.length; + while (i--) { + if (mob[i].alive) { + mob[i].do(); + } else { + mob[i].replace(i); //removing mob and replace with body, this is done here to avoid an array index bug with drawing I think + } + } + }, + draw() { }, + drawDefault() { + ctx.lineWidth = 2; + let i = mob.length; + while (i--) { + // if (Matter.Query.ray(map, mob[i].position, m.pos).length === 0) { //check if there is a ray between the mob and the player + ctx.beginPath(); + const vertices = mob[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.fillStyle = mob[i].fill; + ctx.strokeStyle = mob[i].stroke; + ctx.fill(); + ctx.stroke(); + // } + } + }, + defaultHealthBar() { + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].seePlayer.recall && mob[i].showHealthBar) { + const h = mob[i].radius * 0.3; + const w = mob[i].radius * 2; + const x = mob[i].position.x - w / 2; + const y = mob[i].position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(255,0,0,0.7)"; + ctx.fillRect(x, y, w * mob[i].health, h); + // if (mob[i].isInvulnerable) { + // ctx.strokeStyle = "rgba(255,255,255,1)"; + // ctx.lineWidth = 5 + // ctx.strokeRect(x, y, w, h); + // } + } + } + }, + healthBar() { }, + statusSlow(who, cycles = 60) { + applySlow(who) + //look for mobs near the target + if (tech.isAoESlow) { + const range2 = (200 + 170 * Math.random()) ** 2 + for (let i = 0, len = mob.length; i < len; i++) { + if (who !== mob[i] && Vector.magnitudeSquared(Vector.sub(who.position, mob[i].position)) < range2 + mob[i].radius) applySlow(mob[i]) + } + simulation.drawList.push({ + x: who.position.x, + y: who.position.y, + radius: Math.sqrt(range2), + color: "rgba(0,100,255,0.05)", + time: simulation.drawTime + }); + } + + function applySlow(whom) { + if (!whom.shield && !whom.isShielded && whom.alive) { + if (tech.isIceMaxHealthLoss && whom.health > 0.66 && whom.damageReduction > 0) whom.health = 0.66 + if (tech.isIceKill && whom.health < 0.34 && whom.damageReduction > 0 && whom.alive) { + // whom.death(); + whom.damage(Infinity); + simulation.drawList.push({ + x: whom.position.x, + y: whom.position.y, + radius: whom.radius * 1.2, + color: "rgb(0,100,255)", + time: 8 + }); + simulation.drawList.push({ + x: whom.position.x, + y: whom.position.y, + radius: whom.radius * 0.7, + color: "rgb(0,100,255)", + time: 12 + }); + simulation.drawList.push({ + x: whom.position.x, + y: whom.position.y, + radius: whom.radius * 0.4, + color: "rgb(0,100,255)", + time: 16 + }); + } + if (whom.isBoss) cycles = Math.floor(cycles * 0.25) + let i = whom.status.length + while (i--) { + if (whom.status[i].type === "slow") whom.status.splice(i, 1); //remove other "slow" effects on this mob + } + whom.isSlowed = true; + whom.status.push({ + effect() { + if (whom.speed > 1) { + const drag = 0.94 + Matter.Body.setVelocity(whom, { + x: whom.velocity.x * drag, + y: whom.velocity.y * drag + }); + } + Matter.Body.setAngularVelocity(whom, 0); + ctx.beginPath(); + ctx.moveTo(whom.vertices[0].x, whom.vertices[0].y); + for (let j = 1, len = whom.vertices.length; j < len; ++j) { + ctx.lineTo(whom.vertices[j].x, whom.vertices[j].y); + } + ctx.lineTo(whom.vertices[0].x, whom.vertices[0].y); + ctx.strokeStyle = "rgba(0,100,255,0.8)"; + ctx.lineWidth = 15; + ctx.stroke(); + ctx.fillStyle = whom.fill + ctx.fill(); + }, + endEffect() { + //check to see if there are not other freeze effects? + whom.isSlowed = false; + }, + type: "slow", + endCycle: simulation.cycle + cycles, + }) + } + } + }, + statusStun(who, cycles = 180) { + if (!who.shield && !who.isShielded) { + if (who.speed > 3) { + Matter.Body.setVelocity(who, { + x: who.velocity.x * 0.8, + y: who.velocity.y * 0.8 + }); + } + Matter.Body.setAngularVelocity(who, who.angularVelocity * 0.8); + //remove other "stun" effects on this mob + let i = who.status.length + while (i--) { + if (who.status[i].type === "stun") who.status.splice(i, 1); + } + who.isStunned = true; + who.status.push({ + effect() { + if (who.memory !== Infinity) { + who.seePlayer.yes = false; + who.seePlayer.recall = 0; + who.seePlayer.position = { + x: who.position.x + 100 * (Math.random() - 0.5), + y: who.position.y + 100 * (Math.random() - 0.5) + } + } else { + Matter.Body.setVelocity(who, { + x: who.velocity.x * 0.6, + y: who.velocity.y * 0.6 + }); + } + if (who.velocity.y < 2) who.force.y += who.mass * 0.0004 //extra gravity + + //draw health bar + const h = who.radius * 0.3; + const w = who.radius * 2; + const x = who.position.x - w / 2; + const y = who.position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = `rgba(${Math.floor(255 * Math.random())},${Math.floor(255 * Math.random())},${Math.floor(255 * Math.random())},0.5)` + ctx.fillRect(x, y, w * who.health, h); + + //draw fill inside mob + ctx.beginPath(); + ctx.moveTo(who.vertices[0].x, who.vertices[0].y); + for (let j = 1, len = who.vertices.length; j < len; ++j) { + ctx.lineTo(who.vertices[j].x, who.vertices[j].y); + } + ctx.lineTo(who.vertices[0].x, who.vertices[0].y); + ctx.fill(); + }, + endEffect() { + who.isStunned = false + }, + type: "stun", + endCycle: simulation.cycle + cycles * (who.isBoss ? 0.2 : 1), + }) + } + }, + statusDoT(who, tickDamage, cycles = 180) { + if (!who.isShielded && who.alive && who.damageReduction > 0) { + who.status.push({ + effect() { + if ((simulation.cycle - this.startCycle) % 30 === 0) { + let dmg = m.dmgScale * tech.radioactiveDamage * this.dmg + who.damage(dmg); + if (who.damageReduction) { + simulation.drawList.push({ //add dmg to draw queue + x: who.position.x + (Math.random() - 0.5) * who.radius * 0.5, + y: who.position.y + (Math.random() - 0.5) * who.radius * 0.5, + radius: Math.log(dmg + 1.1) * 40 * who.damageReduction + 3, + color: "rgba(0,80,80,0.9)", + time: simulation.drawTime + }); + } + } + }, + endEffect() { }, + dmg: tickDamage, + type: "dot", + endCycle: simulation.cycle + cycles, + startCycle: simulation.cycle + 29 //makes sure it doesn't tick on first application + }) + } + }, + // statusBurn(who, tickDamage, cycles = 90 + Math.floor(90 * Math.random())) { + // if (!who.isShielded) { + // //remove other "burn" effects on this mob + // let i = who.status.length + // while (i--) { + // if (who.status[i].type === "burn") who.status.splice(i, 1); + // } + // who.status.push({ + // effect() { + // if ((simulation.cycle - this.startCycle) % 15 === 0) { + // let dmg = m.dmgScale * tickDamage * 0.5 * (1 + Math.random()) + // who.damage(dmg); + // simulation.drawList.push({ //add dmg to draw queue + // x: who.position.x, + // y: who.position.y, + // radius: Math.log(2 * dmg + 1.1) * 40, + // color: `rgba(255,${Math.floor(200*Math.random())},0,0.9)`, + // time: simulation.drawTime + // }); + // } + // }, + // type: "burn", + // endCycle: simulation.cycle + cycles, + // startCycle: simulation.cycle + // }) + // } + // }, + deathCount: 0, + mobSpawnWithHealth: 1, + setMobSpawnHealth() { + mobs.mobSpawnWithHealth = 0.88 ** (tech.mobSpawnWithHealth) + }, + //********************************************************************************************** + //********************************************************************************************** + spawn(xPos, yPos, sides, radius, color) { + let i = mob.length; + mob[i] = Matter.Bodies.polygon(xPos, yPos, sides, radius, { + //inertia: Infinity, //prevents rotation + mob: true, + density: 0.001, + //friction: 0, + frictionAir: 0.005, + //frictionStatic: 0, + restitution: 0.5, + collisionFilter: { + group: 0, + category: cat.mob, + mask: cat.player | cat.map | cat.body | cat.bullet | cat.mob + }, + onHit: undefined, + alive: true, + index: i, + health: mobs.mobSpawnWithHealth, + showHealthBar: true, + accelMag: 0.001 * simulation.accelScale, + cd: 0, //game cycle when cooldown will be over + delay: 60, //static: time between cooldowns + fill: color, + stroke: "#000", + seePlayer: { + yes: false, + recall: 0, + position: { + x: xPos, + y: yPos + } + }, + radius: radius, + spawnPos: { + x: xPos, + y: yPos + }, + status: [], // [ { effect(), endCycle } ] + checkStatus() { + let j = this.status.length; + while (j--) { + this.status[j].effect(); + if (this.status[j].endCycle < simulation.cycle) { + this.status[j].endEffect(); + this.status.splice(j, 1); + } + } + }, + isSlowed: false, + isStunned: false, + seeAtDistance2: Infinity, //sqrt(4000000) = 2000 = max seeing range + distanceToPlayer() { + const dx = this.position.x - player.position.x; + const dy = this.position.y - player.position.y; + return Math.sqrt(dx * dx + dy * dy); + }, + distanceToPlayer2() { + const dx = this.position.x - player.position.x; + const dy = this.position.y - player.position.y; + return dx * dx + dy * dy; + }, + gravity() { + this.force.y += this.mass * this.g; + }, + seePlayerFreq: Math.floor(30 + 30 * Math.random()), //how often NPC checks to see where player is, lower numbers have better vision + foundPlayer() { + this.locatePlayer(); + if (!this.seePlayer.yes) { + this.alertNearByMobs(); + this.seePlayer.yes = true; + } + }, + lostPlayer() { + this.seePlayer.yes = false; + this.seePlayer.recall -= this.seePlayerFreq; + if (this.seePlayer.recall < 0) this.seePlayer.recall = 0; + }, + memory: 120, //default time to remember player's location + locatePlayer() { // updates mob's memory of player location + this.seePlayer.recall = this.memory + Math.round(this.memory * Math.random()); //cycles before mob falls a sleep + this.seePlayer.position.x = player.position.x; + this.seePlayer.position.y = player.position.y; + }, + alertNearByMobs() { + //this.alertRange2 is set at the very bottom of this mobs, after mob is made + for (let i = 0; i < mob.length; i++) { + if (!mob[i].seePlayer.recall && Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)) < this.alertRange2) { + mob[i].locatePlayer(); + } + } + }, + alwaysSeePlayer() { + if (!m.isCloak) { + this.seePlayer.recall = 1; + this.seePlayer.position.x = player.position.x; + this.seePlayer.position.y = player.position.y; + } + }, + seePlayerByHistory(depth = 30) { //depth max 60? limit of history + if (!(simulation.cycle % this.seePlayerFreq)) { + if (Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && !m.isCloak) { + this.foundPlayer(); + } else if (this.seePlayer.recall) { + this.lostPlayer(); + if (!m.isCloak) { + for (let i = 0; i < depth; i++) { //if lost player lock onto a player location in history + let history = m.history[(m.cycle - 10 * i) % 600] + if (Matter.Query.ray(map, this.position, history.position).length === 0) { + this.seePlayer.recall = this.memory + Math.round(this.memory * Math.random()); //cycles before mob falls a sleep + this.seePlayer.position.x = history.position.x; + this.seePlayer.position.y = history.position.y; + this.seePlayer.yes = true; + //draw the history location found for testing purposes + // ctx.beginPath(); + // ctx.moveTo(this.position.x, this.position.y); + // ctx.lineTo(history.position.x, history.position.y); + // ctx.lineWidth = 5; + // ctx.strokeStyle = "#000"; + // ctx.stroke(); + break + } + } + } + } + } + }, + seePlayerCheck() { + if (!(simulation.cycle % this.seePlayerFreq)) { + if ( + this.distanceToPlayer2() < this.seeAtDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + // Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 && + !m.isCloak + ) { + this.foundPlayer(); + } else if (this.seePlayer.recall) { + this.lostPlayer(); + } + } + }, + seePlayerCheckByDistance() { + if (!(simulation.cycle % this.seePlayerFreq)) { + if (this.distanceToPlayer2() < this.seeAtDistance2 && !m.isCloak) { + this.foundPlayer(); + } else if (this.seePlayer.recall) { + this.lostPlayer(); + } + } + }, + seePlayerByDistOrLOS() { + if (!(simulation.cycle % this.seePlayerFreq)) { + if ( + (this.distanceToPlayer2() < this.seeAtDistance2 || (Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0)) && //&& Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + !m.isCloak + ) { + this.foundPlayer(); + } else if (this.seePlayer.recall) { + this.lostPlayer(); + } + } + }, + isLookingAtPlayer(threshold) { + const diff = Vector.normalise(Vector.sub(player.position, this.position)); + //make a vector for the mob's direction of length 1 + const dir = { x: Math.cos(this.angle), y: Math.sin(this.angle) }; + //the dot product of diff and dir will return how much over lap between the vectors + const dot = Vector.dot(dir, diff); + // console.log(Math.cos(dot)*180/Math.PI) + if (dot > threshold) { + return true; + } else { + return false; + } + }, + lookRange: 0.2 + Math.random() * 0.2, + lookTorque: 0.0000004 * (Math.random() > 0.5 ? -1 : 1), + seePlayerByLookingAt() { + if (!(simulation.cycle % this.seePlayerFreq) && (this.seePlayer.recall || this.isLookingAtPlayer(this.lookRange))) { + if ( + this.distanceToPlayer2() < this.seeAtDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + // Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 && + !m.isCloak + ) { + this.foundPlayer(); + } else if (this.seePlayer.recall) { + this.lostPlayer(); + } + } + //if you don't recall player location rotate and draw to show where you are looking + if (!this.seePlayer.recall) { + this.torque = this.lookTorque * this.inertia; + //draw + const range = Math.PI * this.lookRange; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.radius * 2.5, this.angle - range, this.angle + range); + ctx.arc(this.position.x, this.position.y, this.radius * 1.4, this.angle + range, this.angle - range, true); + ctx.fillStyle = "rgba(0,0,0,0.07)"; + ctx.fill(); + } + }, + playerPosRandomY() { + return { + x: player.position.x, // + (Math.random() - 0.5) * 50, + y: player.position.y + (Math.random() - 0.5) * 110 + }; + }, + // hacked() { //set this.hackedTarget variable before running this method + // //find a new target + // if (!(simulation.cycle % this.seePlayerFreq)) { + // this.hackedTarget = null + // for (let i = 0, len = mob.length; i < len; i++) { + // if (mob[i] !== this) { + // // const DIST = Vector.magnitude(Vector.sub(this.position, mob[j])); + // if (Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + // Matter.Query.ray(body, this.position, mob[i].position).length === 0) { + // this.hackedTarget = mob[i] + // } + // } + // } + // } + // //acceleration towards targets + // if (this.hackedTarget) { + // this.force = Vector.mult(Vector.normalise(Vector.sub(this.hackedTarget.position, this.position)), this.mass * 0.0015) + // } + // }, + harmZone() { + if (this.seePlayer.yes) { + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + // ctx.lineDashOffset = 6*(simulation.cycle % 215); + if (this.distanceToPlayer() < this.laserRange) { + if (m.immuneCycle < m.cycle) { + m.damage(0.0003 * simulation.dmgScale); + if (m.energy > 0.1) m.energy -= 0.003 + } + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineTo(m.pos.x + (Math.random() - 0.5) * 3000, m.pos.y + (Math.random() - 0.5) * 3000); + ctx.lineWidth = 2; + ctx.strokeStyle = "rgb(255,0,170)"; + ctx.stroke(); + + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(255,0,170,0.15)"; + ctx.fill(); + } + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.laserRange * 0.9, 0, 2 * Math.PI); + ctx.strokeStyle = "rgba(255,0,170,0.5)"; + ctx.lineWidth = 1; + ctx.stroke(); + ctx.setLineDash([]); + ctx.fillStyle = "rgba(255,0,170,0.03)"; + ctx.fill(); + } + }, + // laser() { + // if (this.seePlayer.recall && !this.isSlowed) { + // const seeRange = 2500; + // best = { + // x: null, + // y: null, + // dist2: Infinity, + // who: null, + // v1: null, + // v2: null + // }; + // const look = { + // x: this.position.x + seeRange * Math.cos(this.angle), + // y: this.position.y + seeRange * Math.sin(this.angle) + // }; + // best = vertexCollision(this.position, look, m.isCloak ? [map, body] : [map, body, [player]]); + + // // hitting player + // if (best.who === player) { + // if (m.immuneCycle < m.cycle) { + // const dmg = 0.0014 * simulation.dmgScale; + // m.damage(dmg); + // ctx.fillStyle = "#f00"; //draw damage + // ctx.beginPath(); + // ctx.arc(best.x, best.y, dmg * 10000, 0, 2 * Math.PI); + // ctx.fill(); + // } + // } + // //draw beam + // if (best.dist2 === Infinity) { + // best = look; + // } + // ctx.beginPath(); + // ctx.moveTo(this.position.x, this.position.y); + // ctx.lineTo(best.x, best.y); + // ctx.strokeStyle = "#f00"; // Purple path + // ctx.lineWidth = 1; + // ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + // ctx.stroke(); // Draw it + // ctx.setLineDash([]); + // } + // }, + wing(a, radius = 250, ellipticity = 0.4, dmg = 0.0006) { + const minorRadius = radius * ellipticity + const perp = { x: Math.cos(a), y: Math.sin(a) } // + const where = Vector.add(this.position, Vector.mult(perp, radius + 0.8 * this.radius)) + + ctx.beginPath(); + ctx.ellipse(where.x, where.y, radius, minorRadius, a, 0, 2 * Math.PI) + ctx.fill(); + + //check for wing -> player damage + const hitPlayer = Matter.Query.ray([player], this.position, Vector.add(this.position, Vector.mult(perp, radius * 2.05)), minorRadius) + if (hitPlayer.length && m.immuneCycle < m.cycle) { + m.damage(dmg * simulation.dmgScale); + } + }, + searchSpring() { + //draw the two dots on the end of the springs + ctx.beginPath(); + ctx.arc(this.cons.pointA.x, this.cons.pointA.y, 6, 0, 2 * Math.PI); + ctx.arc(this.cons2.pointA.x, this.cons2.pointA.y, 6, 0, 2 * Math.PI); + ctx.fillStyle = "#222"; + ctx.fill(); + + if (!(simulation.cycle % this.seePlayerFreq)) { + if ( + (this.seePlayer.recall || this.isLookingAtPlayer(this.lookRange)) && + this.distanceToPlayer2() < this.seeAtDistance2 && + Matter.Query.ray(map, this.position, player.position).length === 0 && + Matter.Query.ray(body, this.position, player.position).length === 0 && + !m.isCloak + ) { + this.foundPlayer(); + } else if (this.seePlayer.recall) { + this.lostPlayer(); + } + } + }, + springAttack() { + // set new values of the ends of the spring constraints + const stepRange = 600 + if (this.seePlayer.recall && Matter.Query.ray(map, this.position, this.seePlayer.position).length === 0) { + if (!(simulation.cycle % (this.seePlayerFreq * 2))) { + const unit = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)) + const goal = Vector.add(this.position, Vector.mult(unit, stepRange)) + this.springTarget.x = goal.x; + this.springTarget.y = goal.y; + // this.springTarget.x = this.seePlayer.position.x; + // this.springTarget.y = this.seePlayer.position.y; + this.cons.length = -200; + this.cons2.length = 100 + 1.5 * this.radius; + } else if (!(simulation.cycle % this.seePlayerFreq)) { + const unit = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)) + const goal = Vector.add(this.position, Vector.mult(unit, stepRange)) + this.springTarget2.x = goal.x; + this.springTarget2.y = goal.y; + // this.springTarget2.x = this.seePlayer.position.x; + // this.springTarget2.y = this.seePlayer.position.y; + this.cons.length = 100 + 1.5 * this.radius; + this.cons2.length = -200; + } + } else { + this.torque = this.lookTorque * this.inertia; + //draw looking around arcs + const range = Math.PI * this.lookRange; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.radius * 2.5, this.angle - range, this.angle + range); + ctx.arc(this.position.x, this.position.y, this.radius * 1.4, this.angle + range, this.angle - range, true); + ctx.fillStyle = "rgba(0,0,0,0.07)"; + ctx.fill(); + //spring to random place on map + if (!(simulation.cycle % (this.seePlayerFreq * 4))) { + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const seeRange = 3000; + const look = { + x: this.position.x + seeRange * Math.cos(this.angle), + y: this.position.y + seeRange * Math.sin(this.angle) + }; + best = vertexCollision(this.position, look, [map, body]); + if (best.dist2 != Infinity) { + if (Math.random() > 0.5) { + this.springTarget.x = best.x; + this.springTarget.y = best.y; + this.cons.length = 100 + 1.5 * this.radius; + this.cons2.length = 100 + 1.5 * this.radius; + } else { + this.springTarget2.x = best.x; + this.springTarget2.y = best.y; + this.cons.length = 100 + 1.5 * this.radius; + this.cons2.length = 100 + 1.5 * this.radius; + } + } + } + } + }, + curl(range = 1000, mag = -10) { + //cause all mobs, and bodies to rotate in a circle + applyCurl = function (center, array, isAntiGravity = true) { + for (let i = 0; i < array.length; ++i) { + if (!array[i].isNotHoldable) { + const sub = Vector.sub(center, array[i].position) + const radius2 = Vector.magnitudeSquared(sub); + + //if too close, like center mob or shield, don't curl // if too far don't curl + if (radius2 < range * range && radius2 > 10000) { + const curlVector = Vector.mult(Vector.perp(Vector.normalise(sub)), mag) + //apply curl force + if (array[i].isMobBullet) { + Matter.Body.setVelocity(array[i], { + x: array[i].velocity.x * 0.97 + curlVector.x * 0.06, + y: array[i].velocity.y * 0.97 + curlVector.y * 0.06 + }) + } else { + Matter.Body.setVelocity(array[i], { + x: array[i].velocity.x * 0.95 + curlVector.x * 0.06, + y: array[i].velocity.y * 0.95 + curlVector.y * 0.06 + }) + } + if (isAntiGravity) array[i].force.y -= 0.8 * simulation.g * array[i].mass + // //draw curl, for debugging + // ctx.beginPath(); + // ctx.moveTo(array[i].position.x, array[i].position.y); + // ctx.lineTo(array[i].position.x + curlVector.x * 10, array[i].position.y + curlVector.y * 10); + // ctx.lineWidth = 2; + // ctx.strokeStyle = "#000"; + // ctx.stroke(); + } + } + } + } + applyCurl(this.position, mob, false); + applyCurl(this.position, body); + applyCurl(this.position, powerUp); + // applyCurl(this.position, bullet); // too powerful, just stops all bullets need to write a curl function just for bullets + // applyCurl(this.position, [player]); + + //draw limit + // ctx.beginPath(); + // ctx.arc(this.position.x, this.position.y, range, 0, 2 * Math.PI); + // ctx.fillStyle = "rgba(55,255,255, 0.1)"; + // ctx.fill(); + }, + pullPlayer() { + if (this.seePlayer.yes && Vector.magnitudeSquared(Vector.sub(this.position, player.position)) < 1000000) { + const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x); + player.force.x -= simulation.accelScale * 0.00113 * player.mass * Math.cos(angle) * (m.onGround ? 2 : 1); + player.force.y -= simulation.accelScale * 0.00084 * player.mass * Math.sin(angle); + + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineWidth = Math.min(60, this.radius * 2); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + ctx.stroke(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ctx.fill(); + } + }, + repelBullets() { + // if (this.seePlayer.yes) { + // ctx.lineWidth = "8"; + // ctx.strokeStyle = this.fill; + // ctx.beginPath(); + for (let i = 0, len = bullet.length; i < len; ++i) { + const dx = bullet[i].position.x - this.position.x; + const dy = bullet[i].position.y - this.position.y; + const dist = Math.max(300, Math.sqrt(dx * dx + dy * dy)) + if (dist < 700) { + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(bullet[i].position.x, bullet[i].position.y); + const angle = Math.atan2(dy, dx); + const mag = (500 * bullet[i].mass * simulation.g) / dist; + bullet[i].force.x += mag * Math.cos(angle); + bullet[i].force.y += mag * Math.sin(angle); + } + } + // ctx.stroke(); + // } + }, + attraction() { + //accelerate towards the player + if (this.seePlayer.recall) { + const force = Vector.mult(Vector.normalise(Vector.sub(this.seePlayer.position, this.position)), this.accelMag * this.mass) + this.force.x += force.x; + this.force.y += force.y; + } + }, + repulsionRange: 500000, //squared + repulsion() { + //accelerate towards the player + if (this.seePlayer.recall && this.distanceToPlayer2() < this.repulsionRange) { + // && dx * dx + dy * dy < 2000000) { + const forceMag = this.accelMag * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x -= 2 * forceMag * Math.cos(angle); + this.force.y -= 2 * forceMag * Math.sin(angle); // - 0.0007 * this.mass; //antigravity + } + }, + hoverOverPlayer() { + if (this.seePlayer.recall) { + // vertical positioning + const rangeY = 250; + if (this.position.y > this.seePlayer.position.y - this.hoverElevation + rangeY) { + this.force.y -= this.accelMag * this.mass; + } else if (this.position.y < this.seePlayer.position.y - this.hoverElevation - rangeY) { + this.force.y += this.accelMag * this.mass; + } + // horizontal positioning + const rangeX = 150; + if (this.position.x > this.seePlayer.position.x + this.hoverXOff + rangeX) { + this.force.x -= this.accelMag * this.mass; + } else if (this.position.x < this.seePlayer.position.x + this.hoverXOff - rangeX) { + this.force.x += this.accelMag * this.mass; + } + } + }, + grow() { + if (this.seePlayer.recall) { + if (this.radius < 80) { + const scale = 1.01; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + // this.torque = -0.00002 * this.inertia; + this.fill = `hsl(144, ${this.radius}%, 50%)`; + if (this.isShielded) { //remove shield if shielded when growing + this.isShielded = false; + this.removeConsBB(); + } + } + } else { + if (this.radius > 15) { + const scale = 0.99; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + this.fill = `hsl(144, ${this.radius}%, 50%)`; + } + } + }, + search() { + //be sure to declare searchTarget in mob spawn + //accelerate towards the searchTarget + if (!this.seePlayer.recall) { + const newTarget = function (that) { + if (Math.random() < 0.0007) { + that.searchTarget = player.position; //chance to target player + } else { + //target random body + that.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; + } + }; + + const sub = Vector.sub(this.searchTarget, this.position); + if (Vector.magnitude(sub) > this.radius * 2) { + // ctx.beginPath(); + // ctx.strokeStyle = "#aaa"; + // ctx.moveTo(this.position.x, this.position.y); + // ctx.lineTo(this.searchTarget.x,this.searchTarget.y); + // ctx.stroke(); + //accelerate at 0.1 of normal acceleration + this.force = Vector.mult(Vector.normalise(sub), this.accelMag * this.mass * 0.2); + } else { + //after reaching random target switch to new target + newTarget(this); + } + //switch to a new target after a while + if (!(simulation.cycle % (this.seePlayerFreq * 15))) { + newTarget(this); + } + } + }, + blink() { + //teleport towards player as a way to move + if (this.seePlayer.recall && !(simulation.cycle % this.blinkRate)) { + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + const unitVector = Vector.normalise(dist); + const rando = (Math.random() - 0.5) * 50; + if (distMag < this.blinkLength) { + Matter.Body.translate(this, Vector.mult(unitVector, distMag + rando)); + } else { + Matter.Body.translate(this, Vector.mult(unitVector, this.blinkLength + rando)); + } + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = radius * 2; + ctx.strokeStyle = this.stroke; //"rgba(0,0,0,0.5)"; //'#000' + ctx.stroke(); + } + }, + drift() { + //teleport towards player as a way to move + if (this.seePlayer.recall && !(simulation.cycle % this.blinkRate)) { + // && !m.lookingAtMob(this,0.5)){ + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + const vector = Vector.mult(Vector.normalise(dist), this.blinkLength); + if (distMag < this.blinkLength) { + Matter.Body.setPosition(this, this.seePlayer.position); + Matter.Body.translate(this, { + x: (Math.random() - 0.5) * 50, + y: (Math.random() - 0.5) * 50 + }); + } else { + vector.x += (Math.random() - 0.5) * 200; + vector.y += (Math.random() - 0.5) * 200; + Matter.Body.translate(this, vector); + } + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = radius * 2; + ctx.strokeStyle = this.stroke; + ctx.stroke(); + } + }, + bomb() { + //throw a mob/bullet at player + if ( + !(simulation.cycle % this.fireFreq) && + Math.abs(this.position.x - this.seePlayer.position.x) < 400 && //above player + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && //see player + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + spawn.bomb(this.position.x, this.position.y + this.radius * 0.7, 9 + Math.ceil(this.radius / 15), 5); + //add spin and speed + Matter.Body.setAngularVelocity(mob[mob.length - 1], (Math.random() - 0.5) * 0.5); + Matter.Body.setVelocity(mob[mob.length - 1], { x: this.velocity.x, y: this.velocity.y }); + //spin for mob as well + Matter.Body.setAngularVelocity(this, (Math.random() - 0.5) * 0.25); + } + }, + fire() { + const setNoseShape = () => { + const mag = this.radius + this.radius * this.noseLength; + this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag; + }; + //throw a mob/bullet at player + if (this.seePlayer.recall) { + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + this.fireDir.y -= Math.abs(this.seePlayer.position.x - this.position.x) / 2500; //gives the bullet an arc //was / 1600 + } + //rotate towards fireAngle + const angle = this.angle + Math.PI / 2; + const dot = Vector.dot({ + x: Math.cos(angle), + y: Math.sin(angle) + }, this.fireDir) + // c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + const threshold = 0.1; + if (dot > threshold) { + this.torque += 0.000004 * this.inertia; + } else if (dot < -threshold) { + this.torque -= 0.000004 * this.inertia; + } else if (this.noseLength > 1.5 && dot > -0.2 && dot < 0.2) { + //fire + spawn.bullet(this.vertices[1].x, this.vertices[1].y, 9 + Math.ceil(this.radius / 15)); + const v = 15; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v + 3 * Math.random(), + y: this.velocity.y + this.fireDir.y * v + 3 * Math.random() + }); + this.noseLength = 0; + // recoil + this.force.x -= 0.005 * this.fireDir.x * this.mass; + this.force.y -= 0.005 * this.fireDir.y * this.mass; + } + if (this.noseLength < 1.5) this.noseLength += this.fireFreq; + setNoseShape(); + } else if (this.noseLength > 0.1) { + this.noseLength -= this.fireFreq / 2; + setNoseShape(); + } + // else if (this.noseLength < -0.1) { + // this.noseLength += this.fireFreq / 4; + // setNoseShape(); + // } + }, + // launch() { + // if (this.seePlayer.recall) { + // //fire + // spawn.seeker(this.vertices[1].x, this.vertices[1].y, 5 + Math.ceil(this.radius / 15), 5); + // const v = 15; + // Matter.Body.setVelocity(mob[mob.length - 1], { + // x: this.velocity.x + this.fireDir.x * v + Math.random(), + // y: this.velocity.y + this.fireDir.y * v + Math.random() + // }); + // // recoil + // this.force.x -= 0.005 * this.fireDir.x * this.mass; + // this.force.y -= 0.005 * this.fireDir.y * this.mass; + // } + // }, + turnToFacePlayer() { + //turn to face player + const dx = player.position.x - this.position.x; + const dy = -player.position.y + this.position.y; + const dist = this.distanceToPlayer(); + const angle = this.angle + Math.PI / 2; + c = Math.cos(angle) * dx - Math.sin(angle) * dy; + // if (c > 0.04) { + // Matter.Body.rotate(this, 0.01); + // } else if (c < 0.04) { + // Matter.Body.rotate(this, -0.01); + // } + if (c > 0.04 * dist) { + this.torque += 0.002 * this.mass; + } else if (c < 0.04) { + this.torque -= 0.002 * this.mass; + } + }, + facePlayer() { + const unitVector = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + const angle = Math.atan2(unitVector.y, unitVector.x); + Matter.Body.setAngle(this, angle - Math.PI); + }, + explode(mass = this.mass) { + if (m.immuneCycle < m.cycle) { + m.damage(Math.min(Math.max(0.02 * Math.sqrt(mass), 0.01), 0.35) * simulation.dmgScale); + this.isDropPowerUp = false; + this.death(); //death with no power up or body + } + }, + timeLimit() { + this.timeLeft--; + if (this.timeLeft < 0) { + this.isDropPowerUp = false; + this.death(); //death with no power up + } + }, + //draw health by mob //most health bars are drawn in mobs.healthBar(); , not this + healthBar() { + if (this.seePlayer.recall && !level.isHideHealth) { + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(255,0,0,0.7)"; + ctx.fillRect(x, y, w * this.health, h); + } + }, + damage(dmg, isBypassShield = false) { + if ((!this.isShielded || isBypassShield) && this.alive) { + if (dmg !== Infinity) { + dmg *= tech.damageFromTech() + if (this.isDropPowerUp) { + if (this.health === 1) { + if (tech.isMobFullHealthCloak) { + dmg *= 2.11 + simulation.ephemera.push({ + name: "damage outline", + count: 7, //cycles before it self removes + vertices: this.vertices, + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + //draw body + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.fillStyle = `rgba(255,0,100,0.15)` //"rgba(150,150,225,0.5)"; + ctx.fill() + ctx.lineWidth = 3 //60 * (0.25 - this.damageReductionGoal) + ctx.strokeStyle = `#f08` //"rgba(150,150,225,0.5)"; + ctx.stroke(); + }, + }) + } + } else if (tech.isMobLowHealth && this.health < 0.25) { + dmg *= 3 + + simulation.ephemera.push({ + name: "damage outline", + count: 2, //cycles before it self removes + vertices: this.vertices, + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + //draw body + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.fillStyle = `rgba(255,50,100,0.2)` //"rgba(150,150,225,0.5)"; + ctx.fill() + ctx.lineWidth = 3 //60 * (0.25 - this.damageReductionGoal) + ctx.strokeStyle = `#f38` //"rgba(150,150,225,0.5)"; + ctx.stroke(); + }, + }) + } + } + + //mobs specific damage changes + if (tech.isFarAwayDmg) dmg *= 1 + Math.sqrt(Math.max(500, Math.min(3000, this.distanceToPlayer())) - 500) * 0.0067 //up to 33% dmg at max range of 3000 + dmg *= this.damageReduction + //energy and heal drain should be calculated after damage boosts + if (tech.energySiphon && dmg !== Infinity && this.isDropPowerUp && m.immuneCycle < m.cycle) m.energy += Math.min(this.health, dmg) * tech.energySiphon * level.isReducedRegen + dmg /= Math.sqrt(this.mass) + } + + this.health -= dmg + //this.fill = this.color + this.health + ')'; + this.onDamage(dmg); //custom damage effects + if ((this.health < 0.01 || isNaN(this.health)) && this.alive) this.death(); + } + }, + onDamage() { + // a placeholder for custom effects on mob damage + //to use declare custom method in mob spawn + }, + onDeath() { + // a placeholder for custom effects on mob death + // to use declare custom method in mob spawn + }, + damageReduction: 1, + // damageReductionGoal: 0.001, //must add this to boss set up: me.damageReduction = 0.25 + // damageReductionScale: 0.004, //for bosses in this.onDamage determines the impact of dmg on damageReductionGoal + // armor() { //slowly reduce damage reduction, for bosses + // if (this.seePlayer.recall) { + // if (this.damageReductionGoal > 0.24) { + // this.damageReductionGoal = 0.25 + // } else { + // this.damageReductionGoal = this.damageReductionGoal * 0.999 + 0.001 * 0.25 //smooth the goal towards 0.25 damage reduction + // } + // this.damageReduction = this.damageReduction * 0.995 + 0.005 * this.damageReductionGoal //smooth damage reduction towards the goal + // // console.log(`damageReduction = ${this.damageReduction.toFixed(4)}`, `damageReductionGoal = ${this.damageReductionGoal.toFixed(4)}`) + // } + // //draw armor + // //draw body + // ctx.beginPath(); + // const vertices = this.vertices; + // ctx.moveTo(vertices[0].x, vertices[0].y); + // for (let j = 1, len = vertices.length; j < len; ++j) { + // ctx.lineTo(vertices[j].x, vertices[j].y); + // } + // ctx.lineTo(vertices[0].x, vertices[0].y); + // console.log(this.damageReduction, this.damageReductionGoal) + // ctx.lineWidth = 3 //60 * (0.25 - this.damageReductionGoal) + // ctx.strokeStyle = `rgba(255,255,255,${4.1*(0.25 - this.damageReductionGoal)})` //"rgba(150,150,225,0.5)"; + // ctx.stroke(); + // }, + leaveBody: true, + maxMobBody: 40, + isDropPowerUp: true, + death() { + if (tech.collidePowerUps && this.isDropPowerUp) powerUps.randomize(this.position) //needs to run before onDeath spawns power ups + this.onDeath(this); //custom death effects + this.removeConsBB(); + this.alive = false; //triggers mob removal in mob[i].replace(i) + // console.log(this.shieldCount) + + if (this.isDropPowerUp) { + if (level.isMobDeathHeal) { + for (let i = 0; i < mob.length; i++) { + if (Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)) < 500000 && mob[i].alive) { //700 + if (mob[i].health < 1) { + mob[i].health += 0.33 + this.isBoss + if (mob[i].health > 1) mob[i].health = 1 + simulation.drawList.push({ + x: mob[i].position.x, + y: mob[i].position.y, + radius: mob[i].radius + 20, + color: "rgba(0,255,100,0.5)", + time: 10 + }); + } + } + } + } + if (this.isSoonZombie) { //spawn zombie on death + this.leaveBody = false; + let count = 5 //delay spawn cycles + let cycle = () => { + if (count > 0) { + if (m.alive) requestAnimationFrame(cycle); + if (!simulation.paused && !simulation.isChoosing) { + count-- + } + } else { + spawn.zombie(this.position.x, this.position.y, this.radius, this.vertices.length, this.fill) // zombie(x, y, radius, sides, color) + } + } + requestAnimationFrame(cycle); + } + if (tech.iceIXOnDeath && this.isSlowed) { + for (let i = 0, len = 2 * Math.sqrt(Math.min(this.mass, 25)) * tech.iceIXOnDeath; i < len; i++) b.iceIX(3, Math.random() * 2 * Math.PI, this.position) + } + if (tech.deathSpawnsFromBoss || tech.deathSpawns) { + const spawns = tech.deathSpawns + tech.deathSpawnsFromBoss + const len = Math.min(12, spawns * Math.ceil(Math.random() * simulation.difficulty * spawns)) + for (let i = 0; i < len; i++) { + spawn.spawns(this.position.x + (Math.random() - 0.5) * radius * 2.5, this.position.y + (Math.random() - 0.5) * radius * 2.5); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + (Math.random() - 0.5) * 10, + y: this.velocity.x + (Math.random() - 0.5) * 10 + }); + } + } + if (level.isMobRespawn && !this.isBoss && 0.33 > Math.random()) { + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: 30, + color: `#fff`, + time: 20 + }); + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: 20, + color: `#fff`, + time: 40 + }); + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: 10, + color: `#fff`, + time: 60 + }); + setTimeout(() => { + const pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + const size = 16 + Math.ceil(Math.random() * 15) + spawn[pick](this.position.x, this.position.y, size); + }, 1000); + } + if (tech.healSpawn && Math.random() < tech.healSpawn) { + powerUps.spawn(this.position.x + 20 * (Math.random() - 0.5), this.position.y + 20 * (Math.random() - 0.5), "heal"); + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: 50, + color: "#0eb", + time: 12 + }); + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: 100, + color: "#0eb", + time: 6 + }); + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: 200, + color: "#0eb", + time: 3 + }); + } + + if (tech.isVerlet && !m.isTimeDilated) { + requestAnimationFrame(() => { + simulation.timePlayerSkip(this.isBoss ? 60 : 30) + simulation.loop(); //ending with a wipe and normal loop fixes some very minor graphical issues where things are draw in the wrong locations + }); //wrapping in animation frame prevents errors, probably + } + if (tech.isEnergyLoss) { + m.energy -= 0.05; + if (m.energy < 0) m.energy = 0 + } + powerUps.spawnRandomPowerUp(this.position.x, this.position.y); + m.lastKillCycle = m.cycle; //tracks the last time a kill was made, mostly used in simulation.checks() + mobs.mobDeaths++ + + if (Math.random() < tech.sporesOnDeath) { + const amount = Math.min(25, Math.floor(2 + this.mass * (0.5 + 0.5 * Math.random()))) + if (tech.isSporeFlea) { + const len = amount / 2 + for (let i = 0; i < len; i++) { + const speed = 10 + 5 * Math.random() + const angle = 2 * Math.PI * Math.random() + b.flea(this.position, { x: speed * Math.cos(angle), y: speed * Math.sin(angle) }) + } + } else if (tech.isSporeWorm) { + const len = amount / 2 + for (let i = 0; i < len; i++) b.worm(this.position) + } else { + for (let i = 0; i < amount; i++) b.spore(this.position) + } + } else if (tech.isExplodeMob) { + b.explosion(this.position, Math.min(700, Math.sqrt(this.mass + 6) * (30 + 60 * Math.random()))) + } else if (tech.nailsDeathMob) { + b.targetedNail(this.position, tech.nailsDeathMob, 39 + 6 * Math.random()) + } + if (tech.isBotSpawnerReset) { + for (let i = 0, len = bullet.length; i < len; i++) { + if (bullet[i].botType && bullet[i].endCycle !== Infinity) bullet[i].endCycle = simulation.cycle + 900 //15 seconds + } + } + if (Math.random() < tech.botSpawner) { + b.randomBot(this.position, false) + bullet[bullet.length - 1].endCycle = simulation.cycle + 900 //15 seconds + this.leaveBody = false; // no body since it turned into the bot + } + if (tech.isMobDeathImmunity) { + const immuneTime = 360 + if (m.immuneCycle < m.cycle + immuneTime) m.immuneCycle = m.cycle + immuneTime; //player is immune to damage + } + if (tech.isAddRemoveMaxHealth) { + if (!this.isBoss) { + const amount = 0.0025 + if (tech.isEnergyHealth) { + if (m.maxEnergy > amount) { + tech.healMaxEnergyBonus -= amount + m.setMaxEnergy(); + } + } else if (m.maxHealth > amount) { + tech.extraMaxHealth -= amount //decrease max health + m.setMaxHealth(); + } + } + } + if (tech.cloakDuplication && !this.isBoss) { + tech.cloakDuplication -= 0.01 + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + } + } else if (tech.isShieldAmmo && this.shield && this.shieldCount === 1) { + let type = "ammo" + if (Math.random() < 0.4) { + type = "heal" + } else if (Math.random() < 0.3 && !tech.isSuperDeterminism) { + type = "research" + } + for (let i = 0, len = Math.ceil(2 * Math.random()); i < len; i++) { + powerUps.spawn(this.position.x, this.position.y, type); + } + } + if (tech.isRadioactive) { + //look for dots and spread them + let dmgTotal = 0 + for (let i = 0, len = this.status.length; i < len; i++) { + if (this.status[i].type === "dot") dmgTotal += this.status[i].dmg * (this.status[i].endCycle - simulation.cycle) + } + if (dmgTotal > 0) { //look for closest mob + let closestRadius = 500; + let closestIndex = null; + for (let i = 0, len = mob.length; i < len; ++i) { + const radius = Vector.magnitude(Vector.sub(this.position, mob[i].position)) + if (mob[i].alive && !mob[i].isShielded && radius < closestRadius) { + closestRadius = radius + closestIndex = i + } + } + if (closestIndex) { + mobs.statusDoT(mob[closestIndex], dmgTotal / 180, 180) + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(mob[closestIndex].position.x, mob[closestIndex].position.y); + ctx.lineWidth = this.radius; + ctx.strokeStyle = "rgba(0,80,80,1)"; + ctx.stroke(); + } + //draw AOE + // simulation.drawList.push({ //add dmg to draw queue + // x: this.position.x, + // y: this.position.y, + // radius: radius, + // color: "rgba(0,80,80,0.03)", + // time: 15 + // }); + } + } + }, + removeConsBB() { + for (let i = 0, len = consBB.length; i < len; ++i) { + if (consBB[i].bodyA === this) { + if (consBB[i].bodyB.shield) { //&& !this.shield + consBB[i].bodyB.do = function () { this.death() } + } + consBB[i].bodyA = consBB[i].bodyB; + consBB.splice(i, 1); + this.removeConsBB(); + break; + } else if (consBB[i].bodyB === this) { + if (consBB[i].bodyA.shield) { + consBB[i].bodyA.do = function () { this.death() } + } + consBB[i].bodyB = consBB[i].bodyA; + consBB.splice(i, 1); + this.removeConsBB(); + break; + } + } + }, + removeCons() { + for (let i = 0, len = cons.length; i < len; ++i) { + if (cons[i].bodyA === this) { + cons[i].bodyA = cons[i].bodyB; + cons.splice(i, 1); + this.removeCons(); + break; + } else if (cons[i].bodyB === this) { + cons[i].bodyB = cons[i].bodyA; + cons.splice(i, 1); + this.removeCons(); + break; + } + } + }, + //replace dead mob with a regular body + replace(i) { + //if there are too many bodies don't turn into blocks to help performance + if (this.leaveBody && body.length < mobs.maxMobBody && this.mass < 200 && this.mass > 2 && this.radius > 18) { + let v = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) //might help with vertex collision issue, not sure + if (v.length > 5 && body.length < 35 && Math.random() < 0.25) { + const cutPoint = 3 + Math.floor((v.length - 6) * Math.random()) //Math.floor(v.length / 2) + const v2 = v.slice(0, cutPoint + 1) + v = v.slice(cutPoint - 1) + const len = body.length; + body[len] = Matter.Bodies.fromVertices(this.position.x, this.position.y, v2); + Matter.Body.setVelocity(body[len], Vector.mult(this.velocity, 0.5)); + Matter.Body.setAngularVelocity(body[len], this.angularVelocity); + body[len].collisionFilter.category = cat.body; + body[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet; + body[len].classType = "body"; + body[len].frictionAir = 0.001 + body[len].friction = 0.05 + Composite.add(engine.world, body[len]); //add to world + + const len2 = body.length; + body[len2] = Matter.Bodies.fromVertices(this.position.x, this.position.y, v); + Matter.Body.setVelocity(body[len2], Vector.mult(this.velocity, 0.5)); + Matter.Body.setAngularVelocity(body[len2], this.angularVelocity); + body[len2].collisionFilter.category = cat.body; + body[len2].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet; + body[len2].classType = "body"; + body[len2].frictionAir = 0.001 + body[len2].friction = 0.05 + Composite.add(engine.world, body[len2]); //add to world + + //large mobs shrink so they don't block paths + if (body[len].mass + body[len2].mass > 16) { + const massLimit = 8 + 6 * Math.random() + const shrink = function (that1, that2) { + if (that1.mass + that2.mass > massLimit) { + const scale = 0.95; + Matter.Body.scale(that1, scale, scale); + Matter.Body.scale(that2, scale, scale); + setTimeout(shrink, 20, that1, that2); + } + }; + shrink(body[len], body[len2]) + } + } else { + const len = body.length; + body[len] = Matter.Bodies.fromVertices(this.position.x, this.position.y, v); + Matter.Body.setVelocity(body[len], Vector.mult(this.velocity, 0.5)); + Matter.Body.setAngularVelocity(body[len], this.angularVelocity); + body[len].collisionFilter.category = cat.body; + body[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet; + body[len].classType = "body"; + body[len].frictionAir = 0.001 + body[len].friction = 0.05 + Composite.add(engine.world, body[len]); //add to world + //large mobs shrink so they don't block paths + if (body[len].mass > 9) { + const massLimit = 7 + 4 * Math.random() + const shrink = function (that) { + if (that.mass > massLimit) { + const scale = 0.95; + Matter.Body.scale(that, scale, scale); + setTimeout(shrink, 20, that); + } + }; + shrink(body[len]) + } + } + Matter.Composite.remove(engine.world, this); + mob.splice(i, 1); + if (tech.isMobBlockFling) { + const who = body[body.length - 1] + if (!who.isNotHoldable) { + b.targetedBlock(who) + Matter.Body.setAngularVelocity(who, (0.5 + 0.2 * Math.random()) * (Math.random() < 0.5 ? -1 : 1)); + // who.torque += who.inertia * 0.002 * (Math.random() - 0.5) + } + } + } else { + Matter.Composite.remove(engine.world, this); + mob.splice(i, 1); + } + } + }); + mob[i].alertRange2 = Math.pow(mob[i].radius * 3 + 550, 2); + Composite.add(engine.world, mob[i]); //add to world + } +}; \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/player.js b/WebGames-master/WebGames-master/n-gon-master/js/player.js new file mode 100644 index 00000000..83d4a473 --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/player.js @@ -0,0 +1,6327 @@ +//global player variables for use in matter.js physics +let player, jumpSensor, playerBody, playerHead, headSensor; + +// player Object Prototype ********************************************* +const m = { + spawn() { + //load player in matter.js physic engine + // let vector = Vertices.fromPath("0 40 50 40 50 115 0 115 30 130 20 130"); //player as a series of vertices + let vertices = Vertices.fromPath("0,40, 50,40, 50,115, 30,130, 20,130, 0,115, 0,40"); //player as a series of vertices + playerBody = Bodies.fromVertices(0, 0, vertices); + jumpSensor = Bodies.rectangle(0, 46, 36, 6, { //(0, 46, 50, 6, { //for wall jumping + //this sensor check if the player is on the ground to enable jumping + sleepThreshold: 99999999999, + isSensor: true + }); + vertices = Vertices.fromPath("16 -82 2 -66 2 -37 43 -37 43 -66 30 -82"); + playerHead = Bodies.fromVertices(0, -55, vertices); //this part of the player lowers on crouch + headSensor = Bodies.rectangle(0, -57, 48, 45, { + //senses if the player's head is empty and can return after crouching + sleepThreshold: 99999999999, + isSensor: true + }); + player = Body.create({ + //combine jumpSensor and playerBody + parts: [playerBody, playerHead, jumpSensor, headSensor], + inertia: Infinity, //prevents player rotation + friction: 0.002, + frictionAir: 0.001, + //frictionStatic: 0.5, + restitution: 0, + sleepThreshold: Infinity, + collisionFilter: { + group: 0, + category: cat.player, + mask: cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield + }, + // death() { + // m.death(); + // } + }); + Matter.Body.setMass(player, m.mass); + Composite.add(engine.world, [player]); + }, + cycle: 600, //starts at 600 cycles instead of 0 to prevent bugs with m.history + lastKillCycle: 0, + lastHarmCycle: 0, + width: 50, + radius: 30, + eyeFillColor: null, + fillColor: null, //set by setFillColors + fillColorDark: null, //set by setFillColors + bodyGradient: null, //set by setFillColors + color: { + hue: 0, + sat: 0, + light: 100, + }, + setFillColors() { + m.fillColor = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light}%)` + m.fillColorDark = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light - 25}%)` + let grd = ctx.createLinearGradient(-30, 0, 30, 0); + grd.addColorStop(0, m.fillColorDark); + grd.addColorStop(1, m.fillColor); + m.bodyGradient = grd + }, + // setFillColorsAlpha(alpha = 0.5) { + // m.fillColor = `hsla(${m.color.hue},${m.color.sat}%,${m.color.light}%,${alpha})` + // m.fillColorDark = `hsla(${m.color.hue},${m.color.sat}%,${m.color.light - 25}%,${alpha})` + // let grd = ctx.createLinearGradient(-30, 0, 30, 0); + // grd.addColorStop(0, m.fillColorDark); + // grd.addColorStop(1, m.fillColor); + // m.bodyGradient = grd + // }, + height: 42, + yOffWhen: { + crouch: 22, + stand: 49, + jump: 70 + }, + defaultMass: 5, + mass: 5, + FxNotHolding: 0.015, + Fx: 0.016, //run Force on ground // + jumpForce: 0.42, + setMovement() { + // console.log(player.mass) + // m.FxAir = 0.4 / mass / mass + m.Fx = tech.baseFx * m.fieldFx * m.squirrelFx * (tech.isFastTime ? 1.5 : 1) / player.mass //base player mass is 5 + m.jumpForce = tech.baseJumpForce * m.fieldJump * m.squirrelJump * (tech.isFastTime ? 1.13 : 1) / player.mass / player.mass //base player mass is 5 + }, + FxAir: 0.016, // 0.4/5/5 run Force in Air + yOff: 70, + yOffGoal: 70, + onGround: false, //checks if on ground or in air + lastOnGroundCycle: 0, //use to calculate coyote time + coyoteCycles: 5, + hardLanding: 130, + squirrelFx: 1, + squirrelJump: 1, + velocitySmooth: { x: 0, y: 0 },//use for drawing skin's velocity gel tail + standingOn: undefined, + numTouching: 0, + crouch: false, + // isHeadClear: true, + spawnPos: { + x: 0, + y: 0 + }, + spawnVel: { + x: 0, + y: 0 + }, + pos: { + x: 0, + y: 0 + }, + yPosDifference: 24.2859, //player.position.y - m.pos.y //24.285923217549026 + // yPosDifferenceCrouched: -2.7140767824453604, + Sy: 0, //adds a smoothing effect to vertical only + Vx: 0, + Vy: 0, + friction: { + ground: 0.01, + air: 0.0025 + }, + airSpeedLimit: 125, // 125/mass/mass = 5 + angle: 0, + walk_cycle: 0, + stepSize: 0, + flipLegs: -1, + hip: { + x: 12, + y: 24 + }, + knee: { + x: 0, + y: 0, + x2: 0, + y2: 0 + }, + foot: { + x: 0, + y: 0 + }, + legLength1: 55, + legLength2: 45, + transX: 0, + transY: 0, + history: new Array(600), //[], //tracks the last second of player position + rewindCount: 0, //used with CPT + resetHistory() { + const set = { + position: { + x: player.position.x, + y: player.position.y, + }, + velocity: { + x: player.velocity.x, + y: player.velocity.y + }, + yOff: m.yOff, + angle: m.angle, + health: m.health, + energy: m.energy, + activeGun: b.activeGun + } + for (let i = 0; i < 600; i++) { //reset history + m.history[i] = set + } + }, + move() { + m.pos.x = player.position.x; + m.pos.y = playerBody.position.y - m.yOff; + m.Vx = player.velocity.x; + m.Vy = player.velocity.y; + + //tracks the last 10s of player information + m.history.splice(m.cycle % 600, 1, { + position: { + x: player.position.x, + y: player.position.y, + }, + velocity: { + x: player.velocity.x, + y: player.velocity.y + }, + yOff: m.yOff, + angle: m.angle, + health: m.health, + energy: m.energy, + activeGun: b.activeGun + }); + // const back = 59 // 59 looks at 1 second ago //29 looks at 1/2 a second ago + // historyIndex = (m.cycle - back) % 600 + }, + transSmoothX: 0, + transSmoothY: 0, + lastGroundedPositionY: 0, + // mouseZoom: 0, + lookSmoothing: 0.07, //1 is instant jerky, 0.001 is slow smooth zoom, 0.07 is standard + look() { }, //set to lookDefault() + lookDefault() { + //always on mouse look + m.angle = Math.atan2(simulation.mouseInGame.y - m.pos.y, simulation.mouseInGame.x - m.pos.x); + //smoothed mouse look translations + const scale = 0.8; + m.transSmoothX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale + m.transSmoothY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale + + m.transX += (m.transSmoothX - m.transX) * m.lookSmoothing; + m.transY += (m.transSmoothY - m.transY) * m.lookSmoothing; + }, + doCrouch() { + if (!m.crouch) { + m.crouch = true; + m.yOffGoal = m.yOffWhen.crouch; + if ((playerHead.position.y - player.position.y) < 0) { + Matter.Body.setPosition(playerHead, { x: player.position.x, y: player.position.y + 9.1740767 }) + } + } + }, + undoCrouch() { + if (m.crouch) { + m.crouch = false; + m.yOffGoal = m.yOffWhen.stand; + if ((playerHead.position.y - player.position.y) > 0) { + Matter.Body.setPosition(playerHead, { x: player.position.x, y: player.position.y - 30.28592321 }) + } + } + }, + hardLandCD: 0, + hardLandCDScale: 1, + checkHeadClear() { + if (Matter.Query.collides(headSensor, map).length > 0) { + return false + } else { + return true + } + }, + buttonCD_jump: 0, //cool down for player buttons + jump() { + m.buttonCD_jump = m.cycle; //can't jump again until 20 cycles pass + //apply a fraction of the jump force to the body the player is jumping off of + Matter.Body.applyForce(m.standingOn, m.pos, { x: 0, y: m.jumpForce * 0.12 * Math.min(m.standingOn.mass, 5) }); + player.force.y = -m.jumpForce; //player jump force + Matter.Body.setVelocity(player, { //zero player y-velocity for consistent jumps + x: player.velocity.x, + y: Math.max(-10, Math.min(m.standingOn.velocity.y, 10)) //cap velocity contribution from blocks you are standing on to 10 in the vertical + }); + }, + moverX: 0, //used to tell the player about moving platform x velocity + groundControl() { + //check for crouch or jump + if (m.crouch) { + if (!(input.down) && m.checkHeadClear() && m.hardLandCD < m.cycle) m.undoCrouch(); + } else if (input.down || m.hardLandCD > m.cycle) { + m.doCrouch(); //on ground && not crouched and pressing s or down + } else if (input.up && m.buttonCD_jump + 20 < m.cycle) { + m.jump() + } + const moveX = player.velocity.x - m.moverX //account for mover platforms + if (input.left) { + if (moveX > -2) { + player.force.x -= m.Fx * 1.5 + } else { + player.force.x -= m.Fx + } + // } + } else if (input.right) { + if (moveX < 2) { + player.force.x += m.Fx * 1.5 + } else { + player.force.x += m.Fx + } + } else { + const stoppingFriction = 0.92; //come to a stop if no move key is pressed + Matter.Body.setVelocity(player, { x: m.moverX * 0.08 + player.velocity.x * stoppingFriction, y: player.velocity.y * stoppingFriction }); + } + + if (Math.abs(moveX) > 4) { //come to a stop if fast // if (player.speed > 4) { //come to a stop if fast + const stoppingFriction = (m.crouch) ? 0.65 : 0.89; // this controls speed when crouched + Matter.Body.setVelocity(player, { x: m.moverX * (1 - stoppingFriction) + player.velocity.x * stoppingFriction, y: player.velocity.y * stoppingFriction }); + } + m.moverX = 0 //reset the level mover offset + }, + airControl() { + //check for coyote time jump + if (input.up && m.buttonCD_jump + 20 < m.cycle && m.lastOnGroundCycle + m.coyoteCycles > m.cycle) m.jump() + + //check for short jumps //moving up //recently pressed jump //but not pressing jump key now + if (m.buttonCD_jump + 60 > m.cycle && !(input.up) && m.Vy < 0) { + Matter.Body.setVelocity(player, { x: player.velocity.x, y: player.velocity.y * 0.94 }); //reduce player y-velocity every cycle + } + + if (input.left) { + if (player.velocity.x > -m.airSpeedLimit / player.mass / player.mass) player.force.x -= m.FxAir; // move player left / a + } else if (input.right) { + if (player.velocity.x < m.airSpeedLimit / player.mass / player.mass) player.force.x += m.FxAir; //move player right / d + } + }, + printBlock() { + const sides = Math.floor(4 + 6 * Math.random() * Math.random()) + body[body.length] = Matter.Bodies.polygon(m.pos.x, m.pos.y, sides, 8, { + friction: 0.05, + frictionAir: 0.001, + collisionFilter: { category: 0, mask: 0 }, //no collision because player is holding + classType: "body", + isPrinted: true, + radius: 10, //used to grow and warp the shape of the block + density: 0.002, //double density for 2x damage + }); + const who = body[body.length - 1] + Composite.add(engine.world, who); //add to world + m.throwCharge = 4; + m.holdingTarget = who + m.isHolding = true; + }, + alive: false, + isSwitchingWorlds: false, + switchWorlds(giveTech = "") { + if (!m.isSwitchingWorlds) { + let totalTech = 0; + for (let i = tech.tech.length - 1; i > -1; i--) { + if (tech.tech[i].count > 0 && !tech.tech[i].isLore && !tech.tech[i].isNonRefundable && !tech.tech[i].isAltRealityTech) { + totalTech += tech.tech[i].count + } + } + powerUps.boost.endCycle = 0 + simulation.isTextLogOpen = false; //prevent console spam + tech.resetAllTech() + if (giveTech) tech.giveTech(giveTech) //give many worlds back + + //remove all bullets + for (let i = 0; i < bullet.length; ++i) Matter.Composite.remove(engine.world, bullet[i]); + bullet = []; + + //randomize + powerUps.research.count = Math.floor(powerUps.research.count * (0.5 + 1.5 * Math.random())) + m.coupling = Math.floor(m.coupling * (0.5 + 1.5 * Math.random())) + //randomize health + m.health = m.health * (1 + 0.5 * (Math.random() - 0.5)) + if (m.health > 1) m.health = 1; + //randomize field + m.setField(Math.ceil(Math.random() * (m.fieldUpgrades.length - 1))) + //removes guns and ammo + b.inventory = []; + b.activeGun = null; + b.inventoryGun = 0; + for (let i = 0, len = b.guns.length; i < len; ++i) { + b.guns[i].have = false; + if (b.guns[i].ammo !== Infinity) { + b.guns[i].ammo = 0; + b.guns[i].ammoPack = b.guns[i].defaultAmmoPack; + } + } + //give random guns + // const totalGuns = 1 + Math.floor(b.inventory.length * (0.5 + 1.5 * Math.random())) + const totalGuns = 1 + Math.floor(Math.random() * Math.random() * 7) + for (let i = 0; i < totalGuns; i++) b.giveGuns() + + //randomize ammo based on ammo/ammoPack count + for (let i = 0, len = b.inventory.length; i < len; i++) { + if (b.guns[b.inventory[i]].ammo !== Infinity) b.guns[b.inventory[i]].ammo = Math.floor(b.guns[b.inventory[i]].ammo * (0.25 + Math.random() + Math.random() + Math.random())) + } + + let loop = () => { + if (!(m.cycle % 10)) { + if (totalTech > 0 && m.alive) { + totalTech-- + let options = []; + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isBadRandomOption && !tech.tech[i].isLore && !tech.tech[i].isJunk) { + for (let j = 0; j < tech.tech[i].frequency; j++) options.push(i); + } + } + if (options.length > 0) tech.giveTech(options[Math.floor(Math.random() * options.length)]) //add a new tech from options pool + requestAnimationFrame(loop); + } else { + m.isSwitchingWorlds = false + } + } else if (m.alive) { + requestAnimationFrame(loop); + } else { + m.isSwitchingWorlds = false + } + } + requestAnimationFrame(loop); + + b.respawnBots(); + // for (let i = 0; i < randomBotCount; i++) b.randomBot() + simulation.makeGunHUD(); //update gun HUD + simulation.updateTechHUD(); + m.displayHealth(); + simulation.isTextLogOpen = true; + m.drop(); + if (simulation.paused) build.pauseGrid() //update the build when paused + } + }, + // switchWorlds() { + // if (!m.isSwitchingWorlds) { + // powerUps.boost.endCycle = 0 + // const totalGuns = b.inventory.length + // //track ammo/ ammoPack count + // let ammoCount = 0 + // for (let i = 0, len = b.inventory.length; i < len; i++) { + // if (b.guns[b.inventory[i]].ammo !== Infinity) { + // ammoCount += b.guns[b.inventory[i]].ammo / b.guns[b.inventory[i]].ammoPack + // } else { + // ammoCount += 5 + // } + // } + + // simulation.isTextLogOpen = false; //prevent console spam + // //remove all tech and count current tech total + // let totalTech = 0; + // for (let i = tech.tech.length - 1; i > -1; i--) { + // if (tech.tech[i].isJunk) tech.tech[i].frequency = 0 + // if (tech.tech[i].count > 0 && !tech.tech[i].isLore) { + // if (tech.tech[i].frequencyDefault) { + // tech.tech[i].frequency = tech.tech[i].frequencyDefault + // } else { + // tech.tech[i].frequency = 1 + // } + // if (!tech.tech[i].isNonRefundable && !tech.tech[i].isAltRealityTech) { + // totalTech += tech.tech[i].count + // tech.tech[i].remove(); + // tech.tech[i].isLost = false + // tech.tech[i].count = 0 + // } + // } + // } + // // lore.techCount = 0; + // // tech.removeLoreTechFromPool(); + // // tech.addLoreTechToPool(); + // // tech.removeJunkTechFromPool(); + + + // // tech.junkChance = 0; + // // tech.duplication = 0; + // // tech.extraMaxHealth = 0; + // // tech.totalCount = 0; + // // tech.removeCount = 0; + // // const randomBotCount = b.totalBots() + // // b.zeroBotCount() + // //remove all bullets, respawn bots + // for (let i = 0; i < bullet.length; ++i) Matter.Composite.remove(engine.world, bullet[i]); + // bullet = []; + + // //randomize health + // m.health = m.health * (1 + 0.5 * (Math.random() - 0.5)) + // if (m.health > 1) m.health = 1; + // m.displayHealth(); + // //randomize field + // m.setField(Math.ceil(Math.random() * (m.fieldUpgrades.length - 1))) + // //removes guns and ammo + // b.inventory = []; + // b.activeGun = null; + // b.inventoryGun = 0; + // for (let i = 0, len = b.guns.length; i < len; ++i) { + // b.guns[i].have = false; + // if (b.guns[i].ammo !== Infinity) { + // b.guns[i].ammo = 0; + // b.guns[i].ammoPack = b.guns[i].defaultAmmoPack; + // } + // } + // //give random guns + // for (let i = 0; i < totalGuns; i++) b.giveGuns() + + // //randomize ammo based on ammo/ammoPack count + // for (let i = 0, len = b.inventory.length; i < len; i++) { + // if (b.guns[b.inventory[i]].ammo !== Infinity) b.guns[b.inventory[i]].ammo = Math.max(0, Math.floor(ammoCount / b.inventory.length * b.guns[b.inventory[i]].ammoPack * (2.5 + 0.3 * (Math.random() - 0.5)))) + // } + + + // //randomize tech + // // for (let i = 0; i < totalTech; i++) { + // // let options = []; + // // for (let i = 0, len = tech.tech.length; i < len; i++) { + // // if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isBadRandomOption && !tech.tech[i].isLore && !tech.tech[i].isJunk) { + // // for (let j = 0; j < tech.tech[i].frequency; j++) options.push(i); + // // } + // // } + // // if (options.length > 0) tech.giveTech(options[Math.floor(Math.random() * options.length)]) //add a new tech from options pool + + // // } + // let loop = () => { + // if (!(m.cycle % 10)) { + // if (totalTech > 0 && m.alive) { + // totalTech-- + // let options = []; + // for (let i = 0, len = tech.tech.length; i < len; i++) { + // if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isBadRandomOption && !tech.tech[i].isLore && !tech.tech[i].isJunk) { + // for (let j = 0; j < tech.tech[i].frequency; j++) options.push(i); + // } + // } + // if (options.length > 0) tech.giveTech(options[Math.floor(Math.random() * options.length)]) //add a new tech from options pool + // requestAnimationFrame(loop); + // } else { + // m.isSwitchingWorlds = false + // } + // } else if (m.alive) { + // requestAnimationFrame(loop); + // } else { + // m.isSwitchingWorlds = false + // } + // } + // requestAnimationFrame(loop); + + // b.respawnBots(); + // // for (let i = 0; i < randomBotCount; i++) b.randomBot() + // simulation.makeGunHUD(); //update gun HUD + // simulation.updateTechHUD(); + // simulation.isTextLogOpen = true; + // m.drop(); + // if (simulation.paused) build.pauseGrid() //update the build when paused + // } + // }, + // switchWorlds() { + // if (!m.isSwitchingWorlds) { + // powerUps.boost.endCycle = 0 + // const totalGuns = b.inventory.length + // //track ammo/ ammoPack count + // let ammoCount = 0 + // for (let i = 0, len = b.inventory.length; i < len; i++) { + // if (b.guns[b.inventory[i]].ammo !== Infinity) { + // ammoCount += b.guns[b.inventory[i]].ammo / b.guns[b.inventory[i]].ammoPack + // } else { + // ammoCount += 5 + // } + // } + + // simulation.isTextLogOpen = false; //prevent console spam + // //remove all tech and count current tech total + // let totalTech = 0; + // for (let i = 0, len = tech.tech.length; i < len; i++) { + // if (tech.tech[i].isJunk) tech.tech[i].frequency = 0 + // if (tech.tech[i].count > 0 && !tech.tech[i].isLore) { + // if (tech.tech[i].frequencyDefault) { + // tech.tech[i].frequency = tech.tech[i].frequencyDefault + // } else { + // tech.tech[i].frequency = 1 + // } + // if ( + // !tech.tech[i].isNonRefundable && + // // !tech.tech[i].isFromAppliedScience && + // !tech.tech[i].isAltRealityTech + // ) { + // totalTech += tech.tech[i].count + // tech.tech[i].remove(); + // tech.tech[i].isLost = false + // tech.tech[i].count = 0 + // } + // } + // } + // // lore.techCount = 0; + // // tech.removeLoreTechFromPool(); + // // tech.addLoreTechToPool(); + // // tech.removeJunkTechFromPool(); + + + // tech.junkChance = 0; + // tech.duplication = 0; + // tech.extraMaxHealth = 0; + // tech.totalCount = 0; + // tech.removeCount = 0; + // // const randomBotCount = b.totalBots() + // b.zeroBotCount() + // //remove all bullets, respawn bots + // for (let i = 0; i < bullet.length; ++i) Matter.Composite.remove(engine.world, bullet[i]); + // bullet = []; + + // //randomize health + // m.health = m.health * (1 + 0.5 * (Math.random() - 0.5)) + // if (m.health > 1) m.health = 1; + // m.displayHealth(); + // //randomize field + // m.setField(Math.ceil(Math.random() * (m.fieldUpgrades.length - 1))) + // //removes guns and ammo + // b.inventory = []; + // b.activeGun = null; + // b.inventoryGun = 0; + // for (let i = 0, len = b.guns.length; i < len; ++i) { + // b.guns[i].have = false; + // if (b.guns[i].ammo !== Infinity) { + // b.guns[i].ammo = 0; + // b.guns[i].ammoPack = b.guns[i].defaultAmmoPack; + // } + // } + // //give random guns + // for (let i = 0; i < totalGuns; i++) b.giveGuns() + + // //randomize ammo based on ammo/ammoPack count + // for (let i = 0, len = b.inventory.length; i < len; i++) { + // if (b.guns[b.inventory[i]].ammo !== Infinity) b.guns[b.inventory[i]].ammo = Math.max(0, Math.floor(ammoCount / b.inventory.length * b.guns[b.inventory[i]].ammoPack * (2.5 + 0.3 * (Math.random() - 0.5)))) + // } + + + // //randomize tech + // // for (let i = 0; i < totalTech; i++) { + // // let options = []; + // // for (let i = 0, len = tech.tech.length; i < len; i++) { + // // if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isBadRandomOption && !tech.tech[i].isLore && !tech.tech[i].isJunk) { + // // for (let j = 0; j < tech.tech[i].frequency; j++) options.push(i); + // // } + // // } + // // if (options.length > 0) tech.giveTech(options[Math.floor(Math.random() * options.length)]) //add a new tech from options pool + + // // } + // let loop = () => { + // if (!(m.cycle % 10)) { + // if (totalTech > 0 && m.alive) { + // totalTech-- + // let options = []; + // for (let i = 0, len = tech.tech.length; i < len; i++) { + // if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isBadRandomOption && !tech.tech[i].isLore && !tech.tech[i].isJunk) { + // for (let j = 0; j < tech.tech[i].frequency; j++) options.push(i); + // } + // } + // if (options.length > 0) tech.giveTech(options[Math.floor(Math.random() * options.length)]) //add a new tech from options pool + // requestAnimationFrame(loop); + // } else { + // m.isSwitchingWorlds = false + // } + // } else if (m.alive) { + // requestAnimationFrame(loop); + // } else { + // m.isSwitchingWorlds = false + // } + // } + // requestAnimationFrame(loop); + + // b.respawnBots(); + // // for (let i = 0; i < randomBotCount; i++) b.randomBot() + // simulation.makeGunHUD(); //update gun HUD + // simulation.updateTechHUD(); + // simulation.isTextLogOpen = true; + // m.drop(); + // if (simulation.paused) build.pauseGrid() //update the build when paused + // } + // }, + dmgScale: null, //scales all damage, but not raw .dmg + death() { + if (tech.isImmortal) { //if player has the immortality buff, spawn on the same level with randomized damage + //remove immortality tech + // for (let i = 0; i < tech.tech.length; i++) { + // if (tech.tech[i].name === "quantum immortality") tech.removeTech(i) + // } + + m.setMaxHealth() + m.health = 1; + // m.addHealth(1) + + simulation.wipe = function () { //set wipe to have trails + ctx.fillStyle = "rgba(255,255,255,0)"; + ctx.fillRect(0, 0, canvas.width, canvas.height); + } + spawn.setSpawnList(); //new mob types + level.isFlipped = false + simulation.clearNow = true; //triggers a map reset + + m.switchWorlds() + const swapPeriod = 1000 + for (let i = 0, len = 5; i < len; i++) { + setTimeout(function () { + simulation.wipe = function () { //set wipe to have trails + ctx.fillStyle = "rgba(255,255,255,0)"; + ctx.fillRect(0, 0, canvas.width, canvas.height); + } + spawn.setSpawnList(); //new mob types + // simulation.clearNow = true; //triggers a map reset + // m.switchWorlds() + simulation.isTextLogOpen = true; + simulation.inGameConsole(`simulation.amplitude = 0.${len - i - 1}`, swapPeriod); + simulation.isTextLogOpen = false; + simulation.wipe = function () { //set wipe to have trails + ctx.fillStyle = `rgba(255,255,255,${(i + 1) * (i + 1) * 0.006})`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + } + }, (i + 1) * swapPeriod); + } + setTimeout(function () { + simulation.wipe = function () { //set wipe to normal + ctx.clearRect(0, 0, canvas.width, canvas.height); + } + simulation.isTextLogOpen = true; + simulation.inGameConsole("simulation.amplitude = null"); + tech.isImmortal = false //disable future immortality + }, 6 * swapPeriod); + } else if (m.alive) { //normal death code here + m.storeTech() + m.alive = false; + simulation.paused = true; + m.health = 0; + simulation.ephemera = [] + document.getElementById("defense-bar").style.display = "none"; //hide defense + document.getElementById("damage-bar").style.display = "none" + m.displayHealth(); + document.getElementById("text-log").style.display = "none" + document.getElementById("fade-out").style.opacity = 0.9; //slowly fade to 90% white on top of canvas + setTimeout(function () { + Composite.clear(engine.world); + Engine.clear(engine); + simulation.splashReturn(); + }, 5000); + } + }, + storeTech() { //store a copy of your tech, it will show up at your location next run in the entanglement power up + if (localSettings.isAllowed && !simulation.isCheating) { + const gunList = [] //store gun names + for (i = 0, len = b.inventory.length; i < len; i++) gunList.push(b.inventory[i]) + const techList = [] //store tech names + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].count > 0 && !tech.tech[i].isNonRefundable) techList.push(tech.tech[i].name) + } + if (techList.length) { + localSettings.entanglement = { + fieldIndex: m.fieldMode, + gunIndexes: gunList, + techIndexes: techList, + position: { + x: m.pos.x, + y: m.pos.y + }, + levelName: level.levels[level.onLevel], + isHorizontalFlipped: simulation.isHorizontalFlipped + } + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + } + }, + health: 0, + maxHealth: 1, //set in simulation.reset() + drawHealth() { + if (m.health < 1) { + ctx.fillStyle = "rgba(100, 100, 100, 0.5)"; + ctx.fillRect(m.pos.x - m.radius, m.pos.y - 50, 60, 10); + ctx.fillStyle = "#f00"; + ctx.fillRect( + m.pos.x - m.radius, + m.pos.y - 50, + 60 * m.health, + 10 + ); + } + }, + displayHealth() { + id = document.getElementById("health"); + // health display is a x^1.5 rule to make it seem like the player has lower health, this makes the player feel more excitement + id.style.width = Math.floor(300 * m.maxHealth * Math.pow(m.health / m.maxHealth, 1.4)) + "px"; + //css animation blink if health is low + // if (m.health < 0.3) { + // id.classList.add("low-health"); + // } else { + // id.classList.remove("low-health"); + // } + }, + addHealth(heal) { + if (!tech.isEnergyHealth) { + m.health += heal * simulation.healScale * (level.isLowHeal ? 0.5 : 1); + if (m.health > m.maxHealth) m.health = m.maxHealth; + m.displayHealth(); + } + }, + baseHealth: 1, + setMaxHealth(isMessage) { + m.maxHealth = m.baseHealth + tech.extraMaxHealth + 5 * tech.isFallingDamage + if (level.isReducedHealth) { + level.reducedHealthLost = Math.max(0, m.health - m.maxHealth * 0.5) + m.maxHealth *= 0.5 + } + document.getElementById("health-bg").style.width = `${Math.floor(300 * m.maxHealth)}px` + document.getElementById("defense-bar").style.width = Math.floor(300 * m.maxHealth * (1 - m.defense())) + "px"; + + if (isMessage) simulation.inGameConsole(`m.maxHealth = ${m.maxHealth.toFixed(2)}`) + if (m.health > m.maxHealth) m.health = m.maxHealth; + m.displayHealth(); + }, + defaultFPSCycle: 0, //tracks when to return to normal fps + immuneCycle: 0, //used in engine + lastCalculatedDamage: 0, //used to decided if damage bar needs to be redrawn (in simulation.checks) + lastCalculatedDefense: 0, //used to decided if defense bar needs to be redrawn (in simulation.checks) + defense() { + let dmg = 1 + if (powerUps.boost.isDefense && powerUps.boost.endCycle > simulation.cycle) dmg *= 0.3 + if (tech.isMaxHealthDefense && m.health === m.maxHealth) dmg *= 0.2 + if (tech.isDiaphragm) dmg *= 0.55 + 0.35 * Math.sin(m.cycle * 0.0075); + if (tech.isZeno) dmg *= 0.15 + if (tech.isFieldHarmReduction) dmg *= 0.6 + if (tech.isHarmDarkMatter) dmg *= (tech.isMoveDarkMatter || tech.isNotDarkMatter) ? 0.25 : 0.4 + if (tech.isImmortal) dmg *= 0.7 + if (m.fieldMode === 0 || m.fieldMode === 3) dmg *= 0.973 ** m.coupling + if (tech.isHarmReduceNoKill && m.lastKillCycle + 300 < m.cycle) dmg *= 0.3 + if (tech.isAddBlockMass && m.isHolding) dmg *= 0.1 + if (tech.isSpeedHarm && (tech.speedAdded + player.speed) > 0.1) dmg *= 1 - Math.min((tech.speedAdded + player.speed) * 0.01583, 0.95) //capped at speed of 55 + if (tech.isHarmReduce && input.field) dmg *= 0.1 + if (tech.isNeutronium && input.field && m.fieldCDcycle < m.cycle) dmg *= 0.05 + if (tech.isBotArmor) dmg *= 0.96 ** b.totalBots() + if (tech.isHarmArmor && m.lastHarmCycle + 600 > m.cycle) dmg *= 0.3; + if (tech.isNoFireDefense && m.cycle > m.fireCDcycle + 120) dmg *= 0.3 + if (tech.isTurret && m.crouch) dmg *= 0.3; + if (tech.isFirstDer && b.inventory[0] === b.activeGun) dmg *= 0.85 ** b.inventory.length + // if (tech.isLowHealthDefense) dmg *= Math.pow(0.3, Math.max(0, (tech.isEnergyHealth ? m.maxEnergy - m.energy : m.maxHealth - m.health))) + if (tech.isLowHealthDefense) dmg *= Math.pow(0.2, Math.max(0, 1 - (tech.isEnergyHealth ? m.energy / m.maxEnergy : m.health / m.maxHealth))) + // return tech.isEnergyHealth ? Math.pow(dmg, 0.7) : dmg //defense has less effect + // dmg *= m.fieldHarmReduction + return dmg * m.fieldHarmReduction + }, + rewind(steps) { // m.rewind(Math.floor(Math.min(599, 137 * m.energy))) + if (tech.isRewindGrenade) { + const immunityDuration = 50 + const immunityCycle = m.cycle + immunityDuration + 10 + tech.isPetalsExplode * 30 + tech.isCircleExplode * 21 + if (m.immuneCycle < immunityCycle) m.immuneCycle = immunityCycle; //player is immune to damage until after grenades might explode... + + for (let i = 1, len = Math.floor(4 + steps / 40); i < len; i++) { + b.grenade(Vector.add(m.pos, { x: 10 * (Math.random() - 0.5), y: 10 * (Math.random() - 0.5) }), -i * Math.PI / len) //fire different angles for each grenade + const who = bullet[bullet.length - 1] + + if (tech.isNeutronBomb) { + Matter.Body.setVelocity(who, { x: who.velocity.x * 0.3, y: who.velocity.y * 0.3 }); + } else if (tech.isVacuumBomb) { + Matter.Body.setVelocity(who, { x: who.velocity.x * 0.5, y: who.velocity.y * 0.5 }); + who.endCycle = simulation.cycle + immunityDuration + + } else if (tech.isRPG) { + who.endCycle = simulation.cycle + 10 + } else { + Matter.Body.setVelocity(who, { x: who.velocity.x * 0.5, y: who.velocity.y * 0.5 }); + who.endCycle = simulation.cycle + immunityDuration + } + } + } + + let history = m.history[(m.cycle - steps) % 600] + Matter.Body.setPosition(player, history.position); + Matter.Body.setVelocity(player, { x: history.velocity.x, y: history.velocity.y }); + m.yOff = history.yOff + if (m.yOff < 48) { + m.doCrouch() + } else { + m.undoCrouch() + } + + // b.activeGun = history.activeGun + // for (let i = 0; i < b.inventory.length; i++) { + // if (b.inventory[i] === b.activeGun) b.inventoryGun = i + // } + // simulation.updateGunHUD(); + // simulation.boldActiveGunHUD(); + + // move bots to player's new position + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + m.energy = Math.max(m.energy - steps / 330, 0.01) + if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + + let isDrawPlayer = true + const shortPause = function () { + if (m.defaultFPSCycle < m.cycle) { //back to default values + simulation.fpsCap = simulation.fpsCapDefault + simulation.fpsInterval = 1000 / simulation.fpsCap; + document.getElementById("dmg").style.transition = "opacity 1s"; + document.getElementById("dmg").style.opacity = "0"; + } else { + requestAnimationFrame(shortPause); + if (isDrawPlayer) { + isDrawPlayer = false + ctx.save(); + ctx.globalCompositeOperation = "lighter"; + ctx.translate(canvas.width2, canvas.height2); //center + ctx.scale(simulation.zoom / simulation.edgeZoomOutSmooth, simulation.zoom / simulation.edgeZoomOutSmooth); //zoom in once centered + ctx.translate(-canvas.width2 + m.transX, -canvas.height2 + m.transY); //translate + for (let i = 1; i < steps; i++) { + history = m.history[(m.cycle - i) % 600] + m.pos.x = history.position.x + m.pos.y = history.position.y + m.yPosDifference - history.yOff + m.yOff = history.yOff + m.draw(); + } + ctx.restore(); + m.resetHistory() + } + } + }; + + if (m.defaultFPSCycle < m.cycle) requestAnimationFrame(shortPause); + simulation.fpsCap = 3 //1 is longest pause, 4 is standard + simulation.fpsInterval = 1000 / simulation.fpsCap; + m.defaultFPSCycle = m.cycle + if (tech.isRewindBot) { + const len = steps * 0.05 * tech.isRewindBot + const botStep = Math.floor(steps / len) + for (let i = 0; i < len; i++) { + const where = m.history[Math.abs(m.cycle - i * botStep) % 600].position //spread out spawn locations along past history + b.randomBot({ + x: where.x + 20 * (Math.random() - 0.5), + y: where.y + 20 * (Math.random() - 0.5) + }, false, false) + bullet[bullet.length - 1].endCycle = simulation.cycle + 440 + Math.floor(120 * Math.random()) //8-10 seconds + } + } + }, + collisionImmuneCycles: 30, + damage(dmg, isDefense = true) { + if (tech.isRewindAvoidDeath && (m.energy + 0.05) > Math.min(0.95, m.maxEnergy) && dmg > 0.01) { + const steps = Math.floor(Math.min(299, 150 * m.energy)) + simulation.inGameConsole(`m.rewind(${steps})`) + m.rewind(steps) + return + } + m.lastHarmCycle = m.cycle + if (tech.isDroneOnDamage && bullet.length < 180) { //chance to build a drone on damage from tech + const len = Math.min((dmg - 0.045 * Math.random()) * 95, 65) / tech.droneEnergyReduction * (tech.isEnergyHealth ? 0.5 : 1) + for (let i = 0; i < len; i++) { + if (Math.random() < 0.5) b.drone({ + x: m.pos.x + 30 * Math.cos(m.angle) + 100 * (Math.random() - 0.5), + y: m.pos.y + 30 * Math.sin(m.angle) + 100 * (Math.random() - 0.5) + }) //spawn drone + } + } + if (tech.isEnergyHealth) { + if (isDefense) dmg *= Math.pow(m.defense(), 0.5) + m.energy -= 0.9 * dmg / Math.sqrt(simulation.healScale) //scale damage with heal reduction difficulty + if (m.energy < 0 || isNaN(m.energy)) { //taking deadly damage + if (tech.isDeathAvoid && powerUps.research.count && !tech.isDeathAvoidedThisLevel) { + tech.isDeathAvoidedThisLevel = true + powerUps.research.changeRerolls(-1) + simulation.inGameConsole(`m.research--
${powerUps.research.count}`) + for (let i = 0; i < 22; i++) powerUps.spawn(m.pos.x + 100 * (Math.random() - 0.5), m.pos.y + 100 * (Math.random() - 0.5), "heal", false); + m.energy = m.maxEnergy + 0.1 + if (m.immuneCycle < m.cycle + 300) m.immuneCycle = m.cycle + 300 //disable this.immuneCycle bonus seconds + simulation.wipe = function () { //set wipe to have trails + ctx.fillStyle = "rgba(255,255,255,0.03)"; + ctx.fillRect(0, 0, canvas.width, canvas.height); + } + setTimeout(function () { + simulation.wipe = function () { //set wipe to normal + ctx.clearRect(0, 0, canvas.width, canvas.height); + } + }, 3000); + } else { //death + m.health = 0; + m.energy = 0; + m.death(); + } + return; + } + } else { + if (isDefense) dmg *= m.defense() + m.health -= dmg; + if (m.health < 0 || isNaN(m.health)) { + if (tech.isDeathAvoid && powerUps.research.count > 0 && !tech.isDeathAvoidedThisLevel) { //&& Math.random() < 0.5 + tech.isDeathAvoidedThisLevel = true + m.health = 0.05 + powerUps.research.changeRerolls(-1) + simulation.inGameConsole(`m.research--
${powerUps.research.count}`) + for (let i = 0; i < 16; i++) powerUps.spawn(m.pos.x + 100 * (Math.random() - 0.5), m.pos.y + 100 * (Math.random() - 0.5), "heal", false); + if (m.immuneCycle < m.cycle + 300) m.immuneCycle = m.cycle + 300 //disable this.immuneCycle bonus seconds + simulation.wipe = function () { //set wipe to have trails + ctx.fillStyle = "rgba(255,255,255,0.03)"; + ctx.fillRect(0, 0, canvas.width, canvas.height); + } + setTimeout(function () { + simulation.wipe = function () { //set wipe to normal + ctx.clearRect(0, 0, canvas.width, canvas.height); + } + }, 3000); + } else { + m.health = 0; + m.displayHealth(); + m.death(); + return; + } + } + m.displayHealth(); + document.getElementById("dmg").style.transition = "opacity 0s"; + document.getElementById("dmg").style.opacity = 0.1 + Math.min(0.6, dmg * 4); + } + if (dmg > 0.03) { + m.lastHit = dmg; + if (dmg > 0.06 / m.holdingMassScale) m.drop(); //drop block if holding // m.holdingMassScale = 0.5 for most fields + if (m.isCloak) m.fireCDcycle = m.cycle //forced exit cloak + } + const normalFPS = function () { + if (m.defaultFPSCycle < m.cycle) { //back to default values + simulation.fpsCap = simulation.fpsCapDefault + simulation.fpsInterval = 1000 / simulation.fpsCap; + document.getElementById("dmg").style.transition = "opacity 1s"; + document.getElementById("dmg").style.opacity = "0"; + } else { + requestAnimationFrame(normalFPS); + } + }; + + if (m.defaultFPSCycle < m.cycle) requestAnimationFrame(normalFPS); + if (dmg > 0.05) { // freeze game for high damage hits + simulation.fpsCap = 4 //40 - Math.min(25, 100 * dmg) + simulation.fpsInterval = 1000 / simulation.fpsCap; + if (tech.isHarmFreeze) { + for (let i = 0, len = mob.length; i < len; i++) mobs.statusSlow(mob[i], 480) //freeze all mobs + } + } else { + simulation.fpsCap = simulation.fpsCapDefault + simulation.fpsInterval = 1000 / simulation.fpsCap; + } + m.defaultFPSCycle = m.cycle + if (level.isMobHealPlayerDamage) { + for (let i = 0; i < mob.length; i++) { + if (mob[i].health < 1 && mob[i].isDropPowerUp && mob[i].alive) { + simulation.drawList.push({ + x: mob[i].position.x, + y: mob[i].position.y, + radius: mob[i].radius + 20, + color: "rgba(0,255,100,0.5)", + time: 10 + }); + mob[i].health += dmg * 7 + if (mob[i].health > 1) mob[i].health = 1 + } + } + } + // if (tech.isSlowFPS) { // slow game + // simulation.fpsCap = 30 //new fps + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // //how long to wait to return to normal fps + // m.defaultFPSCycle = m.cycle + 20 + Math.min(90, Math.floor(200 * dmg)) + // if (tech.isHarmFreeze) { //freeze all mobs + // for (let i = 0, len = mob.length; i < len; i++) { + // mobs.statusSlow(mob[i], 450) + // } + // } + // } else { + // if (dmg > 0.05) { // freeze game for high damage hits + // simulation.fpsCap = 4 //40 - Math.min(25, 100 * dmg) + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // } else { + // simulation.fpsCap = simulation.fpsCapDefault + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // } + // m.defaultFPSCycle = m.cycle + // } + // if (!noTransition) { + // document.getElementById("health").style.transition = "width 0s ease-out" + // } else { + // document.getElementById("health").style.transition = "width 1s ease-out" + // } + }, + buttonCD: 0, //cool down for player buttons + // ********************************************* + // ****** drawing player and skins ************* + // ********************************************* + drawLeg(stroke) { }, + calcLeg(cycle_offset, offset) { + m.hip.x = 12 + offset; + m.hip.y = 24 + offset; + //stepSize goes to zero if Vx is zero or not on ground (make m transition cleaner) + m.stepSize = 0.8 * m.stepSize + 0.2 * (7 * Math.sqrt(Math.min(9, Math.abs(m.Vx))) * m.onGround); + //changes to stepsize are smoothed by adding only a percent of the new value each cycle + const stepAngle = 0.034 * m.walk_cycle + cycle_offset; + m.foot.x = 2.2 * m.stepSize * Math.cos(stepAngle) + offset; + m.foot.y = offset + 1.2 * m.stepSize * Math.sin(stepAngle) + m.yOff + m.height; + const Ymax = m.yOff + m.height; + if (m.foot.y > Ymax) m.foot.y = Ymax; + + //calculate knee position as intersection of circle from hip and foot + const d = Math.sqrt((m.hip.x - m.foot.x) * (m.hip.x - m.foot.x) + (m.hip.y - m.foot.y) * (m.hip.y - m.foot.y)); + const l = (m.legLength1 * m.legLength1 - m.legLength2 * m.legLength2 + d * d) / (2 * d); + const h = Math.sqrt(m.legLength1 * m.legLength1 - l * l); + m.knee.x = (l / d) * (m.foot.x - m.hip.x) - (h / d) * (m.foot.y - m.hip.y) + m.hip.x + offset; + m.knee.y = (l / d) * (m.foot.y - m.hip.y) + (h / d) * (m.foot.x - m.hip.x) + m.hip.y; + }, + draw() { }, + isAltSkin: false, + drawBoost() { + + }, + resetSkin() { + simulation.isAutoZoom = true; + m.hardLandCDScale = 1 + m.yOffWhen.jump = 70 + m.yOffWhen.stand = 49 + m.yOffWhen.crouch = 22 + m.isAltSkin = false + m.coyoteCycles = 5 + m.hardLanding = 130 + m.squirrelFx = 1; + m.squirrelJump = 1; + m.velocitySmooth = { x: 0, y: 0 } + requestAnimationFrame(() => { m.setMovement() }) + m.color = { + hue: 0, + sat: 0, + light: 100, + } + m.setFillColors(); + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#4a4a4a"); + m.calcLeg(0, 0); + m.drawLeg("#333"); + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 5; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + if (m.onGround) { + ctx.lineTo(m.foot.x - 14, m.foot.y + 5); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 14, m.foot.y + 5); + } else { + ctx.lineTo(m.foot.x - 12, m.foot.y + 8); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 12, m.foot.y + 8); + } + ctx.lineWidth = 4; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 9, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 5, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 5, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 4, m.foot.y + 1); + ctx.arc(m.foot.x, m.foot.y + 1, 4, 0, 2 * Math.PI); + ctx.fillStyle = m.fillColor; + ctx.fill(); + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + } + }, + skin: { + none() { + m.isAltSkin = true + }, + favicon() { //used to render the favicon, not actually in game + m.yOffWhen.jump = 70 + m.yOffWhen.stand = 49 + m.yOffWhen.crouch = 22 + m.isAltSkin = false + + m.fillColor = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light}%)` + m.fillColorDark = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light - 10}%)` + let grd = ctx.createLinearGradient(-30, 0, 30, 0); + grd.addColorStop(0, m.fillColorDark); + grd.addColorStop(1, m.fillColor); + m.bodyGradient = grd + + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + // m.calcLeg(Math.PI, -3); + // m.drawLeg("#4a4a4a"); + // m.calcLeg(0, 0); + // m.drawLeg("#333"); + // ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(12, 0, 4.5, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 4.5; + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + }, + egg() { + m.isAltSkin = true + m.yOffWhen.stand = 52 + m.yOffWhen.jump = 72 + m.coyoteCycles = 11 + m.hardLandCDScale = 0.5 + m.hardLanding = 160 + m.squirrelFx = 1.4; + m.squirrelJump = 1.16; + m.setMovement() + + m.draw = function () { + if (powerUps.boost.endCycle > simulation.cycle) { + //gel that acts as if the wind is blowing it when player moves + ctx.save(); + ctx.translate(m.pos.x, m.pos.y); + m.velocitySmooth = Vector.add(Vector.mult(m.velocitySmooth, 0.8), Vector.mult(player.velocity, 0.2)) + ctx.rotate(Math.atan2(m.velocitySmooth.y, m.velocitySmooth.x)) + ctx.beginPath(); + const radius = 39 + const mag = 14 * Vector.magnitude(m.velocitySmooth) + radius + ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + ctx.bezierCurveTo(-radius, radius, -radius, 0, -mag, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + ctx.bezierCurveTo(-radius, 0, -radius, -radius, 0, -radius); + + // const time = (powerUps.boost.endCycle - m.cycle) / powerUps.boost.duration + const time = Math.min(0.5, (powerUps.boost.endCycle - simulation.cycle) / powerUps.boost.duration) + + ctx.fillStyle = `rgba(0,0,0,${0.04 + 0.3 * time})` + ctx.fill() + // ctx.strokeStyle = "#333" + // ctx.lineWidth = 1 + // ctx.stroke(); + ctx.restore(); + } + + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -1.25); + m.drawLeg("#606060"); + m.calcLeg(0, 0); + m.drawLeg("#444"); + + ctx.rotate(m.angle); + ctx.beginPath(); + // ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.ellipse(0, 0, 0.9 * 31, 1.05 * 31, 0, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + // ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.ellipse(15, 0, 0.8 * 4, 1.1 * 4, 0, 0, 2 * Math.PI); + + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.75 + m.yOffGoal * 0.25; //smoothly move leg height towards height goal + } + m.drawLeg = function (stroke) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + const hip = { x: m.hip.x - 5, y: m.hip.y + 5 } + const sub = Vector.sub(m.knee, hip) + const off = Vector.mult(Vector.rotate(Vector.normalise(sub), Math.PI / 2), 8) + const kneeBraceHigh = Vector.add(hip, off) + const kneeBraceLow = Vector.add(kneeBraceHigh, Vector.mult(sub, 0.9)) + const foot = { x: m.foot.x - 10, y: m.foot.y - 15 } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(hip.x, hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(foot.x, foot.y); + //extra upper leg brace + ctx.moveTo(kneeBraceHigh.x, kneeBraceHigh.y); + ctx.lineTo(kneeBraceLow.x, kneeBraceLow.y); + ctx.lineTo(m.knee.x, m.knee.y); + + ctx.strokeStyle = stroke; + ctx.lineWidth = 3; + ctx.stroke(); + //foot + ctx.beginPath(); + ctx.moveTo(foot.x, foot.y); + ctx.quadraticCurveTo(m.foot.x - 30, m.foot.y + 12, m.foot.x + 13, m.foot.y + 3); + ctx.lineWidth = 1.5; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y - 2, 11, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 3, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 3, 0, 2 * Math.PI); + //knee brace + // ctx.moveTo(kneeBraceHigh.x + 4, kneeBraceHigh.y); + // ctx.arc(kneeBraceHigh.x, kneeBraceHigh.y, 4, 0, 2 * Math.PI); + ctx.moveTo(kneeBraceLow.x + 2.5, kneeBraceLow.y); + ctx.arc(kneeBraceLow.x, kneeBraceLow.y, 2.5, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(foot.x + 2.5, foot.y); + ctx.arc(foot.x, foot.y, 2.5, 0, 2 * Math.PI); + ctx.fillStyle = "#f6f6f6"//m.fillColor; + ctx.fill(); + ctx.lineWidth = 1; + // ctx.strokeStyle = "#333" + ctx.stroke(); + ctx.restore(); + } + }, + mech() { + m.isAltSkin = true + m.yOffWhen.stand = 52 + m.yOffWhen.jump = 72 + m.coyoteCycles = 11 + m.hardLandCDScale = 0.5 + m.hardLanding = 160 + m.squirrelFx = 1.4; + m.squirrelJump = 1.16; + m.setMovement() + + m.draw = function () { + if (powerUps.boost.endCycle > simulation.cycle) { + //gel that acts as if the wind is blowing it when player moves + ctx.save(); + ctx.translate(m.pos.x, m.pos.y); + m.velocitySmooth = Vector.add(Vector.mult(m.velocitySmooth, 0.8), Vector.mult(player.velocity, 0.2)) + ctx.rotate(Math.atan2(m.velocitySmooth.y, m.velocitySmooth.x)) + ctx.beginPath(); + const radius = 39 + const mag = 14 * Vector.magnitude(m.velocitySmooth) + radius + ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + ctx.bezierCurveTo(-radius, radius, -radius, 0, -mag, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + ctx.bezierCurveTo(-radius, 0, -radius, -radius, 0, -radius); + + // const time = (powerUps.boost.endCycle - m.cycle) / powerUps.boost.duration + const time = Math.min(0.5, (powerUps.boost.endCycle - simulation.cycle) / powerUps.boost.duration) + + ctx.fillStyle = `rgba(0,0,0,${0.04 + 0.3 * time})` + ctx.fill() + // ctx.strokeStyle = "#333" + // ctx.lineWidth = 1 + // ctx.stroke(); + ctx.restore(); + } + + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -1.25); + m.drawLeg("#606060"); + m.calcLeg(0, 0); + m.drawLeg("#444"); + + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.75 + m.yOffGoal * 0.25; //smoothly move leg height towards height goal + } + m.drawLeg = function (stroke) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + const hip = { x: m.hip.x - 5, y: m.hip.y + 5 } + const sub = Vector.sub(m.knee, hip) + const off = Vector.mult(Vector.rotate(Vector.normalise(sub), Math.PI / 2), 8) + const kneeBraceHigh = Vector.add(hip, off) + const kneeBraceLow = Vector.add(kneeBraceHigh, Vector.mult(sub, 0.9)) + const foot = { x: m.foot.x - 10, y: m.foot.y - 15 } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(hip.x, hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(foot.x, foot.y); + //extra upper leg brace + ctx.moveTo(kneeBraceHigh.x, kneeBraceHigh.y); + ctx.lineTo(kneeBraceLow.x, kneeBraceLow.y); + ctx.lineTo(m.knee.x, m.knee.y); + + ctx.strokeStyle = stroke; + ctx.lineWidth = 3; + ctx.stroke(); + //foot + ctx.beginPath(); + ctx.moveTo(foot.x, foot.y); + ctx.quadraticCurveTo(m.foot.x - 30, m.foot.y + 12, m.foot.x + 13, m.foot.y + 3); + ctx.lineWidth = 1.5; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y - 1, 11, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 3, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 3, 0, 2 * Math.PI); + //knee brace + // ctx.moveTo(kneeBraceHigh.x + 4, kneeBraceHigh.y); + // ctx.arc(kneeBraceHigh.x, kneeBraceHigh.y, 4, 0, 2 * Math.PI); + ctx.moveTo(kneeBraceLow.x + 2.5, kneeBraceLow.y); + ctx.arc(kneeBraceLow.x, kneeBraceLow.y, 2.5, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(foot.x + 2.5, foot.y); + ctx.arc(foot.x, foot.y, 2.5, 0, 2 * Math.PI); + ctx.fillStyle = m.fillColor; + ctx.fill(); + ctx.lineWidth = 1; + // ctx.strokeStyle = "#333" + ctx.stroke(); + ctx.restore(); + } + }, + polar() { + m.isAltSkin = true + // m.setFillColors(); + m.fillColor = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light}%)` + m.fillColorDark = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light - 35}%)` + let grd = ctx.createLinearGradient(-30, 0, 30, 0); + grd.addColorStop(0, m.fillColorDark); + grd.addColorStop(0.7, m.fillColor); + // grd.addColorStop(1, m.fillColor); + m.bodyGradient = grd + + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + + const diff = (m.lastKillCycle - m.cycle + tech.isDamageCooldownTime) / tech.isDamageCooldownTime + const color = diff < 0 ? "#fff" : "#aaa" + const hue = 220 + 20 * Math.sin(0.01 * m.cycle) + const colorInverse = diff < 0 ? `hsl(${hue}, 80%, 40%)` : "#fff" + m.drawLeg(color, colorInverse); + m.calcLeg(0, 0); + m.drawLeg(color, colorInverse); + + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = color + ctx.fill(); + + ctx.beginPath(); + ctx.moveTo(15, 0) + ctx.lineTo(28, 0) + ctx.strokeStyle = colorInverse; + ctx.lineWidth = 4; + ctx.stroke(); + ctx.restore(); + + ctx.beginPath(); + ctx.ellipse(m.pos.x, m.pos.y, 24, 18, 3.14 * Math.random(), 0, 2 * Math.PI) + ctx.fillStyle = diff < 0 ? `hsl(${hue}, 80%, 40%)` : `rgba(255,255,255,${Math.min(Math.max(0, diff + 0.3), 1)})` + ctx.fill(); + + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + m.drawLeg = function (stroke, circles) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 5; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + if (m.onGround) { + ctx.lineTo(m.foot.x - 15, m.foot.y + 5); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 15, m.foot.y + 5); + } else { + ctx.lineTo(m.foot.x - 13, m.foot.y + 8); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 13, m.foot.y + 8); + } + ctx.lineWidth = 3; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 11, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 5, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 5, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 5, m.foot.y); + ctx.arc(m.foot.x, m.foot.y, 5, 0, 2 * Math.PI); + ctx.fillStyle = circles; + ctx.fill(); + // ctx.lineWidth = 2; + // ctx.stroke(); + ctx.restore(); + } + }, + strokeGap() { + m.isAltSkin = true + m.yOffWhen.stand = 52 + m.yOffWhen.jump = 72 + // m.speedSmooth = 0 + // m.smoothAngle = 0 + m.draw = function () { + if (powerUps.boost.endCycle > simulation.cycle) { + //gel that acts as if the wind is blowing it when player moves + ctx.save(); + ctx.translate(m.pos.x, m.pos.y); + m.velocitySmooth = Vector.add(Vector.mult(m.velocitySmooth, 0.8), Vector.mult(player.velocity, 0.2)) + ctx.rotate(Math.atan2(m.velocitySmooth.y, m.velocitySmooth.x)) + ctx.beginPath(); + const radius = 40 + const mag = 9 * Vector.magnitude(m.velocitySmooth) + radius + ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + ctx.bezierCurveTo(-radius, radius, -radius, 0, -mag, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + ctx.bezierCurveTo(-radius, 0, -radius, -radius, 0, -radius); + + // const time = (powerUps.boost.endCycle - m.cycle) / powerUps.boost.duration + const time = Math.min(0.5, (powerUps.boost.endCycle - simulation.cycle) / powerUps.boost.duration) + + // ctx.fillStyle = `rgba(255,0,200,${0.4 * time})` + // ctx.fill() + // ctx.strokeStyle = "#f09" + + ctx.fillStyle = `rgba(255,255,255,${0.3 + time})`; + ctx.fill() + ctx.strokeStyle = "#446" + ctx.lineWidth = 0.2 + 4 * time + // ctx.lineWidth = 1 + ctx.stroke(); + ctx.restore(); + } + + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -1.25); + m.drawLeg("#606080"); + m.calcLeg(0, 0); + m.drawLeg("#446"); + + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + // ctx.arc(0, 0, 30, m.angle + 1, m.angle - 1); + ctx.fillStyle = "#fff"//m.bodyGradient + ctx.fill(); + ctx.beginPath(); + const arc = 0.7 + 0.17 * Math.sin(m.cycle * 0.012) + ctx.arc(0, 0, 30, -arc, arc, true); //- Math.PI / 2 + ctx.strokeStyle = "#446"; + ctx.lineWidth = 2; + ctx.stroke(); + + //fire outline directed opposite player look direction + // ctx.beginPath(); + // const radius = 40 + // const extend = -50 + // ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + // ctx.bezierCurveTo(extend, radius, extend, 0, -100, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + // ctx.bezierCurveTo(extend, 0, extend, -radius, 0, -radius); + // ctx.fillStyle = "rgba(255,0,255,0.3)"; + // ctx.fill() + ctx.beginPath(); + ctx.moveTo(13, 0) + ctx.lineTo(20, 0) + ctx.lineWidth = 5; + ctx.stroke(); + + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 5; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + if (m.onGround) { + ctx.lineTo(m.foot.x - 14, m.foot.y + 5); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 14, m.foot.y + 5); + } else { + ctx.lineTo(m.foot.x - 12, m.foot.y + 8); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 12, m.foot.y + 8); + } + ctx.lineWidth = 4; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 8, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 4, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 4, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 4, m.foot.y + 1); + ctx.arc(m.foot.x, m.foot.y + 1, 4, 0, 2 * Math.PI); + ctx.fillStyle = m.fillColor; + ctx.fill(); + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + } + }, + energy() { + m.isAltSkin = true + m.color = { + hue: 184, + sat: 100, + light: 85, + } + m.setFillColors(); + m.draw = function () { + if (powerUps.boost.endCycle > simulation.cycle) { + //gel that acts as if the wind is blowing it when player moves + ctx.save(); + ctx.translate(m.pos.x, m.pos.y); + m.velocitySmooth = Vector.add(Vector.mult(m.velocitySmooth, 0.8), Vector.mult(player.velocity, 0.2)) + ctx.rotate(Math.atan2(m.velocitySmooth.y, m.velocitySmooth.x)) + ctx.beginPath(); + const radius = 40 + const mag = 10 * Vector.magnitude(m.velocitySmooth) + radius + ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + ctx.bezierCurveTo(-radius, radius, -radius, 0, -mag, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + ctx.bezierCurveTo(-radius, 0, -radius, -radius, 0, -radius); + + // const time = (powerUps.boost.endCycle - m.cycle) / powerUps.boost.duration + const time = Math.min(0.5, (powerUps.boost.endCycle - simulation.cycle) / powerUps.boost.duration) + + ctx.fillStyle = `hsla(184,100%,70%,${0.1 + 1.5 * time})` + ctx.fill() + ctx.strokeStyle = "#035"//"hsl(184,100%,70%)" + ctx.lineWidth = 0.2 + 3 * time + ctx.stroke(); + ctx.restore(); + } + + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#456"); + m.calcLeg(0, 0); + m.drawLeg("#345"); + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.strokeStyle = "rgba(0,255,255,0.25)"; + ctx.lineWidth = 15; + ctx.stroke(); + ctx.fillStyle = 'hsl(184,100%,85%)' //m.fillColor; //"#9ff" //m.bodyGradient + ctx.fill(); + + ctx.beginPath(); + ctx.arc(17, 0, 5.5, 0, 2 * Math.PI); + ctx.fillStyle = "#357" + ctx.fill(); + ctx.restore(); + + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 5; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + if (m.onGround) { + ctx.lineTo(m.foot.x - 15, m.foot.y + 5); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 15, m.foot.y + 5); + } else { + ctx.lineTo(m.foot.x - 13, m.foot.y + 8); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 13, m.foot.y + 8); + } + ctx.lineWidth = 3; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 10, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 6, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 6, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 5, m.foot.y); + ctx.arc(m.foot.x, m.foot.y + 1, 5, 0, 2 * Math.PI); + ctx.strokeStyle = "rgba(0,255,255,0.25)"; + ctx.lineWidth = 6; + ctx.stroke(); + ctx.fillStyle = m.fillColor; + ctx.fill(); + ctx.restore(); + } + }, + tungsten() { + m.hardLandCDScale = 2 + m.hardLanding = 60 + // m.coyoteCycles = 0 + m.isAltSkin = true + m.color = { + hue: 210, + sat: 5, + light: 75, + } + // m.setFillColors(); + m.fillColor = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light}%)` + m.fillColorDark = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light - 50}%)` + const grd = ctx.createLinearGradient(-30, -5, 30, 10); + grd.addColorStop(0, `#e0e0e0`); + grd.addColorStop(0.3, `#bbb`); + grd.addColorStop(0.4, `#b3b3b3`); + grd.addColorStop(0.5, `#c5c5c5`); + grd.addColorStop(0.65, `#bbb`); + grd.addColorStop(0.7, `#b3b3b3`); + grd.addColorStop(0.75, `#bbb`); + grd.addColorStop(1, `#e0e0e0`); + // const grdRad = ctx.createRadialGradient(0, 0, 0, 0, 0, 30); + // grdRad.addColorStop(0, `rgba(0,0,0,0.3)`); + // grdRad.addColorStop(0.5, `rgba(210,210,210,0)`); + m.bodyGradient = grd + + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(4.2, -3); + m.drawLeg("#666"); + m.calcLeg(2.1, -1); + m.drawLeg("#5f5f5f"); + m.calcLeg(0, 1); + m.drawLeg("#555"); + ctx.rotate(m.angle); + + const size = 33 + ctx.beginPath(); + ctx.lineTo(size * 1, size * 0) + ctx.lineTo(size * 0.5, size * 0.866) + ctx.lineTo(size * -0.5, size * 0.866) + ctx.lineTo(size * -1, size * 0) + ctx.lineTo(size * -0.5, size * -0.866) + ctx.lineTo(size * 0.5, size * -0.866) + ctx.lineTo(size * 1, size * 0) + ctx.lineTo(size * 0.5, size * 0) + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 1.5; + ctx.stroke(); + + ctx.beginPath(); + ctx.arc(15, 0, 3, 0, 2 * Math.PI); + ctx.fillStyle = "#333" + ctx.fill(); + + ctx.restore(); + m.yOff = m.yOff * 0.9 + m.yOffGoal * 0.1; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 4.5; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y - 1); + ctx.lineTo(m.foot.x - 15, m.foot.y + 5); + ctx.lineTo(m.foot.x + 15, m.foot.y + 5); + ctx.lineTo(m.foot.x, m.foot.y - 1); + ctx.lineWidth = 4; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y - 4, 12, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 6, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 6, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 5, m.foot.y); + ctx.arc(m.foot.x, m.foot.y, 5, 0, 2 * Math.PI); + ctx.fillStyle = m.fillColor; + ctx.fill(); + ctx.lineWidth = 1; + ctx.strokeStyle = "#000" + ctx.stroke(); + ctx.restore(); + } + + }, + anodize() { + m.isAltSkin = true + m.color = { + hue: 210, + sat: 14, + light: 65, + } + m.fillColor = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light}%)` + m.fillColorDark = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light - 50}%)` + const grd = ctx.createRadialGradient(16, 0, 0, 0, 0, 40); + grd.addColorStop(0, `#c78034`); + grd.addColorStop(0.04, `#bd5235`); + grd.addColorStop(0.08, `#ab554d`); + grd.addColorStop(0.12, `#8f5d8f`); + grd.addColorStop(0.16, `#4352ab`); + grd.addColorStop(0.2, `#2058b3`); + grd.addColorStop(0.24, `#1a6fc4`); + grd.addColorStop(0.28, `#1b85cf`); + grd.addColorStop(0.32, `#2d9bd7`); + grd.addColorStop(0.4, `#d2d7b4`); + grd.addColorStop(0.44, `#e1cd87`); + grd.addColorStop(0.48, `#f0b955`); + grd.addColorStop(0.52, `#ffa050`); + grd.addColorStop(0.56, `#ff8269`); + grd.addColorStop(0.6, `#f5697d`); + grd.addColorStop(0.64, `#e65aaf`); + grd.addColorStop(0.68, `#d732d7`); + grd.addColorStop(0.72, `#c846e6`); + grd.addColorStop(0.76, `#c850fa`); + grd.addColorStop(0.8, `#878cf0`); + grd.addColorStop(0.84, `#37beeb`); + grd.addColorStop(0.88, `#00d2be`); + grd.addColorStop(0.92, `#00e19b`); + grd.addColorStop(0.96, `#19f5aa`); + grd.addColorStop(1, `#aaf5af`); + m.bodyGradient = grd + + m.draw = function () { + if (powerUps.boost.endCycle > simulation.cycle) { + //gel that acts as if the wind is blowing it when player moves + ctx.save(); + ctx.translate(m.pos.x, m.pos.y); + m.velocitySmooth = Vector.add(Vector.mult(m.velocitySmooth, 0.8), Vector.mult(player.velocity, 0.2)) + ctx.rotate(Math.atan2(m.velocitySmooth.y, m.velocitySmooth.x)) + ctx.beginPath(); + const radius = 40 + const mag = 12 * Vector.magnitude(m.velocitySmooth) + radius + ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + ctx.bezierCurveTo(-radius, radius, -radius, 0, -mag, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + ctx.bezierCurveTo(-radius, 0, -radius, -radius, 0, -radius); + // const time = (powerUps.boost.endCycle - m.cycle) / powerUps.boost.duration + const time = Math.min(0.5, (powerUps.boost.endCycle - simulation.cycle) / powerUps.boost.duration) + + ctx.fillStyle = `hsla(${simulation.cycle},100%,70%,${0.1 + 2 * time})` + ctx.fill() + ctx.restore(); + } + + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#4a4a5a"); + m.calcLeg(0, 0); + m.drawLeg("#445"); + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + // ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#222"; + ctx.lineWidth = 2; + // ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 5; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + if (m.onGround) { + ctx.lineTo(m.foot.x - 15, m.foot.y + 5); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 15, m.foot.y + 5); + } else { + ctx.lineTo(m.foot.x - 13, m.foot.y + 8); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 13, m.foot.y + 8); + } + ctx.lineWidth = 4; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 9, 0, 2 * Math.PI); + ctx.fillStyle = "#222"; + ctx.fill(); + //knee joint + ctx.beginPath(); + ctx.arc(m.knee.x, m.knee.y, 5, 0, 2 * Math.PI); + ctx.fill(); + //foot joint + ctx.beginPath(); + ctx.arc(m.foot.x, m.foot.y, 4, 0, 2 * Math.PI); + ctx.fill(); + ctx.restore(); + } + }, + dilate() { + m.isAltSkin = true + simulation.isAutoZoom = false; + m.draw = function () { + const amplitude = 8 + 4 * Math.sin(m.cycle * 0.01) + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#456"); + m.calcLeg(0, 0); + m.drawLeg("#345"); + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.strokeStyle = "#345"; + ctx.lineWidth = 2; + ctx.arc(12, 0, amplitude, 0, 2 * Math.PI); //big eye + ctx.stroke(); + ctx.beginPath(); + ctx.arc(12, 0, amplitude, 0, 2 * Math.PI); //big eye + // ctx.fillStyle = `hsl(0,0%,${50+50*Math.sin(m.cycle * 0.0075+Math.PI)}%)` //`hsl(${150+50*Math.sin(m.cycle * 0.0075)},100%,50%)` + // ctx.fill(); + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + + if (powerUps.boost.endCycle > simulation.cycle) { + //gel that acts as if the wind is blowing it when player moves + ctx.save(); + ctx.translate(m.pos.x, m.pos.y); + m.velocitySmooth = Vector.add(Vector.mult(m.velocitySmooth, 0.8), Vector.mult(player.velocity, 0.2)) + ctx.rotate(Math.atan2(m.velocitySmooth.y, m.velocitySmooth.x)) + ctx.beginPath(); + const radius = 39 + const mag = 6 * Vector.magnitude(m.velocitySmooth) + radius + ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + ctx.bezierCurveTo(-radius, radius, -radius, 0, -mag, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + ctx.bezierCurveTo(-radius, 0, -radius, -radius, 0, -radius); + // ctx.fillStyle = `hsla(${simulation.cycle * 0.5},100%,70%,0.4)` + // ctx.fill() + ctx.strokeStyle = "#345" + // const time = (powerUps.boost.endCycle - m.cycle) / powerUps.boost.duration + const time = Math.min(0.5, (powerUps.boost.endCycle - simulation.cycle) / powerUps.boost.duration) + + ctx.lineWidth = 0.2 + 4 * time + ctx.stroke(); + ctx.restore(); + } + + //zoom camera in and out + simulation.setZoom(1800 + 400 * Math.sin(m.cycle * 0.01)) + } + }, + dilate2() { + m.isAltSkin = true + m.draw = function () { + const amplitude = Math.sin(m.cycle * 0.01) + + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#456"); + m.calcLeg(0, 0); + m.drawLeg("#345"); + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.strokeStyle = "#345"; + ctx.lineWidth = 3 + 3 * Math.sin(m.cycle * 0.01 + Math.PI); + ctx.stroke(); + // ctx.arc(12, 0, 8 + 4 * amplitude, 0, 2 * Math.PI); //big eye + ctx.beginPath(); + ctx.arc(12, 0, 8 + 4 * amplitude, 0, 2 * Math.PI); //big eye + ctx.fillStyle = "#345" + // ctx.fillStyle = //`hsl(0,0%,${50+50*Math.sin(m.cycle * 0.0075+Math.PI)}%)` //`hsl(${150+50*Math.sin(m.cycle * 0.0075)},100%,50%)` + // ctx.fillStyle = `hsl(${150 + 100 * amplitude},100%,50%)` + ctx.fill(); + // ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + + if (powerUps.boost.endCycle > simulation.cycle) { + //gel that acts as if the wind is blowing it when player moves + ctx.save(); + ctx.translate(m.pos.x, m.pos.y); + m.velocitySmooth = Vector.add(Vector.mult(m.velocitySmooth, 0.8), Vector.mult(player.velocity, 0.2)) + ctx.rotate(Math.atan2(m.velocitySmooth.y, m.velocitySmooth.x)) + ctx.beginPath(); + const radius = 39 + const mag = 6 * Vector.magnitude(m.velocitySmooth) + radius + ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + ctx.bezierCurveTo(-radius, radius, -radius, 0, -mag, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + ctx.bezierCurveTo(-radius, 0, -radius, -radius, 0, -radius); + // ctx.fillStyle = `hsla(${simulation.cycle * 0.5},100%,70%,0.4)` + // ctx.fill() + const time = Math.min(0.5, (powerUps.boost.endCycle - simulation.cycle) / powerUps.boost.duration) + + ctx.strokeStyle = "#345" + ctx.lineWidth = 0.2 + 7 * time + // ctx.lineWidth = (4 + 3 * Math.sin(m.cycle * 0.01 + Math.PI)) * time; + ctx.stroke(); + ctx.restore(); + } + + simulation.setZoom(1800 + 400 * amplitude) + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 6 + 2 * Math.sin(m.cycle * 0.01 + Math.PI); + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + if (m.onGround) { + ctx.lineTo(m.foot.x - 15, m.foot.y + 5); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 15, m.foot.y + 5); + } else { + ctx.lineTo(m.foot.x - 13, m.foot.y + 8); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 13, m.foot.y + 8); + } + ctx.lineWidth = 4; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 11, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 7, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 7, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 6, m.foot.y); + ctx.arc(m.foot.x, m.foot.y, 6, 0, 2 * Math.PI); + ctx.fillStyle = "#345"; + ctx.fill(); + ctx.lineWidth = 3 + 3 * Math.sin(m.cycle * 0.01 + Math.PI); + ctx.stroke(); + ctx.restore(); + } + }, + CPT() { + m.isAltSkin = true + + m.fillColor = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light}%)` + m.fillColorDark = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light - 35}%)` + let grd = ctx.createLinearGradient(-20, 0, 15, 0); + grd.addColorStop(0, m.fillColorDark); + grd.addColorStop(1, m.fillColor); + // grd.addColorStop(1, m.fillColor); + m.bodyGradient = grd + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#eee"); + m.calcLeg(0, 0); + m.drawLeg("#fff"); + + ctx.rotate(0.024 * simulation.cycle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.energy > 0.85 * Math.min(1, m.maxEnergy) ? m.bodyGradient : "#fff" + ctx.fill(); + ctx.restore(); + + ctx.beginPath(); + ctx.arc(m.pos.x + 15 * Math.cos(m.angle), m.pos.y + 15 * Math.sin(m.angle), 5, 0, 2 * Math.PI); + ctx.fillStyle = "#000" + ctx.fill(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 5; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + if (m.onGround) { + ctx.lineTo(m.foot.x - 15, m.foot.y + 5); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 15, m.foot.y + 5); + } else { + ctx.lineTo(m.foot.x - 13, m.foot.y + 8); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 13, m.foot.y + 8); + } + ctx.lineWidth = 3; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 11, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 5, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 5, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 5, m.foot.y); + ctx.arc(m.foot.x, m.foot.y, 5, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + // ctx.lineWidth = 2; + // ctx.stroke(); + ctx.restore(); + } + }, + verlet() { + m.isAltSkin = true + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -2); + m.drawLeg("#4a4a4a"); + m.calcLeg(0, 0); + m.drawLeg("#333"); + + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + const rate = 0.09 + ctx.strokeStyle = "#000"; + ctx.lineWidth = 1; + ctx.beginPath(); + ctx.arc(0, 0, rate * (simulation.cycle + 0) % 30, 0, 2 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(0, 0, rate * (simulation.cycle + 15 / rate) % 30, 0, 2 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.stroke(); + + ctx.globalCompositeOperation = "difference"; + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(21, 0, 8, 0, 2 * Math.PI); + ctx.fillStyle = input.fire ? "#0ff" : input.field ? "#d30" : `#fff` + ctx.fill(); + ctx.restore(); + + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 1; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + const footDrop = m.onGround ? 5 : 10 + ctx.lineTo(m.foot.x - 15, m.foot.y + footDrop); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 15, m.foot.y + footDrop); + ctx.lineWidth = 1; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 9, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 5, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 3, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 5, m.foot.y); + ctx.arc(m.foot.x, m.foot.y, 4, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + // ctx.lineWidth = 2; + // ctx.stroke(); + ctx.restore(); + } + }, + stubs() { + m.isAltSkin = true + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#555"); + m.calcLeg(0, 0); + m.drawLeg("#333"); + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y + 5); + ctx.strokeStyle = stroke; + ctx.lineWidth = 6; + ctx.stroke(); + ctx.restore(); + } + }, + Sleipnir() { + m.isAltSkin = true + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 + ctx.translate(m.pos.x, m.pos.y); + for (let i = 0; i < 16; i++) { + m.calcLeg(Math.PI * i / 8, -3 * i / 16) + m.drawLeg("#444") + } + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + }, + diegesis() { + m.isAltSkin = true + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#4a4a4a"); + m.calcLeg(0, 0); + m.drawLeg("#333"); + ctx.rotate(m.angle - (m.fireCDcycle !== Infinity ? m.flipLegs * 0.25 * Math.pow(Math.max(m.fireCDcycle - m.cycle, 0), 0.5) : 0)); + + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + }, + cat() { + m.isAltSkin = true + m.coyoteCycles = 10 + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#4a4a4a"); + if (!(m.angle > -Math.PI / 2 && m.angle < Math.PI / 2)) { + ctx.scale(1, -1); + ctx.rotate(Math.PI); + } + ctx.beginPath(); + ctx.moveTo(-30, 0); + ctx.bezierCurveTo(-65, -75, + -5, 150 + (5 * Math.sin(simulation.cycle / 10)), + -70 + (10 * Math.sin(simulation.cycle / 10)), 0 + (10 * Math.sin(simulation.cycle / 10))); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 4; + ctx.stroke(); + + if (!(m.angle > -Math.PI / 2 && m.angle < Math.PI / 2)) { + ctx.scale(1, -1); + ctx.rotate(0 - Math.PI); + } + m.calcLeg(0, 0); + m.drawLeg("#333"); + + ctx.rotate(m.angle); + if (!(m.angle > -Math.PI / 2 && m.angle < Math.PI / 2)) ctx.scale(1, -1); + ctx.beginPath(); + ctx.moveTo(5, -30); + ctx.lineTo(20, -40); + ctx.lineTo(20, -20); + ctx.lineWidth = 2; + ctx.fillStyle = "#f3f"; + ctx.fill(); + ctx.stroke(); + + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.stroke(); + ctx.moveTo(19, 0); + ctx.arc(15, 0, 4, Math.PI, 2 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(24.3, 6, 5, Math.PI * 2, Math.PI); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(30, 6); + ctx.lineTo(32, 0); + ctx.lineTo(26, 0); + ctx.lineTo(30, 6); + ctx.fillStyle = "#f3f"; + ctx.fill(); + ctx.stroke(); + + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + }, + pareidolia() { + m.isAltSkin = true + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.7 + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#4a4a4a"); + m.calcLeg(0, 0); + m.drawLeg("#333"); + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + if (!(m.angle > -Math.PI / 2 && m.angle < Math.PI / 2)) ctx.scale(1, -1); //here is the flip + ctx.stroke(); + ctx.beginPath(); + ctx.arc(2, -6, 7, 0, 2 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(25, -6, 7, 0.25 * Math.PI, 1.6 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(2, -10, 9, 1.25 * Math.PI, 1.75 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(25, -10, 9, 1.25 * Math.PI, 1.4 * Math.PI); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(18, 13, 10, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient; + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(18, 13, 6, 0, 2 * Math.PI); + ctx.fillStyle = "#555"; + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(3, -6, 3, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(26, -6, 3, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; + powerUps.boost.draw() + } + }, + flipFlop() { + m.isAltSkin = true + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + + //draw body + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 + ctx.translate(m.pos.x, m.pos.y); + + m.calcLeg(Math.PI, -3); + m.drawLeg("#4a4a4a"); + m.calcLeg(0, 0); + m.drawLeg("#333"); + + ctx.rotate(m.angle); + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + //draw eye + ctx.beginPath(); + ctx.arc(15, 0, 3.5, 0, 2 * Math.PI); + ctx.fillStyle = m.eyeFillColor; + ctx.fill() + ctx.restore(); + + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + }, + hexagon() { + m.isAltSkin = true + + m.fillColor = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light}%)` + m.fillColorDark = `hsl(${m.color.hue},${m.color.sat}%,${m.color.light - 35}%)` + let grd = ctx.createLinearGradient(-30, 0, 30, 0); + grd.addColorStop(0, m.fillColorDark); + grd.addColorStop(0.7, m.fillColor); + // grd.addColorStop(1, m.fillColor); + m.bodyGradient = grd + + m.draw = function () { + ctx.fillStyle = m.fillColor; + m.walk_cycle += m.flipLegs * m.Vx; + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 //|| (m.cycle % 40 > 20) + ctx.translate(m.pos.x, m.pos.y); + m.calcLeg(Math.PI, -3); + m.drawLeg("#4a4a4a"); + m.calcLeg(0, 0); + m.drawLeg("#333"); + ctx.rotate(m.angle); + + const size = 32 + ctx.beginPath(); + ctx.lineTo(size * 1, size * 0) + ctx.lineTo(size * 0.5, size * 0.866) + ctx.lineTo(size * -0.5, size * 0.866) + ctx.lineTo(size * -1, size * 0) + ctx.lineTo(size * -0.5, size * -0.866) + ctx.lineTo(size * 0.5, size * -0.866) + ctx.lineTo(size * 1, size * 0) + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + ctx.restore(); + m.yOff = m.yOff * 0.85 + m.yOffGoal * 0.15; //smoothly move leg height towards height goal + powerUps.boost.draw() + } + m.drawLeg = function (stroke) { + // if (simulation.mouseInGame.x > m.pos.x) { + if (m.angle > -Math.PI / 2 && m.angle < Math.PI / 2) { + m.flipLegs = 1; + } else { + m.flipLegs = -1; + } + ctx.save(); + ctx.scale(m.flipLegs, 1); //leg lines + ctx.beginPath(); + ctx.moveTo(m.hip.x, m.hip.y); + ctx.lineTo(m.knee.x, m.knee.y); + ctx.lineTo(m.foot.x, m.foot.y); + ctx.strokeStyle = stroke; + ctx.lineWidth = 6; + ctx.stroke(); + + //toe lines + ctx.beginPath(); + ctx.moveTo(m.foot.x, m.foot.y); + if (m.onGround) { + ctx.lineTo(m.foot.x - 15, m.foot.y + 5); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 15, m.foot.y + 5); + } else { + ctx.lineTo(m.foot.x - 13, m.foot.y + 8); + ctx.moveTo(m.foot.x, m.foot.y); + ctx.lineTo(m.foot.x + 13, m.foot.y + 8); + } + ctx.lineWidth = 3; + ctx.stroke(); + + //hip joint + ctx.beginPath(); + ctx.arc(m.hip.x, m.hip.y, 11, 0, 2 * Math.PI); + //knee joint + ctx.moveTo(m.knee.x + 5, m.knee.y); + ctx.arc(m.knee.x, m.knee.y, 5, 0, 2 * Math.PI); + //foot joint + ctx.moveTo(m.foot.x + 5, m.foot.y); + ctx.arc(m.foot.x, m.foot.y, 5, 0, 2 * Math.PI); + ctx.fillStyle = "#000"; + ctx.fill(); + // ctx.lineWidth = 2; + // ctx.stroke(); + ctx.restore(); + } + }, + }, + // ********************************************* + // **************** fields ********************* + // ********************************************* + closest: { + dist: 1000, + index: 0 + }, + isHolding: false, + isCloak: false, + throwCharge: 0, + fireCDcycle: 0, + fieldCDcycle: 0, + fieldMode: 0, //basic field mode before upgrades + maxEnergy: 1, //can be increased by a tech + holdingTarget: null, + timeSkipLastCycle: 0, + coupling: 0, + // these values are set on reset by setHoldDefaults() + fieldFx: 1, + fieldJump: 1, + blockingRecoil: 4, + grabPowerUpRange2: 0, + isFieldActive: false, + fieldRange: 155, + fieldShieldingScale: 1, + fieldDamage: 1, + isSneakAttack: false, + lastHit: 0, //stores value of last damage player took above a threshold, in m.damage + sneakAttackCycle: 0, + enterCloakCycle: 0, + duplicateChance: 0, + energy: 0, + fieldRegen: 0.001, + fieldMode: 0, + fieldFire: false, + fieldHarmReduction: 1, + holdingMassScale: 0, + hole: { + isOn: false, + isReady: false, + pos1: { x: 0, y: 0 }, + pos2: { x: 0, y: 0 }, + }, + fieldArc: 0, + fieldThreshold: 0, + calculateFieldThreshold() { + m.fieldThreshold = Math.cos((m.fieldArc) * Math.PI) + }, + setHoldDefaults() { + if (tech.isFreeWormHole && m.fieldMode !== 9) { //not wormhole + const removed = tech.removeTech("charmed baryon") //neutronum can get player stuck so it has to be removed if player has wrong field + if (removed) powerUps.directSpawn(m.pos.x, m.pos.y, "tech"); + } + if (tech.isNeutronium && m.fieldMode !== 3) { //not negative mass field + const removed = tech.removeTech("neutronium") //neutronum can get player stuck so it has to be removed if player has wrong field + if (removed) powerUps.directSpawn(m.pos.x, m.pos.y, "tech"); + } + if (m.energy < m.maxEnergy) m.energy = m.maxEnergy; + m.fieldMeterColor = "#0cf" + m.eyeFillColor = m.fieldMeterColor + m.fieldShieldingScale = 1; + m.fieldBlockCD = 10; + m.fieldDamage = 1 + m.fieldHarmReduction = 1; + m.isSneakAttack = false + m.duplicateChance = 0 + m.grabPowerUpRange2 = 200000; + m.blockingRecoil = 4; + m.fieldRange = 155; + m.fieldFire = false; + m.fieldCDcycle = 0; + m.isCloak = false; + player.collisionFilter.mask = cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield + m.airSpeedLimit = 125 + m.fieldFx = 1 + m.fieldJump = 1 + m.setFieldRegen(); + m.setMovement(); + m.drop(); + m.holdingMassScale = 0.5; + m.fieldArc = 0.2; //run calculateFieldThreshold after setting fieldArc, used for powerUp grab and mobPush with lookingAt(mob) + m.calculateFieldThreshold(); //run calculateFieldThreshold after setting fieldArc, used for powerUp grab and mobPush with lookingAt(mob) + m.isTimeDilated = true; + m.wakeCheck(); + m.setMaxEnergy(false); + m.setMaxHealth(false); + m.couplingChange() + m.hole = { + isOn: false, + isReady: false, + pos1: { x: 0, y: 0 }, + pos2: { x: 0, y: 0 }, + } + }, + setMaxEnergy(isMessage = true) { + m.maxEnergy = (tech.isMaxEnergyTech ? 0.5 : 1) + tech.bonusEnergy + tech.healMaxEnergyBonus + tech.harmonicEnergy + 3 * tech.isGroundState + 1.5 * (m.fieldMode === 1) + (m.fieldMode === 0 || m.fieldMode === 1) * 0.05 * m.coupling + 0.77 * tech.isStandingWaveExpand + if (level.isReducedEnergy) m.maxEnergy *= 0.5 + if (isMessage) simulation.inGameConsole(`m.maxEnergy = ${(m.maxEnergy.toFixed(2))}`) + }, + fieldMeterColor: "#0cf", + drawRegenEnergy(bgColor = "rgba(0, 0, 0, 0.4)", range = 60) { + if (m.energy < m.maxEnergy) { + m.regenEnergy(); + ctx.fillStyle = bgColor; + const xOff = m.pos.x - m.radius * m.maxEnergy + const yOff = m.pos.y - 50 + ctx.fillRect(xOff, yOff, range * m.maxEnergy, 10); + ctx.fillStyle = m.fieldMeterColor; + ctx.fillRect(xOff, yOff, range * m.energy, 10); + } else if (m.energy > m.maxEnergy + 0.05) { + ctx.fillStyle = bgColor; + const xOff = m.pos.x - m.radius * m.energy + const yOff = m.pos.y - 50 + // ctx.fillRect(xOff, yOff, range * m.maxEnergy, 10); + ctx.fillStyle = m.fieldMeterColor; + ctx.fillRect(xOff, yOff, range * m.energy, 10); + } + }, + drawRegenEnergyCloaking: function () { + if (m.energy < m.maxEnergy) { // replaces m.drawRegenEnergy() with custom code + m.regenEnergy(); + const xOff = m.pos.x - m.radius * m.maxEnergy + const yOff = m.pos.y - 50 + ctx.fillStyle = "rgba(0, 0, 0, 0.2)" // + ctx.fillRect(xOff, yOff, 60 * m.maxEnergy, 10); + ctx.fillStyle = "#fff" //m.cycle > m.lastKillCycle + 300 ? "#000" : "#fff" //"#fff"; + ctx.fillRect(xOff, yOff, 60 * m.energy, 10); + ctx.beginPath() + ctx.rect(xOff, yOff, 60 * m.maxEnergy, 10); + ctx.strokeStyle = m.fieldMeterColor; + ctx.lineWidth = 1; + ctx.stroke(); + } + }, + setFieldRegen() { + if (m.fieldMode === 0) { + m.fieldRegen = 0.00067 //4 energy per second for field emitter + } else if (m.fieldMode === 6) { + m.fieldRegen = 0.002 //12 energy per second for time dilation + } else if (m.fieldMode === 2) { + m.fieldRegen = 0.000833 //5 energy per second perfect dia + } else if (m.fieldMode === 4) { + m.fieldRegen = 0.002 //12 energy per second molecular assembler + } else if (m.fieldMode === 5) { + m.fieldRegen = 0.001667 //10 energy per second plasma torch + } else if (m.fieldMode === 8) { + m.fieldRegen = 0.001667 //10 energy per second pilot wave + } else if (m.fieldMode === 9) { + m.fieldRegen = 0.00117 //7 energy per second wormhole + } else if (m.fieldMode === 10) { + m.fieldRegen = 0.0015 //9 energy per second grappling hook + } else { + m.fieldRegen = 0.001 //6 energy per second + } + if (m.fieldMode === 0 || m.fieldMode === 4) m.fieldRegen += 0.0001 * m.coupling + if (tech.isTimeCrystals) { + m.fieldRegen *= 2.5 + } else if (tech.isGroundState) { + m.fieldRegen *= 0.66 + } + }, + regenEnergy() { //used in drawRegenEnergy // rewritten by some tech + if (m.immuneCycle < m.cycle && m.fieldCDcycle < m.cycle) m.energy += m.fieldRegen * level.isReducedRegen; + if (m.energy < 0) m.energy = 0 + }, + regenEnergyDefault() { + if (m.immuneCycle < m.cycle && m.fieldCDcycle < m.cycle) m.energy += m.fieldRegen * level.isReducedRegen; + if (m.energy < 0) m.energy = 0 + }, + lookingAt(who) { + //calculate a vector from body to player and make it length 1 + const diff = Vector.normalise(Vector.sub(who.position, m.pos)); + //make a vector for the player's direction of length 1 + const dir = { x: Math.cos(m.angle), y: Math.sin(m.angle) }; + //the dot product of diff and dir will return how much over lap between the vectors + if (Vector.dot(dir, diff) > m.fieldThreshold) { + return true; + } + return false; + }, + drop() { + if (m.isHolding) { + m.fieldCDcycle = m.cycle + 15; + m.isHolding = false; + m.throwCharge = 0; + m.definePlayerMass() + } + if (m.holdingTarget) { + m.holdingTarget.collisionFilter.category = cat.body; + m.holdingTarget.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + m.holdingTarget = null; + } + }, + definePlayerMass(mass = m.defaultMass) { + Matter.Body.setMass(player, mass); + //reduce air and ground move forces + m.setMovement() + //make player stand a bit lower when holding heavy masses + m.yOffWhen.stand = Math.max(m.yOffWhen.crouch, Math.min(49, 49 - (mass - 5) * 6)) + if (m.onGround && !m.crouch) m.yOffGoal = m.yOffWhen.stand; + }, + drawHold(target, stroke = true) { + if (target) { + const eye = 15; + const len = target.vertices.length - 1; + ctx.fillStyle = "rgba(110,170,200," + (0.2 + 0.4 * Math.random()) + ")"; + ctx.lineWidth = 1; + ctx.strokeStyle = "#000"; + ctx.beginPath(); + ctx.moveTo( + m.pos.x + eye * Math.cos(m.angle), + m.pos.y + eye * Math.sin(m.angle) + ); + ctx.lineTo(target.vertices[len].x, target.vertices[len].y); + ctx.lineTo(target.vertices[0].x, target.vertices[0].y); + ctx.fill(); + if (stroke) ctx.stroke(); + for (let i = 0; i < len; i++) { + ctx.beginPath(); + ctx.moveTo( + m.pos.x + eye * Math.cos(m.angle), + m.pos.y + eye * Math.sin(m.angle) + ); + ctx.lineTo(target.vertices[i].x, target.vertices[i].y); + ctx.lineTo(target.vertices[i + 1].x, target.vertices[i + 1].y); + ctx.fill(); + if (stroke) ctx.stroke(); + } + } + }, + holding() { + if (m.fireCDcycle < m.cycle) m.fireCDcycle = m.cycle - 1 + if (m.holdingTarget) { + m.energy -= m.fieldRegen; + if (m.energy < 0) m.energy = 0; + Matter.Body.setPosition(m.holdingTarget, { + x: m.pos.x + 70 * Math.cos(m.angle), + y: m.pos.y + 70 * Math.sin(m.angle) + }); + Matter.Body.setVelocity(m.holdingTarget, player.velocity); + Matter.Body.rotate(m.holdingTarget, 0.01 / m.holdingTarget.mass); //gently spin the block + } else { + m.isHolding = false + } + }, + throwBlock() { }, + throwBlockDefault() { + if (m.holdingTarget) { + if (input.field) { + if (m.energy > 0.001) { + if (m.fireCDcycle < m.cycle) m.fireCDcycle = m.cycle + if (tech.isCapacitor && m.throwCharge < 4) m.throwCharge = 4 + m.throwCharge += 0.5 / m.holdingTarget.mass / b.fireCDscale + if (m.throwCharge < 6) m.energy -= 0.001 / b.fireCDscale; // m.throwCharge caps at 5 + + //trajectory path prediction + if (tech.isTokamak) { + //draw charge + const x = m.pos.x + 15 * Math.cos(m.angle); + const y = m.pos.y + 15 * Math.sin(m.angle); + const len = m.holdingTarget.vertices.length - 1; + const opacity = m.throwCharge > 4 ? 0.65 : m.throwCharge * 0.06 + ctx.fillStyle = `rgba(255,0,255,${opacity})`; + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(m.holdingTarget.vertices[len].x, m.holdingTarget.vertices[len].y); + ctx.lineTo(m.holdingTarget.vertices[0].x, m.holdingTarget.vertices[0].y); + ctx.fill(); + for (let i = 0; i < len; i++) { + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(m.holdingTarget.vertices[i].x, m.holdingTarget.vertices[i].y); + ctx.lineTo(m.holdingTarget.vertices[i + 1].x, m.holdingTarget.vertices[i + 1].y); + ctx.fill(); + } + if (tech.isTokamakFly && m.throwCharge > 4 && m.energy > 0.01) { + player.force.y -= 0.5 * player.mass * simulation.g; //add some reduced gravity + // const mass = (player.mass + 10) / 3 * simulation.g //this makes it so you fly slower with larger blocks + let isDrain = false + const thrust = player.mass * simulation.g * Math.pow(5 / player.mass, 0.1) + if (input.down) { + isDrain = true + player.force.y += 0.9 * thrust; + } else if (input.up) { + isDrain = true + player.force.y -= 0.9 * thrust + } + if (!m.onGround) { + if (input.left) { + isDrain = true + player.force.x -= 0.4 * thrust + } else if (input.right) { + isDrain = true + player.force.x += 0.4 * thrust + } + if (isDrain) m.energy -= 0.0017; + } + + } + } else { + if (tech.isGroupThrow) { + const range = 810000 + + for (let i = 0; i < body.length; i++) { + const sub = Vector.sub(m.pos, body[i].position) + const dist2 = Vector.magnitudeSquared(sub) + if (dist2 < range) { + body[i].force.y -= body[i].mass * (simulation.g * 1.01); //remove a bit more then standard gravity + if (dist2 > 40000) { + const f = Vector.mult(Vector.normalise(sub), 0.0008 * body[i].mass) + body[i].force.x += f.x + body[i].force.y += f.y + Matter.Body.setVelocity(body[i], { x: 0.96 * body[i].velocity.x, y: 0.96 * body[i].velocity.y }); + } + } + } + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, Math.sqrt(range), 0, 2 * Math.PI); + ctx.fillStyle = "rgba(245,245,255,0.15)"; + ctx.fill(); + // ctx.globalCompositeOperation = "difference"; + // ctx.globalCompositeOperation = "source-over"; + } + //draw charge + const x = m.pos.x + 15 * Math.cos(m.angle); + const y = m.pos.y + 15 * Math.sin(m.angle); + const len = m.holdingTarget.vertices.length - 1; + const edge = m.throwCharge * m.throwCharge * m.throwCharge; + const grd = ctx.createRadialGradient(x, y, edge, x, y, edge + 5); + grd.addColorStop(0, "rgba(255,50,150,0.3)"); + grd.addColorStop(1, "transparent"); + ctx.fillStyle = grd; + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(m.holdingTarget.vertices[len].x, m.holdingTarget.vertices[len].y); + ctx.lineTo(m.holdingTarget.vertices[0].x, m.holdingTarget.vertices[0].y); + ctx.fill(); + for (let i = 0; i < len; i++) { + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(m.holdingTarget.vertices[i].x, m.holdingTarget.vertices[i].y); + ctx.lineTo(m.holdingTarget.vertices[i + 1].x, m.holdingTarget.vertices[i + 1].y); + ctx.fill(); + } + //trajectory prediction + const cycles = 30 + const charge = Math.min(m.throwCharge / 5, 1) + const speed = (tech.isPrinter ? 15 + 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.1)) : 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.25))) + const v = { x: speed * Math.cos(m.angle), y: speed * Math.sin(m.angle) } + ctx.beginPath() + for (let i = 1, len = 10; i < len + 1; i++) { + const time = cycles * i / len + ctx.lineTo(m.pos.x + time * v.x, m.pos.y + time * v.y + 0.34 * time * time) + } + ctx.strokeStyle = "rgba(68, 68, 68, 0.15)" //color.map + ctx.lineWidth = 2 + ctx.stroke() + } + } else { + m.drop() + } + } else if (m.throwCharge > 0) { //Matter.Query.region(mob, player.bounds) + if (m.holdingTarget.isPrinted) m.holdingTarget.isPrinted = undefined + //throw the body + m.fieldCDcycle = m.cycle + 20; + m.fireCDcycle = m.cycle + 20; + + m.isHolding = false; + + if (tech.isTokamak && m.throwCharge > 4) { //remove the block body and pulse in the direction you are facing + //m.throwCharge > 5 seems to be when the field full colors in a block you are holding + m.throwCycle = m.cycle + 180 //used to detect if a block was thrown in the last 3 seconds + if (m.immuneCycle < m.cycle) m.energy += 0.25 * Math.sqrt(m.holdingTarget.mass) * Math.min(5, m.throwCharge) * level.isReducedRegen + m.throwCharge = 0; + m.definePlayerMass() //return to normal player mass + //remove block before pulse, so it doesn't get in the way + for (let i = 0; i < body.length; i++) { + if (body[i] === m.holdingTarget) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + } + } + b.pulse(60 * Math.pow(m.holdingTarget.mass, 0.25), m.angle) + if (tech.isTokamakHeal && tech.tokamakHealCount < 5) { + tech.tokamakHealCount++ + let massScale = Math.min(65 * Math.sqrt(m.maxHealth), 14 * Math.pow(m.holdingTarget.mass, 0.4)) + if (powerUps.healGiveMaxEnergy) massScale = powerUps["heal"].size() + powerUps.spawn(m.pos.x, m.pos.y, "heal", true, massScale * (simulation.healScale ** 0.25) * Math.sqrt(tech.largerHeals * (tech.isHalfHeals ? 0.5 : 1))) // spawn(x, y, target, moving = true, mode = null, size = powerUps[target].size()) { + } + } else { //normal throw + //bullet-like collisions + m.holdingTarget.collisionFilter.category = cat.bullet + m.holdingTarget.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield; + if (tech.isBlockRestitution) { + m.holdingTarget.restitution = 0.999 //extra bouncy + m.holdingTarget.friction = m.holdingTarget.frictionStatic = m.holdingTarget.frictionAir = 0.001 + } + //check every second to see if player is away from thrown body, and make solid + const solid = function (that) { + const dx = that.position.x - player.position.x; + const dy = that.position.y - player.position.y; + // if (that.speed < 3 && dx * dx + dy * dy > 10000 && that !== m.holdingTarget) { + if (dx * dx + dy * dy > 10000 && that !== m.holdingTarget) { + that.collisionFilter.category = cat.body; //make solid + that.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet; //can hit player now + } else { + setTimeout(solid, 40, that); + } + }; + setTimeout(solid, 200, m.holdingTarget); + + const charge = Math.min(m.throwCharge / 5, 1) + //***** scale throw speed with the first number, 80 ***** + // let speed = 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.25)); + let speed = (tech.isPrinter ? 15 + 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.1)) : 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.25))) + + if (Matter.Query.collides(m.holdingTarget, map).length !== 0) { + speed *= 0.7 //drop speed by 30% if touching map + if (Matter.Query.ray(map, m.holdingTarget.position, m.pos).length !== 0) speed = 0 //drop to zero if the center of the block can't see the center of the player through the map + } + m.throwCharge = 0; + m.throwCycle = m.cycle + 180 //used to detect if a block was thrown in the last 3 seconds + Matter.Body.setVelocity(m.holdingTarget, { + x: player.velocity.x * 0.5 + Math.cos(m.angle) * speed, + y: player.velocity.y * 0.5 + Math.sin(m.angle) * speed + }); + Matter.Body.setVelocity(player, { + x: player.velocity.x - Math.cos(m.angle) * speed / (m.crouch ? 30 : 10) * Math.sqrt(m.holdingTarget.mass), + y: player.velocity.y - Math.sin(m.angle) * speed / 30 * Math.sqrt(m.holdingTarget.mass) + }); + m.definePlayerMass() //return to normal player mass + + if (tech.isStaticBlock) m.holdingTarget.isStatic = true + if (tech.isAddBlockMass) { + const expand = function (that, massLimit) { + if (that.mass < massLimit) { + const scale = 1.04; + Matter.Body.scale(that, scale, scale); + setTimeout(expand, 20, that, massLimit); + } + }; + expand(m.holdingTarget, Math.min(20, m.holdingTarget.mass * 3)) + } + if (tech.isGroupThrow) { + const range = 810000 + for (let i = 0; i < body.length; i++) { + if (body[i] !== m.holdingTarget) { + const dist2 = Vector.magnitudeSquared(Vector.sub(m.pos, body[i].position)) + if (dist2 < range) { + const blockSpeed = 90 * charge * Math.min(0.85, 0.8 / Math.pow(body[i].mass, 0.25)) * Math.pow((range - dist2) / range, 0.2) + Matter.Body.setVelocity(body[i], { + x: body[i].velocity.x * 0.5 + Math.cos(m.angle) * blockSpeed, + y: body[i].velocity.y * 0.5 + Math.sin(m.angle) * blockSpeed + }); + } + } + } + } + } + } + } else { + m.isHolding = false + } + }, + throwSelf() { + if (m.holdingTarget) { + if (input.field) { + if (m.energy > 0.001) { + if (m.fireCDcycle < m.cycle) m.fireCDcycle = m.cycle + if (tech.isCapacitor && m.throwCharge < 4) m.throwCharge = 4 + m.throwCharge += 0.5 / m.holdingTarget.mass / b.fireCDscale + if (m.throwCharge < 6) m.energy -= 0.001 / b.fireCDscale; // m.throwCharge caps at 5 + + //trajectory path prediction + //draw charge + const x = m.pos.x + 15 * Math.cos(m.angle); + const y = m.pos.y + 15 * Math.sin(m.angle); + const len = m.holdingTarget.vertices.length - 1; + const edge = m.throwCharge * m.throwCharge * m.throwCharge; + const grd = ctx.createRadialGradient(x, y, edge, x, y, edge + 5); + grd.addColorStop(0, "rgba(255,50,150,0.3)"); + grd.addColorStop(1, "transparent"); + ctx.fillStyle = grd; + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(m.holdingTarget.vertices[len].x, m.holdingTarget.vertices[len].y); + ctx.lineTo(m.holdingTarget.vertices[0].x, m.holdingTarget.vertices[0].y); + ctx.fill(); + for (let i = 0; i < len; i++) { + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(m.holdingTarget.vertices[i].x, m.holdingTarget.vertices[i].y); + ctx.lineTo(m.holdingTarget.vertices[i + 1].x, m.holdingTarget.vertices[i + 1].y); + ctx.fill(); + } + //trajectory prediction + const cycles = 30 + const charge = Math.min(m.throwCharge / 5, 1) + const speed = (tech.isPrinter ? 15 + 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.1)) : 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.25))) + const v = { x: speed * Math.cos(m.angle), y: speed * Math.sin(m.angle) } + ctx.beginPath() + for (let i = 1, len = 10; i < len + 1; i++) { + const time = cycles * i / len + ctx.lineTo(m.pos.x + time * v.x, m.pos.y + time * v.y + 0.34 * time * time) + } + ctx.strokeStyle = "rgba(68, 68, 68, 0.15)" //color.map + ctx.lineWidth = 2 + ctx.stroke() + + } else { + m.drop() + } + } else if (m.throwCharge > 0) { //Matter.Query.region(mob, player.bounds) + if (m.holdingTarget.isPrinted) m.holdingTarget.isPrinted = undefined + //throw the body + m.fieldCDcycle = m.cycle + 20; + m.fireCDcycle = m.cycle + 20; + + m.isHolding = false; + //bullet-like collisions + m.holdingTarget.collisionFilter.category = cat.bullet + m.holdingTarget.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield; + if (tech.isBlockRestitution) { + m.holdingTarget.restitution = 0.999 //extra bouncy + m.holdingTarget.friction = m.holdingTarget.frictionStatic = m.holdingTarget.frictionAir = 0.001 + } + //check every second to see if player is away from thrown body, and make solid + const solid = function (that) { + const dx = that.position.x - player.position.x; + const dy = that.position.y - player.position.y; + // if (that.speed < 3 && dx * dx + dy * dy > 10000 && that !== m.holdingTarget) { + if (dx * dx + dy * dy > 10000 && that !== m.holdingTarget) { + that.collisionFilter.category = cat.body; //make solid + that.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet; //can hit player now + } else { + setTimeout(solid, 40, that); + } + }; + setTimeout(solid, 200, m.holdingTarget); + + const charge = Math.min(m.throwCharge / 5, 1) + //***** scale throw speed with the first number, 80 ***** + // let speed = 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.25)); + let speed = (tech.isPrinter ? 15 + 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.1)) : 80 * charge * Math.min(0.85, 0.8 / Math.pow(m.holdingTarget.mass, 0.25))) + + + m.throwCharge = 0; + m.throwCycle = m.cycle + 180 //used to detect if a block was thrown in the last 3 seconds + Matter.Body.setVelocity(m.holdingTarget, { + x: Math.cos(m.angle) * speed / (m.crouch ? 30 : 10) * Math.sqrt(m.holdingTarget.mass), + y: player.velocity.y - Math.sin(m.angle) * speed / 30 * Math.sqrt(m.holdingTarget.mass) + }); + Matter.Body.setVelocity(player, { + x: player.velocity.x - player.velocity.x * 0.5 + Math.cos(m.angle) * speed, + y: player.velocity.y - player.velocity.y * 0.5 + Math.sin(m.angle) * speed + }); + m.definePlayerMass() //return to normal player mass + + if (tech.isAddBlockMass) { + const expand = function (that, massLimit) { + if (that.mass < massLimit) { + const scale = 1.04; + Matter.Body.scale(that, scale, scale); + setTimeout(expand, 20, that, massLimit); + } + }; + expand(m.holdingTarget, Math.min(20, m.holdingTarget.mass * 3)) + } + + } + } else { + m.isHolding = false + } + }, + drawField() { + if (m.holdingTarget) { + ctx.fillStyle = "rgba(110,170,200," + (m.energy * (0.05 + 0.05 * Math.random())) + ")"; + ctx.strokeStyle = "rgba(110, 200, 235, " + (0.3 + 0.08 * Math.random()) + ")" //"#9bd" //"rgba(110, 200, 235, " + (0.5 + 0.1 * Math.random()) + ")" + } else { + ctx.fillStyle = "rgba(110,170,200," + (0.02 + m.energy * (0.15 + 0.15 * Math.random())) + ")"; + ctx.strokeStyle = "rgba(110, 200, 235, " + (0.6 + 0.2 * Math.random()) + ")" //"#9bd" //"rgba(110, 200, 235, " + (0.5 + 0.1 * Math.random()) + ")" + } + // const off = 2 * Math.cos(simulation.cycle * 0.1) + const range = m.fieldRange; + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, range, m.angle - Math.PI * m.fieldArc, m.angle + Math.PI * m.fieldArc, false); + ctx.lineWidth = 2; + ctx.stroke(); + let eye = 13; + let aMag = 0.75 * Math.PI * m.fieldArc + let a = m.angle + aMag + let cp1x = m.pos.x + 0.6 * range * Math.cos(a) + let cp1y = m.pos.y + 0.6 * range * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, m.pos.x + eye * Math.cos(m.angle), m.pos.y + eye * Math.sin(m.angle)) + a = m.angle - aMag + cp1x = m.pos.x + 0.6 * range * Math.cos(a) + cp1y = m.pos.y + 0.6 * range * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, m.pos.x + 1 * range * Math.cos(m.angle - Math.PI * m.fieldArc), m.pos.y + 1 * range * Math.sin(m.angle - Math.PI * m.fieldArc)) + ctx.fill(); + // ctx.lineTo(m.pos.x + eye * Math.cos(m.angle), m.pos.y + eye * Math.sin(m.angle)); + + //draw random lines in field for cool effect + let offAngle = m.angle + 1.7 * Math.PI * m.fieldArc * (Math.random() - 0.5); + ctx.beginPath(); + eye = 15; + ctx.moveTo(m.pos.x + eye * Math.cos(m.angle), m.pos.y + eye * Math.sin(m.angle)); + ctx.lineTo(m.pos.x + range * Math.cos(offAngle), m.pos.y + range * Math.sin(offAngle)); + ctx.strokeStyle = "rgba(120,170,255,0.6)"; + ctx.lineWidth = 1; + ctx.stroke(); + }, + grabPowerUp() { //look for power ups to grab with field + if (m.fireCDcycle < m.cycle) m.fireCDcycle = m.cycle - 1 + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (tech.isEnergyNoAmmo && powerUp[i].name === "ammo") continue + const dxP = m.pos.x - powerUp[i].position.x; + const dyP = m.pos.y - powerUp[i].position.y; + const dist2 = dxP * dxP + dyP * dyP + 10; + // float towards player if looking at and in range or if very close to player + if ( + dist2 < m.grabPowerUpRange2 && + (m.lookingAt(powerUp[i]) || dist2 < 10000) && + Matter.Query.ray(map, powerUp[i].position, m.pos).length === 0 + ) { + if (!tech.isHealAttract || powerUp[i].name !== "heal") { //if you have accretion heals are already pulled in a different way + powerUp[i].force.x += 0.04 * (dxP / Math.sqrt(dist2)) * powerUp[i].mass; + powerUp[i].force.y += 0.04 * (dyP / Math.sqrt(dist2)) * powerUp[i].mass - powerUp[i].mass * simulation.g; //negate gravity + Matter.Body.setVelocity(powerUp[i], { x: powerUp[i].velocity.x * 0.11, y: powerUp[i].velocity.y * 0.11 }); //extra friction + } + if ( //use power up if it is close enough + dist2 < 5000 && + !simulation.isChoosing && + (powerUp[i].name !== "heal" || m.maxHealth - m.health > 0.01 || tech.isOverHeal) + ) { + powerUps.onPickUp(powerUp[i]); + Matter.Body.setVelocity(player, { //player knock back, after grabbing power up + x: player.velocity.x + powerUp[i].velocity.x / player.mass * 4 * powerUp[i].mass, + y: player.velocity.y + powerUp[i].velocity.y / player.mass * 4 * powerUp[i].mass + }); + powerUp[i].effect(); + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + return; //because the array order is messed up after splice + } + } + } + }, + minEnergyToDeflect: 0.05, + bulletsToBlocks(who) { + if (who.isMobBullet && !who.isInvulnerable && who.mass < 10 && body.length < mobs.maxMobBody) { + // spawn block + body[body.length] = Matter.Bodies.polygon(who.position.x, who.position.y, who.vertices.length, who.radius, { + friction: 0.05, + frictionAir: 0.001, + collisionFilter: { + category: cat.bullet, + mask: cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield + }, + classType: "body", + isPrinted: true, + radius: 10, //used to grow and warp the shape of the block + density: 0.002, //double density for 2x damage + }); + const block = body[body.length - 1] + Composite.add(engine.world, block); //add to world + //reverse velocity and make sure it's above 40 + const unit = Vector.mult(Vector.normalise(who.velocity), -Math.max(40, who.speed)) + Matter.Body.setVelocity(block, unit); + + simulation.ephemera.push({ + name: "remove block", + count: 120, //cycles before it self removes + do() { + this.count-- + if (this.count < 0) { + simulation.removeEphemera(this.name) + Matter.Composite.remove(engine.world, block); + //find block + for (let i = 0; i < body.length; i++) { + if (body[i] === block) { + body.splice(i, 1); + break + } + } + + } + }, + }) + //remove mob bullet + Matter.Composite.remove(engine.world, who); //remove from physics early to avoid collisions with block + who.alive = false + } + }, + pushMass(who, fieldBlockCost = (0.025 + Math.sqrt(who.mass) * Vector.magnitude(Vector.sub(who.velocity, player.velocity)) * 0.002) * m.fieldShieldingScale) { + if (m.energy > m.minEnergyToDeflect) { //shield needs at least some of the cost to block + if (who.isShielded) fieldBlockCost *= 2; //shielded mobs take more energy to block + m.energy -= fieldBlockCost + if (m.energy < m.minEnergyToDeflect) { + m.energy = 0; + m.fieldCDcycle = m.cycle + Math.max(m.fieldBlockCD, 60); + if (tech.isLaserField) { + simulation.ephemera.push({ + name: "laser field", //used to find this array element in simulation.removeEphemera() + count: 20 + Math.floor(m.maxEnergy * 30 * 0.0018 / tech.laserDrain), //how many cycles the ephemera lasts, scales with max energy + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + for (let i = 0, num = 12; i < num; i++) { //draw random lasers + const angle = 6.28 * i / num + m.cycle * 0.04 + b.laser({ x: m.pos.x + 30 * Math.cos(angle), y: m.pos.y + 30 * Math.sin(angle) }, { x: m.pos.x + 3000 * Math.cos(angle), y: m.pos.y + 3000 * Math.sin(angle) }, tech.laserDamage * 2.5)//dmg = tech.laserDamage, reflections = tech.laserReflections, isThickBeam = false, push = 1 + } + }, + }) + } + } else { + m.fieldCDcycle = m.cycle + m.fieldBlockCD; + } + if (!who.isInvulnerable && (m.coupling && m.fieldMode === 0) && bullet.length < 200) { //for field emitter iceIX + for (let i = 0; i < m.coupling; i++) { + if (0.1 * m.coupling - i > 1.25 * Math.random()) { + const sub = Vector.mult(Vector.normalise(Vector.sub(who.position, m.pos)), (m.fieldRange * m.harmonicRadius) * (0.4 + 0.3 * Math.random())) //m.harmonicRadius should be 1 unless you are standing wave expansion + const rad = Vector.rotate(sub, 1 * (Math.random() - 0.5)) + const angle = Math.atan2(sub.y, sub.x) + b.iceIX(6 + 6 * Math.random(), angle + 3 * (Math.random() - 0.5), Vector.add(m.pos, rad)) + } + } + } + m.bulletsToBlocks(who) + const unit = Vector.normalise(Vector.sub(player.position, who.position)) + if (tech.blockDmg) { + Matter.Body.setVelocity(who, { x: 0.5 * who.velocity.x, y: 0.5 * who.velocity.y }); + if (who.isShielded) { + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].id === who.shieldID) mob[i].damage(tech.blockDmg * m.dmgScale * (tech.isBlockRadiation ? 6 : 2), true) + } + } else if (tech.isBlockRadiation) { + if (who.isMobBullet) { + who.damage(tech.blockDmg * m.dmgScale * 3, true) + } else { + mobs.statusDoT(who, tech.blockDmg * 0.42, 180) //200% increase -> x (1+2) //over 7s -> 360/30 = 12 half seconds -> 3/12 + } + } else { + who.damage(tech.blockDmg * m.dmgScale, true) + } + const step = 40 + ctx.beginPath(); //draw electricity + for (let i = 0, len = 0.5 * tech.blockDmg; i < len; i++) { + let x = m.pos.x - 20 * unit.x; + let y = m.pos.y - 20 * unit.y; + ctx.moveTo(x, y); + for (let i = 0; i < 8; i++) { + x += step * (-unit.x + 1.5 * (Math.random() - 0.5)) + y += step * (-unit.y + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + } + ctx.lineWidth = 3; + ctx.strokeStyle = "#f0f"; + ctx.stroke(); + } else { + m.drawHold(who); + } + if (tech.isStunField) mobs.statusStun(who, tech.isStunField) + //knock backs + const massRoot = Math.sqrt(Math.min(12, Math.max(0.15, who.mass))); // masses above 12 can start to overcome the push back + Matter.Body.setVelocity(who, { x: player.velocity.x - (15 * unit.x) / massRoot, y: player.velocity.y - (15 * unit.y) / massRoot }); + if (who.isUnstable) { + if (m.fieldCDcycle < m.cycle + 30) m.fieldCDcycle = m.cycle + 10 + who.death(); + } + if (m.crouch) { + Matter.Body.setVelocity(player, { x: player.velocity.x + 0.1 * m.blockingRecoil * unit.x * massRoot, y: player.velocity.y + 0.1 * m.blockingRecoil * unit.y * massRoot }); + } else { + Matter.Body.setVelocity(player, { x: player.velocity.x + m.blockingRecoil * unit.x * massRoot, y: player.velocity.y + m.blockingRecoil * unit.y * massRoot }); + } + } + }, + pushMobsFacing() { // find mobs in range and in direction looking + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + Vector.magnitude(Vector.sub(mob[i].position, m.pos)) - mob[i].radius < m.fieldRange && + m.lookingAt(mob[i]) && + !mob[i].isUnblockable && + Matter.Query.ray(map, mob[i].position, m.pos).length === 0 + ) { + mob[i].locatePlayer(); + m.pushMass(mob[i]); + + if (tech.deflectEnergy && !mob[i].isInvulnerable && !mob[i].isShielded) { + m.energy += tech.deflectEnergy * level.isReducedRegen + } + } + } + }, + lookForPickUp() { //find body to pickup + const grabbing = { + targetIndex: null, + targetRange: 150, + // lookingAt: false //false to pick up object in range, but not looking at + }; + for (let i = 0, len = body.length; i < len; ++i) { + if (Matter.Query.ray(map, body[i].position, m.pos).length === 0) { + //is m next body a better target then my current best + const dist = Vector.magnitude(Vector.sub(body[i].position, m.pos)); + const looking = m.lookingAt(body[i]); + // if (dist < grabbing.targetRange && (looking || !grabbing.lookingAt) && !body[i].isNotHoldable) { + if (dist < grabbing.targetRange && looking && !body[i].isNotHoldable) { + grabbing.targetRange = dist; + grabbing.targetIndex = i; + // grabbing.lookingAt = looking; + } + } + } + // set pick up target for when mouse is released + if (body[grabbing.targetIndex]) { + m.holdingTarget = body[grabbing.targetIndex]; + ctx.beginPath(); //draw on each valid body + let vertices = m.holdingTarget.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j += 1) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.fillStyle = "rgba(190,215,230," + (0.3 + 0.7 * Math.random()) + ")"; + ctx.fill(); + + ctx.globalAlpha = 0.2; + m.drawHold(m.holdingTarget); + ctx.globalAlpha = 1; + } else { + m.holdingTarget = null; + } + }, + pickUp() { + //triggers when a hold target exits and field button is released + m.isHolding = true; + //conserve momentum when player mass changes + totalMomentum = Vector.add(Vector.mult(player.velocity, player.mass), Vector.mult(m.holdingTarget.velocity, m.holdingTarget.mass)) + Matter.Body.setVelocity(player, Vector.mult(totalMomentum, 1 / (m.defaultMass + m.holdingTarget.mass))); + + m.definePlayerMass(m.defaultMass + m.holdingTarget.mass * m.holdingMassScale) + //make block collide with nothing + m.holdingTarget.collisionFilter.category = 0; + m.holdingTarget.collisionFilter.mask = 0; + }, + wakeCheck() { + if (m.isTimeDilated) { + m.isTimeDilated = false; + + function wake(who) { + for (let i = 0, len = who.length; i < len; ++i) { + Matter.Sleeping.set(who[i], false) + if (who[i].storeVelocity) { + Matter.Body.setVelocity(who[i], { + x: who[i].storeVelocity.x, + y: who[i].storeVelocity.y + }) + Matter.Body.setAngularVelocity(who[i], who[i].storeAngularVelocity) + } + } + } + // if (tech.isFreezeMobs) { + // for (let i = 0, len = mob.length; i < len; ++i) { + // const ICE_DRAIN = 0.0005 + // if (m.energy > ICE_DRAIN) m.energy -= ICE_DRAIN; + // Matter.Sleeping.set(mob[i], false) + // mobs.statusSlow(mob[i], 60) + // } + // } else { + // wake(mob); + // } + wake(mob); + wake(body); + wake(bullet); + for (let i = 0, len = cons.length; i < len; i++) { + if (cons[i].stiffness === 0) { + cons[i].stiffness = cons[i].storeStiffness + } + } + // wake(powerUp); + } + }, + hold() { }, + couplingDescription(couple = m.coupling) { + switch (m.fieldMode) { + case 0: //field emitter + return `all effects` + case 1: //standing wave + // return `deflecting condenses +${couple.toFixed(1)} ice IX` + return `+${(couple * 5).toFixed(0)} maximum energy` + case 2: //perfect diamagnetism + return `deflecting condenses ${(0.1 * couple).toFixed(2)} ice IX` + // return `invulnerable +${2*couple} seconds post collision` + case 3: //negative mass + return `${(0.973 ** couple).toFixed(2)}x damage taken` + case 4: //assembler + return `+${(0.6 * couple).toFixed(1)} energy per second` + case 5: //plasma + return `${(1 + 0.025 * couple).toFixed(3)}x damage` + case 6: //time dilation + return `+${(1 + 0.05 * couple).toFixed(2)}x longer stopped time` //movement, jumping, and + case 7: //cloaking + // return `${(1 + 3.3 * couple).toFixed(3)}x ambush damage` + return `${(1 + 0.05 * couple).toFixed(3)}x ambush damage` + case 8: //pilot wave + return `${(1 + 0.05 * couple).toFixed(2)}x block collision damage` + case 9: //wormhole + return `after eating blocks +${(2 * couple).toFixed(0)} energy` + case 10: //grappling hook + return `${powerUps.orb.ammo(1)} give ${(4 * couple).toFixed(0)}% more ammo` + } + }, + couplingChange(change = 0) { + if (change > 0 && level.onLevel !== -1) simulation.inGameConsole(`
m.coupling += ${change}`, 60); //level.onLevel !== -1 means not on lore level + m.coupling += change + if (m.coupling < 0) { + //look for coupling power ups on this level and remove them to prevent exploiting tech ejections + for (let i = powerUp.length - 1; i > -1; i--) { + if (powerUp[i].name === "coupling") { + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + m.coupling += 1 + if (!(m.coupling < 0)) break + } + } + m.coupling = 0 //can't go negative + } + m.setMaxEnergy(false); + // m.setMaxHealth(); + m.setFieldRegen() + mobs.setMobSpawnHealth(); + powerUps.setPowerUpMode(); + + // if ((m.fieldMode === 0 || m.fieldMode === 9) && !build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.4); + }, + setField(index) { + if (isNaN(index)) { //find index by name + let found = false + for (let i = 0; i < m.fieldUpgrades.length; i++) { + if (index === m.fieldUpgrades[i].name) { + index = i; + found = true; + break; + } + } + if (!found) return //if you can't find the field don't give a field to avoid game crash + } + m.fieldMode = index; + document.getElementById("field").innerHTML = m.fieldUpgrades[index].name + m.setHoldDefaults(); + m.fieldUpgrades[index].effect(); + simulation.inGameConsole(`
  m.setField("${m.fieldUpgrades[m.fieldMode].name}")
input.key.field: ["MouseRight"]`); + }, + fieldUpgrades: [{ + name: "field emitter", + imageNumber: Math.floor(Math.random() * 26), //pick one of the 25 field emitter image files at random + description: `initial field
use energy to deflect mobs and throw blocks +
4 energy per second`, //
100 max energy + effect: () => { + m.hold = function () { + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if ((input.field && m.fieldCDcycle < m.cycle)) { //not hold but field button is pressed + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + if (m.energy > m.minEnergyToDeflect) { + m.drawField(); + m.pushMobsFacing(); + } + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + } + m.drawRegenEnergy() + } + } + }, + { + name: "standing wave", + //deflecting protects you in every direction + description: `3 oscillating shields are permanently active +
+150 max energy +
6 energy per second`, + drainCD: 0, + effect: () => { + m.fieldBlockCD = 0; + m.blockingRecoil = 1 //4 is normal + m.fieldRange = 185 + m.fieldShieldingScale = 1.6 * Math.pow(0.5, (tech.harmonics - 2)) + // m.fieldHarmReduction = 0.66; //33% reduction + + m.harmonic3Phase = () => { //normal standard 3 different 2-d circles + const fieldRange1 = (0.75 + 0.3 * Math.sin(m.cycle / 23)) * m.fieldRange * m.harmonicRadius + const fieldRange2 = (0.68 + 0.37 * Math.sin(m.cycle / 37)) * m.fieldRange * m.harmonicRadius + const fieldRange3 = (0.7 + 0.35 * Math.sin(m.cycle / 47)) * m.fieldRange * m.harmonicRadius + const netFieldRange = Math.max(fieldRange1, fieldRange2, fieldRange3) + ctx.fillStyle = "rgba(110,170,200," + Math.min(0.6, (0.04 + 0.7 * m.energy * (0.1 + 0.11 * Math.random()))) + ")"; + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, fieldRange1, 0, 2 * Math.PI); + ctx.fill(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, fieldRange2, 0, 2 * Math.PI); + ctx.fill(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, fieldRange3, 0, 2 * Math.PI); + ctx.fill(); + //360 block + for (let i = 0, len = mob.length; i < len; ++i) { + if (Vector.magnitude(Vector.sub(mob[i].position, m.pos)) - mob[i].radius < netFieldRange && !mob[i].isUnblockable) { // && Matter.Query.ray(map, mob[i].position, m.pos).length === 0 + mob[i].locatePlayer(); + if (this.drainCD > m.cycle) { + m.pushMass(mob[i], 0); + } else { + m.pushMass(mob[i]); + this.drainCD = m.cycle + 15 + } + } + } + } + m.harmonicRadius = 1 //for smoothing function when player holds mouse (for harmonicAtomic) + m.harmonicAtomic = () => { //several ellipses spinning about different axises + const rotation = simulation.cycle * 0.0031 + const phase = simulation.cycle * 0.023 + const radius = m.fieldRange * m.harmonicRadius + ctx.lineWidth = 1; + ctx.strokeStyle = "rgba(110,170,200,0.8)" + ctx.fillStyle = "rgba(110,170,200," + Math.min(0.6, 0.7 * m.energy * (0.11 + 0.1 * Math.random()) * (3 / tech.harmonics)) + ")"; + // ctx.fillStyle = "rgba(110,170,200," + Math.min(0.7, m.energy * (0.22 - 0.01 * tech.harmonics) * (0.5 + 0.5 * Math.random())) + ")"; + for (let i = 0; i < tech.harmonics; i++) { + ctx.beginPath(); + ctx.ellipse(m.pos.x, m.pos.y, radius * Math.abs(Math.sin(phase + i / tech.harmonics * Math.PI)), radius, rotation + i / tech.harmonics * Math.PI, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + } + //360 block + for (let i = 0, len = mob.length; i < len; ++i) { + if (Vector.magnitude(Vector.sub(mob[i].position, m.pos)) - mob[i].radius < radius && !mob[i].isUnblockable) { // && Matter.Query.ray(map, mob[i].position, m.pos).length === 0 + mob[i].locatePlayer(); + if (this.drainCD > m.cycle) { + m.pushMass(mob[i], 0); + } else { + m.pushMass(mob[i]); + this.drainCD = m.cycle + 15 + } + } + } + } + if (tech.harmonics === 2) { + m.harmonicShield = m.harmonic3Phase + } else { + m.harmonicShield = m.harmonicAtomic + } + m.hold = function () { + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if ((input.field) && m.fieldCDcycle < m.cycle) { //not hold but field button is pressed + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + } + if (m.energy > m.minEnergyToDeflect && m.fieldCDcycle < m.cycle) { + if (tech.isStandingWaveExpand) { + if (input.field) { + // const oldHarmonicRadius = m.harmonicRadius + m.harmonicRadius = 0.99 * m.harmonicRadius + 0.01 * 4 + // m.energy -= 0.1 * (m.harmonicRadius - oldHarmonicRadius) + } else { + m.harmonicRadius = 0.994 * m.harmonicRadius + 0.006 + } + } + if (!simulation.isTimeSkipping) m.harmonicShield() + } + m.drawRegenEnergy() + } + } + }, + { + name: "perfect diamagnetism", + description: `deflecting does not drain energy
shield maintains functionality while inactive
5 energy per second`, + effect: () => { + m.fieldMeterColor = "#48f" //"#0c5" + m.eyeFillColor = m.fieldMeterColor + m.fieldShieldingScale = 0; + m.fieldBlockCD = 3; + m.grabPowerUpRange2 = 10000000 + m.fieldPosition = { x: m.pos.x, y: m.pos.y } + m.fieldAngle = m.angle + m.perfectPush = (isFree = false) => { + if (m.fieldCDcycle < m.cycle) { + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + Vector.magnitude(Vector.sub(mob[i].position, m.fieldPosition)) - mob[i].radius < m.fieldRange && + !mob[i].isUnblockable && + Vector.dot({ x: Math.cos(m.fieldAngle), y: Math.sin(m.fieldAngle) }, Vector.normalise(Vector.sub(mob[i].position, m.fieldPosition))) > m.fieldThreshold && + Matter.Query.ray(map, mob[i].position, m.fieldPosition).length === 0 + ) { + mob[i].locatePlayer(); + const unit = Vector.normalise(Vector.sub(m.fieldPosition, mob[i].position)) + m.fieldCDcycle = m.cycle + m.fieldBlockCD + (mob[i].isShielded ? 10 : 0); + if (!mob[i].isInvulnerable && bullet.length < 250) { + for (let i = 0; i < m.coupling; i++) { + if (0.1 * m.coupling - i > Math.random()) { + const angle = m.fieldAngle + 4 * m.fieldArc * (Math.random() - 0.5) + const radius = m.fieldRange * (0.6 + 0.3 * Math.random()) + b.iceIX(6 + 6 * Math.random(), angle, Vector.add(m.fieldPosition, { + x: radius * Math.cos(angle), + y: radius * Math.sin(angle) + })) + } + } + } + if (tech.blockDmg) { //electricity + Matter.Body.setVelocity(mob[i], { x: 0.5 * mob[i].velocity.x, y: 0.5 * mob[i].velocity.y }); + if (mob[i].isShielded) { + for (let j = 0, len = mob.length; j < len; j++) { + if (mob[j].id === mob[i].shieldID) mob[j].damage(tech.blockDmg * m.dmgScale * (tech.isBlockRadiation ? 6 : 2), true) + } + } else if (tech.isBlockRadiation) { + if (mob[i].isMobBullet) { + mob[i].damage(tech.blockDmg * m.dmgScale * 3, true) + } else { + mobs.statusDoT(mob[i], tech.blockDmg * m.dmgScale * 0.42, 180) //200% increase -> x (1+2) //over 7s -> 360/30 = 12 half seconds -> 3/12 + } + } else { + mob[i].damage(tech.blockDmg * m.dmgScale, true) + } + // if (mob[i].isShielded) { + // for (let j = 0, len = mob.length; j < len; j++) { + // if (mob[j].id === mob[i].shieldID) mob[j].damage(tech.blockDmg * m.dmgScale * (tech.isBlockRadiation ? 3 : 1), true) + // } + // } else { + // if (tech.isBlockRadiation && !mob[i].isMobBullet) { + // mobs.statusDoT(mob[i], tech.blockDmg * m.dmgScale * 4 / 12, 360) //200% increase -> x (1+2) //over 7s -> 360/30 = 12 half seconds -> 3/12 + // } else { + // mob[i].damage(tech.blockDmg * m.dmgScale) + // } + // } + const step = 40 + ctx.beginPath(); + for (let i = 0, len = 0.5 * tech.blockDmg; i < len; i++) { + let x = m.fieldPosition.x - 20 * unit.x; + let y = m.fieldPosition.y - 20 * unit.y; + ctx.moveTo(x, y); + for (let i = 0; i < 8; i++) { + x += step * (-unit.x + 1.5 * (Math.random() - 0.5)) + y += step * (-unit.y + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + } + ctx.lineWidth = 3; + ctx.strokeStyle = "#f0f"; + ctx.stroke(); + } else if (isFree) { + ctx.lineWidth = 2; //when blocking draw this graphic + ctx.fillStyle = `rgba(110,150,220, ${0.2 + 0.4 * Math.random()})` + ctx.strokeStyle = "#000"; + const len = mob[i].vertices.length - 1; + const mag = mob[i].radius + ctx.beginPath(); + ctx.moveTo(mob[i].vertices[len].x + mag * (Math.random() - 0.5), mob[i].vertices[len].y + mag * (Math.random() - 0.5)) + for (let j = 0; j < len; j++) { + ctx.lineTo(mob[i].vertices[j].x + mag * (Math.random() - 0.5), mob[i].vertices[j].y + mag * (Math.random() - 0.5)); + } + ctx.lineTo(mob[i].vertices[len].x + mag * (Math.random() - 0.5), mob[i].vertices[len].y + mag * (Math.random() - 0.5)) + ctx.fill(); + ctx.stroke(); + } else { + + const eye = 15; //when blocking draw this graphic + const len = mob[i].vertices.length - 1; + ctx.lineWidth = 1; + ctx.fillStyle = `rgba(110,150,220, ${0.2 + 0.4 * Math.random()})` + ctx.strokeStyle = "#000"; + ctx.beginPath(); + ctx.moveTo(m.fieldPosition.x + eye * Math.cos(m.fieldAngle), m.fieldPosition.y + eye * Math.sin(m.fieldAngle)); + ctx.lineTo(mob[i].vertices[len].x, mob[i].vertices[len].y); + ctx.lineTo(mob[i].vertices[0].x, mob[i].vertices[0].y); + ctx.fill(); + ctx.stroke(); + for (let j = 0; j < len; j++) { + ctx.beginPath(); + ctx.moveTo(m.fieldPosition.x + eye * Math.cos(m.fieldAngle), m.fieldPosition.y + eye * Math.sin(m.fieldAngle)); + ctx.lineTo(mob[i].vertices[j].x, mob[i].vertices[j].y); + ctx.lineTo(mob[i].vertices[j + 1].x, mob[i].vertices[j + 1].y); + ctx.fill(); + ctx.stroke(); + } + } + m.bulletsToBlocks(mob[i]) + if (tech.isStunField) mobs.statusStun(mob[i], tech.isStunField) + //mob knock backs + const massRoot = Math.sqrt(Math.max(1, mob[i].mass)); + Matter.Body.setVelocity(mob[i], { + x: player.velocity.x - (30 * unit.x) / massRoot, + y: player.velocity.y - (30 * unit.y) / massRoot + }); + if (mob[i].isUnstable) { + if (m.fieldCDcycle < m.cycle + 10) m.fieldCDcycle = m.cycle + 6 + mob[i].death(); + } + if (!isFree) { //player knock backs + if (mob[i].isDropPowerUp && player.speed < 12) { + const massRootCap = Math.sqrt(Math.min(10, Math.max(0.2, mob[i].mass))); + Matter.Body.setVelocity(player, { + x: 0.9 * player.velocity.x + 0.6 * unit.x * massRootCap, + y: 0.9 * player.velocity.y + 0.6 * unit.y * massRootCap + }); + } + } + } + } + } + } + m.hold = function () { + const wave = Math.sin(m.cycle * 0.022); + m.fieldRange = 180 + 12 * wave + 100 * tech.isBigField + m.fieldArc = 0.35 + 0.045 * wave + 0.065 * tech.isBigField //run calculateFieldThreshold after setting fieldArc, used for powerUp grab and mobPush with lookingAt(mob) + m.calculateFieldThreshold(); + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if (input.field) { //not hold but field button is pressed + //float while field is on + const angleReduction = 0.5 + 0.7 * (Math.PI / 2 - Math.min(Math.PI / 2, Math.abs(m.angle + Math.PI / 2))) + // console.log(angleReduction) + if (player.velocity.y > 1) { + player.force.y -= angleReduction * (tech.isBigField ? 0.95 : 0.5) * player.mass * simulation.g; + Matter.Body.setVelocity(player, { + x: player.velocity.x, + y: 0.98 * player.velocity.y + }); //set velocity to cap, but keep the direction + } + + // go invulnerable while field is active, but also drain energy + // if (true && m.energy > 2 * m.fieldRegen && m.immuneCycle < m.cycle + tech.cyclicImmunity) { + // m.immuneCycle = m.cycle + 1; //player is immune to damage for 60 cycles + // m.energy -= 2 * m.fieldRegen + // if (m.energy < m.fieldRegen) m.fieldCDcycle = m.cycle + 90; + // } + + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + m.fieldPosition = { x: m.pos.x, y: m.pos.y } + m.fieldAngle = m.angle + //draw field attached to player + if (m.holdingTarget) { + ctx.fillStyle = `rgba(110,150,220, ${0.06 + 0.03 * Math.random()})` + ctx.strokeStyle = `rgba(110,150,220, ${0.35 + 0.05 * Math.random()})` + } else { + ctx.fillStyle = `rgba(110,150,220, ${0.27 + 0.2 * Math.random() - 0.1 * wave})` + ctx.strokeStyle = `rgba(110,150,220, ${0.4 + 0.5 * Math.random()})` + } + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, m.fieldRange, m.angle - Math.PI * m.fieldArc, m.angle + Math.PI * m.fieldArc, false); + ctx.lineWidth = 2.5 - 1.5 * wave; + ctx.stroke(); + const curve = 0.57 + 0.04 * wave + const aMag = (1 - curve * 1.2) * Math.PI * m.fieldArc + let a = m.angle + aMag + let cp1x = m.pos.x + curve * m.fieldRange * Math.cos(a) + let cp1y = m.pos.y + curve * m.fieldRange * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, m.pos.x + 30 * Math.cos(m.angle), m.pos.y + 30 * Math.sin(m.angle)) + a = m.angle - aMag + cp1x = m.pos.x + curve * m.fieldRange * Math.cos(a) + cp1y = m.pos.y + curve * m.fieldRange * Math.sin(a) + ctx.quadraticCurveTo(cp1x, cp1y, m.pos.x + 1 * m.fieldRange * Math.cos(m.angle - Math.PI * m.fieldArc), m.pos.y + 1 * m.fieldRange * Math.sin(m.angle - Math.PI * m.fieldArc)) + ctx.fill(); + m.perfectPush(); + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + if (!input.field) { //&& tech.isFieldFree + //draw field free of player + ctx.fillStyle = `rgba(110,150,220, ${0.27 + 0.2 * Math.random() - 0.1 * wave})` + ctx.strokeStyle = `rgba(110,180,255, ${0.4 + 0.5 * Math.random()})` + ctx.beginPath(); + ctx.arc(m.fieldPosition.x, m.fieldPosition.y, m.fieldRange, m.fieldAngle - Math.PI * m.fieldArc, m.fieldAngle + Math.PI * m.fieldArc, false); + ctx.lineWidth = 2.5 - 1.5 * wave; + ctx.stroke(); + const curve = 0.8 + 0.06 * wave + const aMag = (1 - curve * 1.2) * Math.PI * m.fieldArc + let a = m.fieldAngle + aMag + ctx.quadraticCurveTo(m.fieldPosition.x + curve * m.fieldRange * Math.cos(a), m.fieldPosition.y + curve * m.fieldRange * Math.sin(a), m.fieldPosition.x + 1 * m.fieldRange * Math.cos(m.fieldAngle - Math.PI * m.fieldArc), m.fieldPosition.y + 1 * m.fieldRange * Math.sin(m.fieldAngle - Math.PI * m.fieldArc)) + ctx.fill(); + m.perfectPush(true); + } + } + // m.drawRegenEnergy() + m.drawRegenEnergy("rgba(0,0,0,0.2)") + if (tech.isPerfectBrake) { //cap mob speed around player + const range = 200 + 140 * wave + 150 * m.energy + for (let i = 0; i < mob.length; i++) { + const distance = Vector.magnitude(Vector.sub(m.pos, mob[i].position)) + if (distance < range) { + const cap = mob[i].isShielded ? 8 : 4 + if (mob[i].speed > cap && Vector.dot(mob[i].velocity, Vector.sub(m.pos, mob[i].position)) > 0) { // if velocity is directed towards player + Matter.Body.setVelocity(mob[i], Vector.mult(Vector.normalise(mob[i].velocity), cap)); //set velocity to cap, but keep the direction + } + } + } + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, range, 0, 2 * Math.PI); + ctx.fillStyle = "hsla(200,50%,61%,0.08)"; + ctx.fill(); + } + } + } + }, + { + name: "negative mass", + //
hold blocks as if they have a lower mass + description: `use energy to nullify  gravity
0.4x damage taken
6 energy per second`, + fieldDrawRadius: 0, + effect: () => { + m.fieldFire = true; + m.holdingMassScale = 0.01; //can hold heavier blocks with lower cost to jumping + m.fieldMeterColor = "#333" + m.eyeFillColor = m.fieldMeterColor + m.fieldHarmReduction = 0.4; + m.fieldDrawRadius = 0; + + m.hold = function () { + m.airSpeedLimit = 125 //5 * player.mass * player.mass + m.FxAir = 0.016 + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if (input.field) { //push away + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + const DRAIN = 0.00035 + if (m.energy > DRAIN && m.fieldCDcycle < m.cycle) { + if (tech.isFlyFaster) { + //look for nearby objects to make zero-g + function moveThis(who, range, mag = 1.06) { + for (let i = 0, len = who.length; i < len; ++i) { + sub = Vector.sub(who[i].position, m.pos); + dist = Vector.magnitude(sub); + if (dist < range) { + who[i].force.y -= who[i].mass * (simulation.g * mag); //add a bit more then standard gravity + if (input.left) { //blocks move horizontally with the same force as the player + who[i].force.x -= m.FxAir * who[i].mass / 10; // move player left / a + } else if (input.right) { + who[i].force.x += m.FxAir * who[i].mass / 10; //move player right / d + } + //loose attraction to player + // const sub = Vector.sub(m.pos, body[i].position) + // const unit = Vector.mult(Vector.normalise(sub), who[i].mass * 0.0000002 * Vector.magnitude(sub)) + // body[i].force.x += unit.x + // body[i].force.y += unit.y + } + } + } + //control horizontal acceleration + m.airSpeedLimit = 1000 // 7* player.mass * player.mass + m.FxAir = 0.01 + //control vertical acceleration + if (input.down) { //down + player.force.y += 0.5 * player.mass * simulation.g; + this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 500 * 0.03; + moveThis(powerUp, this.fieldDrawRadius, 0); + moveThis(body, this.fieldDrawRadius, 0); + } else if (input.up) { //up + m.energy -= 5 * DRAIN; + this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 1100 * 0.03; + player.force.y -= 2.25 * player.mass * simulation.g; + moveThis(powerUp, this.fieldDrawRadius, 1.8); + moveThis(body, this.fieldDrawRadius, 1.8); + } else { + m.energy -= DRAIN; + this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 800 * 0.03; + player.force.y -= 1.07 * player.mass * simulation.g; // slow upward drift + moveThis(powerUp, this.fieldDrawRadius); + moveThis(body, this.fieldDrawRadius); + } + } else { + //look for nearby objects to make zero-g + function verticalForce(who, range, mag = 1.06) { + for (let i = 0, len = who.length; i < len; ++i) { + sub = Vector.sub(who[i].position, m.pos); + dist = Vector.magnitude(sub); + if (dist < range) { + who[i].force.y -= who[i].mass * (simulation.g * mag); //add a bit more then standard gravity + if (input.left) { //blocks move horizontally with the same force as the player + who[i].force.x -= m.FxAir * who[i].mass / 10; // move player left / a + } else if (input.right) { + who[i].force.x += m.FxAir * who[i].mass / 10; //move player right / d + } + } + + + + // sub = Vector.sub(who[i].position, m.pos); + // dist = Vector.magnitude(sub); + // if (dist < range) who[i].force.y -= who[i].mass * (simulation.g * mag); + } + } + //control horizontal acceleration + m.airSpeedLimit = 400 // 7* player.mass * player.mass + m.FxAir = 0.005 + //control vertical acceleration + if (input.down) { //down + player.force.y -= 0.5 * player.mass * simulation.g; + this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 400 * 0.03; + verticalForce(powerUp, this.fieldDrawRadius, 0.7); + verticalForce(body, this.fieldDrawRadius, 0.7); + } else if (input.up) { //up + m.energy -= 5 * DRAIN; + this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 850 * 0.03; + player.force.y -= 1.45 * player.mass * simulation.g; + verticalForce(powerUp, this.fieldDrawRadius, 1.38); + verticalForce(body, this.fieldDrawRadius, 1.38); + } else { + m.energy -= DRAIN; + this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 650 * 0.03; + player.force.y -= 1.07 * player.mass * simulation.g; // slow upward drift + verticalForce(powerUp, this.fieldDrawRadius); + verticalForce(body, this.fieldDrawRadius); + } + } + + if (m.energy < 0.001) { + m.fieldCDcycle = m.cycle + 120; + m.energy = 0; + } + //add extra friction for horizontal motion + if (input.down || input.up || input.left || input.right) { + Matter.Body.setVelocity(player, { x: player.velocity.x * 0.99, y: player.velocity.y * 0.98 }); + } else { //slow rise and fall + Matter.Body.setVelocity(player, { x: player.velocity.x * 0.99, y: player.velocity.y * 0.98 }); + } + // if (tech.isFreezeMobs) { + // const ICE_DRAIN = 0.0005 + // for (let i = 0, len = mob.length; i < len; i++) { + // if (!mob[i].isMobBullet && !mob[i].shield && !mob[i].isShielded && ((mob[i].distanceToPlayer() + mob[i].radius) < this.fieldDrawRadius)) { + // if (m.energy > ICE_DRAIN * 2) { + // m.energy -= ICE_DRAIN; + // this.fieldDrawRadius -= 2; + // mobs.statusSlow(mob[i], 60) + // } else { + // break; + // } + // } + // } + // } + //draw zero-G range + if (!simulation.isTimeSkipping) { + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, this.fieldDrawRadius, 0, 2 * Math.PI); + ctx.fillStyle = "#f5f5ff"; + ctx.globalCompositeOperation = "difference"; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + } + } + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + this.fieldDrawRadius = 0 + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + this.fieldDrawRadius = 0 + } + m.drawRegenEnergy("rgba(0,0,0,0.2)") + + + // if (tech.isHealAttract) { + // for (let i = 0; i < powerUp.length; i++) { + // if (powerUp[i].name === "heal") { + // //&& Vector.magnitudeSquared(Vector.sub(powerUp[i].position, m.pos)) < 500000 + // let attract = Vector.mult(Vector.normalise(Vector.sub(m.pos, powerUp[i].position)), 0.01 * powerUp[i].mass) + // powerUp[i].force.x += attract.x; + // powerUp[i].force.y += attract.y - powerUp[i].mass * simulation.g; //negate gravity + // Matter.Body.setVelocity(powerUp[i], Vector.mult(powerUp[i].velocity, 0.7)); + // } + // } + // } + + + // powerUp[i].force.x += 0.05 * (dxP / Math.sqrt(dist2)) * powerUp[i].mass; + // powerUp[i].force.y += 0.05 * (dyP / Math.sqrt(dist2)) * powerUp[i].mass - powerUp[i].mass * simulation.g; //negate gravity + // //extra friction + // Matter.Body.setVelocity(powerUp[i], { + // x: powerUp[i].velocity.x * 0.11, + // y: powerUp[i].velocity.y * 0.11 + // }); + + } + } + }, + { + name: "molecular assembler", + description: `use energy to deflect mobs
excess energy used to print ${simulation.molecularMode === 0 ? "spores" : simulation.molecularMode === 1 ? "missiles" : simulation.molecularMode === 2 ? "ice IX" : "drones"}
12 energy per second`, + setDescription() { + return `use energy to deflect mobs
excess energy used to print ${simulation.molecularMode === 0 ? "spores" : simulation.molecularMode === 1 ? "missiles" : simulation.molecularMode === 2 ? "ice IX" : "drones"}
12 energy per second` + }, + + effect: () => { + m.fieldMeterColor = "#ff0" + m.eyeFillColor = m.fieldMeterColor + m.hold = function () { + if (m.energy > m.maxEnergy - 0.02 && m.fieldCDcycle < m.cycle && !input.field && bullet.length < 300 && (m.cycle % 2)) { + if (simulation.molecularMode === 0) { + if (tech.isSporeFlea) { + const drain = 0.18 + (Math.max(bullet.length, 130) - 130) * 0.02 + if (m.energy > drain) { + m.energy -= drain + const speed = m.crouch ? 20 + 8 * Math.random() : 10 + 3 * Math.random() + b.flea({ + x: m.pos.x + 35 * Math.cos(m.angle), + y: m.pos.y + 35 * Math.sin(m.angle) + }, { + x: speed * Math.cos(m.angle), + y: speed * Math.sin(m.angle) + }) + } + } else if (tech.isSporeWorm) { + const drain = 0.18 + (Math.max(bullet.length, 130) - 130) * 0.02 + if (m.energy > drain) { + m.energy -= drain + b.worm({ + x: m.pos.x + 35 * Math.cos(m.angle), + y: m.pos.y + 35 * Math.sin(m.angle) + }) + const SPEED = 2 + 1 * Math.random(); + Matter.Body.setVelocity(bullet[bullet.length - 1], { + x: SPEED * Math.cos(m.angle), + y: SPEED * Math.sin(m.angle) + }); + } + } else { + const drain = 0.095 + (Math.max(bullet.length, 130) - 130) * 0.01 + for (let i = 0, len = Math.random() * 20; i < len; i++) { + if (m.energy > 3 * drain) { + m.energy -= drain + b.spore(m.pos) + } else { + break + } + } + } + } else if (simulation.molecularMode === 1) { + m.energy -= 0.33; + const direction = { x: Math.cos(m.angle), y: Math.sin(m.angle) } + const push = Vector.mult(Vector.perp(direction), 0.08) + b.missile({ x: m.pos.x + 30 * direction.x, y: m.pos.y + 30 * direction.y }, m.angle, -15) + bullet[bullet.length - 1].force.x += push.x * (Math.random() - 0.5) + bullet[bullet.length - 1].force.y += 0.005 + push.y * (Math.random() - 0.5) + // b.missile({ x: m.pos.x, y: m.pos.y - 40 }, -Math.PI / 2 + 0.5 * (Math.random() - 0.5), 0, 1) + } else if (simulation.molecularMode === 2) { + m.energy -= 0.044; + b.iceIX(1) + } else if (simulation.molecularMode === 3) { + if (tech.isDroneRadioactive) { + const drain = 0.8 + (Math.max(bullet.length, 50) - 50) * 0.01 + if (m.energy > drain) { + m.energy -= drain + b.droneRadioactive({ + x: m.pos.x + 30 * Math.cos(m.angle) + 10 * (Math.random() - 0.5), + y: m.pos.y + 30 * Math.sin(m.angle) + 10 * (Math.random() - 0.5) + }, 25) + } + } else { + //every bullet above 100 adds 0.005 to the energy cost per drone + //at 200 bullets the energy cost is 0.45 + 100*0.006 = 1.05 + const drain = (0.45 + (Math.max(bullet.length, 100) - 100) * 0.006) * tech.droneEnergyReduction + if (m.energy > drain) { + m.energy -= drain + b.drone() + } + } + } + } + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + if (tech.isPrinter && m.holdingTarget.isPrinted && input.field) { + // if (Math.random() < 0.004 && m.holdingTarget.vertices.length < 12) m.holdingTarget.vertices.push({ x: 0, y: 0 }) //small chance to increase the number of vertices + m.holdingTarget.radius += Math.min(1.1, 1.3 / m.holdingTarget.mass) //grow up to a limit + const r1 = m.holdingTarget.radius * (1 + 0.12 * Math.sin(m.cycle * 0.11)) + const r2 = m.holdingTarget.radius * (1 + 0.12 * Math.cos(m.cycle * 0.11)) + let angle = (m.cycle * 0.01) % (2 * Math.PI) //rotate the object + let vertices = [] + for (let i = 0, len = m.holdingTarget.vertices.length; i < len; i++) { + angle += 2 * Math.PI / len + vertices.push({ x: m.holdingTarget.position.x + r1 * Math.cos(angle), y: m.holdingTarget.position.y + r2 * Math.sin(angle) }) + } + Matter.Body.setVertices(m.holdingTarget, vertices) + m.definePlayerMass(m.defaultMass + m.holdingTarget.mass * m.holdingMassScale) + } + m.throwBlock(); + } else if ((input.field && m.fieldCDcycle < m.cycle)) { //not hold but field button is pressed + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + if (tech.isPrinter && input.down) { + m.printBlock(); + } else if (m.energy > m.minEnergyToDeflect) { + m.drawField(); + m.pushMobsFacing(); + } + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + } + m.drawRegenEnergy() + } + } + }, + { + name: "plasma torch", + description: "use energy to emit short range plasma
1.5x damage
10 energy per second", + set() { + b.isExtruderOn = false + m.fieldDamage = 1.5 + // m.fieldCDcycleAlternate = 0 + + if (m.plasmaBall) { + m.plasmaBall.reset() + Matter.Composite.remove(engine.world, m.plasmaBall); + } + if (tech.isPlasmaBall) { + const circleRadiusScale = 2 + m.plasmaBall = Bodies.circle(m.pos.x + 10 * Math.cos(m.angle), m.pos.y + 10 * Math.sin(m.angle), 1, { + // collisionFilter: { + // group: 0, + // category: 0, + // mask: 0 //cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield + // }, + isSensor: true, + frictionAir: 0, + alpha: 0.7, + isPopping: false, + isAttached: false, + isOn: false, + drain: 0.0017, + radiusLimit: 10, + damage: 0.8, + setPositionToNose() { + const nose = { x: m.pos.x + 10 * Math.cos(m.angle), y: m.pos.y + 10 * Math.sin(m.angle) } + Matter.Body.setPosition(this, Vector.add(nose, Vector.mult(Vector.normalise(Vector.sub(nose, m.pos)), circleRadiusScale * this.circleRadius))); + }, + fire() { + this.isAttached = false; + const speed = 10 //scale with mass? + Matter.Body.setVelocity(this, { + x: player.velocity.x * 0.4 + speed * Math.cos(m.angle), + y: speed * Math.sin(m.angle) + }); + m.plasmaBall.setPositionToNose() + if (this.circleRadius < 10) this.isPopping = true + }, + scale(scale) { + Matter.Body.scale(m.plasmaBall, scale, scale); //shrink fast + if (this.circleRadius < this.radiusLimit) this.reset() + }, + reset() { + // console.log(this.circleRadius) + const scale = 1 / m.plasmaBall.circleRadius + Matter.Body.scale(m.plasmaBall, scale, scale); //grow + // console.log(this.circleRadius) + // this.circleRadius = 0 + this.alpha = 0.7 + this.isOn = false + this.isPopping = false + // this.isAttached = true; + }, + do() { + if (this.isOn) { + //collisions with map + if (Matter.Query.collides(this, map).length > 0) { + if (this.isAttached) { + this.scale(Math.max(0.9, 0.998 - 0.1 / m.plasmaBall.circleRadius)) + } else { + this.isPopping = true + } + } + if (this.isPopping) { + this.alpha -= 0.03 + if (this.alpha < 0.1) { + this.reset() + } else { + const scale = 1.04 + 4 / Math.max(1, m.plasmaBall.circleRadius) + Matter.Body.scale(m.plasmaBall, scale, scale); //grow + } + // if (this.speed > 2.5) { + // const slow = 0.9 + // Matter.Body.setVelocity(this, { + // x: slow * this.velocity.x, + // y: slow * this.velocity.y + // }); + // } + } + //collisions with mobs + // const whom = Matter.Query.collides(this, mob) + // const dmg = this.damage * m.dmgScale + // for (let i = 0, len = whom.length; i < len; i++) { + // const mobHit = (who) => { + // if (who.alive) { + // if (!this.isAttached && !who.isMobBullet) this.isPopping = true + // who.damage(dmg); + // // if (who.shield) this.scale(Math.max(0.9, 0.99 - 0.5 / m.plasmaBall.circleRadius)) + // if (who.speed > 5) { + // Matter.Body.setVelocity(who, { //friction + // x: who.velocity.x * 0.6, + // y: who.velocity.y * 0.6 + // }); + // } else { + // Matter.Body.setVelocity(who, { //friction + // x: who.velocity.x * 0.93, + // y: who.velocity.y * 0.93 + // }); + // } + // } + // } + // mobHit(whom[i].bodyA) + // mobHit(whom[i].bodyB) + // } + + //damage nearby mobs + const dmg = this.damage * m.dmgScale + const arcList = [] + const damageRadius = circleRadiusScale * this.circleRadius + const dischargeRange = 150 + 1600 * tech.plasmaDischarge + 1.3 * damageRadius + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].alive && (!mob[i].isBadTarget || mob[i].isMobBullet) && !mob[i].isInvulnerable) { + const sub = Vector.magnitude(Vector.sub(this.position, mob[i].position)) + if (sub < damageRadius + mob[i].radius) { + // if (!this.isAttached && !mob[i].isMobBullet) this.isPopping = true + mob[i].damage(dmg); + if (mob[i].speed > 5) { + Matter.Body.setVelocity(mob[i], { x: mob[i].velocity.x * 0.6, y: mob[i].velocity.y * 0.6 }); + } else { + Matter.Body.setVelocity(mob[i], { x: mob[i].velocity.x * 0.93, y: mob[i].velocity.y * 0.93 }); + } + } else if (sub < dischargeRange + mob[i].radius && Matter.Query.ray(map, mob[i].position, this.position).length === 0) { + arcList.push(mob[i]) //populate electrical arc list + } + } + } + for (let i = 0; i < arcList.length; i++) { + if (tech.plasmaDischarge > Math.random()) { + const who = arcList[Math.floor(Math.random() * arcList.length)] + who.damage(dmg * 4); + //draw arcs + const sub = Vector.sub(who.position, this.position) + const unit = Vector.normalise(sub) + let len = 12 + const step = Vector.magnitude(sub) / (len + 2) + let x = this.position.x + let y = this.position.y + ctx.beginPath(); + ctx.moveTo(x, y); + for (let i = 0; i < len; i++) { + x += step * (unit.x + (Math.random() - 0.5)) + y += step * (unit.y + (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + ctx.lineTo(who.position.x, who.position.y); + ctx.strokeStyle = "#88f"; + ctx.lineWidth = 4 + 3 * Math.random(); + ctx.stroke(); + if (who.damageReduction) { + simulation.drawList.push({ + x: who.position.x, + y: who.position.y, + radius: 15, + color: "rgba(150,150,255,0.4)", + time: 15 + }); + } + } + } + + + //slowly slow down if too fast + if (this.speed > 10) { + const scale = 0.998 + Matter.Body.setVelocity(this, { x: scale * this.velocity.x, y: scale * this.velocity.y }); + } + + //graphics + const radius = circleRadiusScale * this.circleRadius * (0.99 + 0.02 * Math.random()) + 3 * Math.random() + const gradient = ctx.createRadialGradient(this.position.x, this.position.y, 0, this.position.x, this.position.y, radius); + const alpha = this.alpha + 0.1 * Math.random() + gradient.addColorStop(0, `rgba(255,255,255,${alpha})`); + gradient.addColorStop(0.35 + 0.1 * Math.random(), `rgba(255,150,255,${alpha})`); + gradient.addColorStop(1, `rgba(255,0,255,${alpha})`); + // gradient.addColorStop(1, `rgba(255,150,255,${alpha})`); + ctx.fillStyle = gradient + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, radius, 0, 2 * Math.PI); + ctx.fill(); + //draw arcs + const unit = Vector.rotate({ x: 1, y: 0 }, Math.random() * 6.28) + let len = 8 + const step = this.circleRadius / len + let x = this.position.x + let y = this.position.y + ctx.beginPath(); + if (Math.random() < 0.5) { + x += step * (unit.x + 6 * (Math.random() - 0.5)) + y += step * (unit.y + 6 * (Math.random() - 0.5)) + len -= 2 + } + if (Math.random() < 0.5) { + x += step * (unit.x + 6 * (Math.random() - 0.5)) + y += step * (unit.y + 6 * (Math.random() - 0.5)) + len -= 2 + } + ctx.moveTo(x, y); + + for (let i = 0; i < len; i++) { + x += step * (unit.x + 1.9 * (Math.random() - 0.5)) + y += step * (unit.y + 1.9 * (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + ctx.strokeStyle = "#88f"; + ctx.lineWidth = 2 * Math.random(); + ctx.stroke(); + } + }, + }); + + Composite.add(engine.world, m.plasmaBall); + // m.plasmaBall.startingVertices = m.plasmaBall.vertices.slice(); + m.hold = function () { + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if (input.field) { //not hold but field button is pressed + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + if (m.fieldCDcycle < m.cycle) { + //field is active + if (!m.plasmaBall.isAttached) { //return ball to player + if (m.plasmaBall.isOn) { + m.plasmaBall.isPopping = true + } else { + m.plasmaBall.isAttached = true + m.plasmaBall.isOn = true + m.plasmaBall.isPopping = false + m.plasmaBall.alpha = 0.7 + m.plasmaBall.setPositionToNose() + // m.plasmaBall.reset() + + } + } else if (m.energy > m.plasmaBall.drain) { //charge up when attached + if (tech.isCapacitor) { + m.energy -= m.plasmaBall.drain * 2; + const scale = 1 + 48 * Math.pow(Math.max(1, m.plasmaBall.circleRadius), -1.8) + Matter.Body.scale(m.plasmaBall, scale, scale); //grow + } else { + m.energy -= m.plasmaBall.drain; + const scale = 1 + 16 * Math.pow(Math.max(1, m.plasmaBall.circleRadius), -1.8) + Matter.Body.scale(m.plasmaBall, scale, scale); //grow + } + if (m.energy > m.maxEnergy) { + m.energy -= m.plasmaBall.drain * 2; + const scale = 1 + 16 * Math.pow(Math.max(1, m.plasmaBall.circleRadius), -1.8) + Matter.Body.scale(m.plasmaBall, scale, scale); //grow + } + m.plasmaBall.setPositionToNose() + + //add friction for player when holding ball, more friction in vertical + // const floatScale = Math.sqrt(m.plasmaBall.circleRadius) + // const friction = 0.0002 * floatScale + // const slowY = (player.velocity.y > 0) ? Math.max(0.8, 1 - friction * player.velocity.y * player.velocity.y) : Math.max(0.98, 1 - friction * Math.abs(player.velocity.y)) //down : up + // Matter.Body.setVelocity(player, { + // x: Math.max(0.95, 1 - friction * Math.abs(player.velocity.x)) * player.velocity.x, + // y: slowY * player.velocity.y + // }); + + // if (player.velocity.y > 7) player.force.y -= 0.95 * player.mass * simulation.g //less gravity when falling fast + // player.force.y -= Math.min(0.95, 0.05 * floatScale) * player.mass * simulation.g; //undo some gravity on up or down + + //float + const slowY = (player.velocity.y > 0) ? Math.max(0.8, 1 - 0.002 * player.velocity.y * player.velocity.y) : Math.max(0.98, 1 - 0.001 * Math.abs(player.velocity.y)) //down : up + Matter.Body.setVelocity(player, { + x: Math.max(0.95, 1 - 0.003 * Math.abs(player.velocity.x)) * player.velocity.x, + y: slowY * player.velocity.y + }); + if (player.velocity.y > 5) { + player.force.y -= 0.9 * player.mass * simulation.g //less gravity when falling fast + } else { + player.force.y -= 0.5 * player.mass * simulation.g; + } + } else { + m.fieldCDcycle = m.cycle + 90; + m.plasmaBall.fire() + } + } + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + if (m.plasmaBall.isAttached) { + m.fieldCDcycle = m.cycle + 30; + m.plasmaBall.fire() + } + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + if (m.plasmaBall.isAttached) { + m.fieldCDcycle = m.cycle + 30; + m.plasmaBall.fire() + } + } + m.drawRegenEnergy("rgba(0, 0, 0, 0.2)") + m.plasmaBall.do() + } + } else if (tech.isExtruder) { + m.hold = function () { + b.isExtruderOn = false + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if (input.field && m.fieldCDcycle < m.cycle) { //not hold but field button is pressed + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + b.extruder(); + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + } + m.drawRegenEnergy("rgba(0, 0, 0, 0.2)") + if (input.field) { + b.wasExtruderOn = true + } else { + b.wasExtruderOn = false + b.canExtruderFire = true + } + ctx.beginPath(); //draw all the wave bullets + for (let i = 1, len = bullet.length; i < len; i++) { //skip the first bullet (which is is oldest bullet) + if (bullet[i].isWave) { + if (bullet[i].isBranch || bullet[i - 1].isBranch) { + ctx.moveTo(bullet[i].position.x, bullet[i].position.y) + } else { + ctx.lineTo(bullet[i].position.x, bullet[i].position.y) + } + } + } + if (b.wasExtruderOn && b.isExtruderOn) ctx.lineTo(m.pos.x + 15 * Math.cos(m.angle), m.pos.y + 15 * Math.sin(m.angle)) + ctx.lineWidth = 4; + ctx.strokeStyle = "#f07" + ctx.stroke(); + ctx.lineWidth = tech.extruderRange; + ctx.strokeStyle = "rgba(255,0,110,0.06)" + ctx.stroke(); + } + // } else if (true) { //plasma sword slash + // const plasmaSweepCycles = 30 + // m.plasmaSweep = 0 + // m.plasmaSlashDirection = m.flipLegs//Math.random() > 0.5 ? 1 : -1; + // m.hold = function () { + // if (m.isHolding) { + // m.drawHold(m.holdingTarget); + // m.holding(); + // m.throwBlock(); + // m.plasmaSweep = 0 + // // } else if (true) { //not hold but field button is pressed + // } else if (input.field && m.fieldCDcycle < m.cycle) { //not hold but field button is pressed + // if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + // m.grabPowerUp(); + // m.lookForPickUp(); + + // //graphics + // if (m.plasmaSweep === 0) m.plasmaSlashDirection = m.flipLegs //Math.random() > 0.5 ? 1 : -1; + // const angle = m.angle //+ 1 * (m.plasmaSweep - plasmaSweepCycles / 2) / plasmaSweepCycles * m.plasmaSlashDirection + // const plasmaSweepCapped = Math.min(m.plasmaSweep, plasmaSweepCycles - 8) / plasmaSweepCycles + // const range = 100 * plasmaSweepCapped + // const arc = 1.3 + // const A = { x: m.pos.x + range * Math.cos(angle - arc), y: m.pos.y + range * Math.sin(angle - arc) } + // const B = { x: m.pos.x + range * Math.cos(angle + arc), y: m.pos.y + range * Math.sin(angle + arc) } + // const controlRange = 500 * plasmaSweepCapped + // const AC = { x: m.pos.x + controlRange * Math.cos(angle - arc / 2), y: m.pos.y + controlRange * Math.sin(angle - arc / 2) } + // const BC = { x: m.pos.x + controlRange * Math.cos(angle + arc / 2), y: m.pos.y + controlRange * Math.sin(angle + arc / 2) } + // const innerControlRange = 300 * plasmaSweepCapped + // const ACinner = { x: m.pos.x + innerControlRange * Math.cos(angle - arc / 2), y: m.pos.y + innerControlRange * Math.sin(angle - arc / 2) } + // const BCinner = { x: m.pos.x + innerControlRange * Math.cos(angle + arc / 2), y: m.pos.y + innerControlRange * Math.sin(angle + arc / 2) } + // ctx.beginPath(); + // ctx.moveTo(A.x, A.y) + // ctx.bezierCurveTo(AC.x, AC.y, BC.x, BC.y, B.x, B.y); //outer curve + // ctx.bezierCurveTo(BCinner.x, BCinner.y, ACinner.x, ACinner.y, A.x, A.y); //inner curve + // // ctx.strokeStyle = "#000" + // // ctx.stroke(); + // ctx.fillStyle = "rgba(255,0,255,0.5)" + // ctx.fill(); + + // //draw control points for graphics reference + // ctx.lineWidth = '0.5' + // ctx.beginPath(); + // ctx.arc(A.x, A.y, 5, 0, 2 * Math.PI); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.arc(B.x, B.y, 5, 0, 2 * Math.PI); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.arc(AC.x, AC.y, 5, 0, 2 * Math.PI); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.arc(BC.x, BC.y, 5, 0, 2 * Math.PI); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.arc(ACinner.x, ACinner.y, 5, 0, 2 * Math.PI); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.arc(BCinner.x, BCinner.y, 5, 0, 2 * Math.PI); + // ctx.stroke(); + + // //mob collision detection + // collideRange = 160 + // const collideCenter = { + // x: m.pos.x + collideRange * Math.cos(angle), + // y: m.pos.y + collideRange * Math.sin(angle) + // } + // ctx.beginPath(); + // ctx.arc(collideCenter.x, collideCenter.y, 140, 0, 2 * Math.PI); + // ctx.stroke(); + + // //push mob away and slow them? + + + // //sweeping motion and cooldown + // m.plasmaSweep++ + // if (m.plasmaSweep > plasmaSweepCycles) { + // m.plasmaSweep = 0 + // if (m.fireCDcycle < m.cycle + 30) m.fieldCDcycle = m.cycle + 30 + // } + // } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + // m.pickUp(); + // m.plasmaSweep = 0 + // } else { + // m.plasmaSweep = 0 + // m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + // } + // m.drawRegenEnergy("rgba(0, 0, 0, 0.2)") + // } + } else { + m.hold = function () { + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if (input.field && m.fieldCDcycle < m.cycle) { //not hold but field button is pressed + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + b.plasma(); + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + } + m.drawRegenEnergy("rgba(0, 0, 0, 0.2)") + } + } + }, + effect() { + m.fieldMeterColor = "#f0f" + m.eyeFillColor = m.fieldMeterColor + this.set(); + } + }, + { + name: "time dilation", + description: `use energy to stop time
1.2x movement and fire rate
12 energy per second`, + set() { + // m.fieldMeterColor = "#0fc" + // m.fieldMeterColor = "#ff0" + m.fieldMeterColor = "#3fe" + m.eyeFillColor = m.fieldMeterColor + m.fieldFx = 1.25 + // m.fieldJump = 1.09 + m.setMovement(); + b.setFireCD() + const timeStop = () => { + m.immuneCycle = m.cycle + 10; //invulnerable to harm while time is stopped, this also disables regen + //draw field everywhere + ctx.globalCompositeOperation = "saturation" + ctx.fillStyle = "#ccc"; + ctx.fillRect(-50000, -50000, 100000, 100000) + ctx.globalCompositeOperation = "source-over" + //stop time + m.isTimeDilated = true; + + function sleep(who) { + for (let i = 0, len = who.length; i < len; ++i) { + if (!who[i].isSleeping) { + who[i].storeVelocity = who[i].velocity + who[i].storeAngularVelocity = who[i].angularVelocity + } + Matter.Sleeping.set(who[i], true) + } + } + sleep(mob); + sleep(body); + sleep(bullet); + simulation.cycle--; //pause all functions that depend on game cycle increasing + } + if (tech.isRewindField) { + this.rewindCount = 0 + m.grabPowerUpRange2 = 300000// m.grabPowerUpRange2 = 200000; + + m.hold = function () { + // console.log(m.fieldCDcycle) + m.grabPowerUp(); + // //grab power ups + // for (let i = 0, len = powerUp.length; i < len; ++i) { + // if ( + // Vector.magnitudeSquared(Vector.sub(m.pos, powerUp[i].position)) < 100000 && + // !simulation.isChoosing && + // (powerUp[i].name !== "heal" || m.health !== m.maxHealth || tech.isOverHeal) + // ) { + // powerUps.onPickUp(powerUp[i]); + // powerUp[i].effect(); + // Matter.Composite.remove(engine.world, powerUp[i]); + // powerUp.splice(i, 1); + // break; //because the array order is messed up after splice + // } + // } + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + m.wakeCheck(); + } else if (input.field && m.fieldCDcycle < m.cycle) { //not hold but field button is pressed + const drain = 0.0014 / (1 + 0.05 * m.coupling) + if (m.energy > drain) m.energy -= drain + m.grabPowerUp(); + if (this.rewindCount === 0) { + m.lookForPickUp(); + } + + if (!m.holdingTarget) { + if (this.rewindCount === 0) { //large upfront energy cost to enter rewind mode + if (m.energy > 0.3) { + m.energy -= 0.3 + } else { + this.rewindCount = 0; + m.resetHistory(); + if (m.fireCDcycle < m.cycle + 60) m.fieldCDcycle = m.cycle + 60 + m.immuneCycle = m.cycle //if you reach the end of the history disable harm immunity + } + } + this.rewindCount += 6; + const DRAIN = 0.003 + let history = m.history[(m.cycle - this.rewindCount) % 600] + if (this.rewindCount > 599 || m.energy < DRAIN) { + this.rewindCount = 0; + m.resetHistory(); + if (m.fireCDcycle < m.cycle + 60) m.fieldCDcycle = m.cycle + 60 + m.immuneCycle = m.cycle //if you reach the end of the history disable harm immunity + } else { + //draw field everywhere + ctx.globalCompositeOperation = "saturation" + ctx.fillStyle = "#ccc"; + ctx.fillRect(-100000, -100000, 200000, 200000) + ctx.globalCompositeOperation = "source-over" + // m.grabPowerUp(); //a second grab power up to make the power ups easier to grab, and they more fast which matches the time theme + m.energy -= DRAIN + if (m.immuneCycle < m.cycle + 5) m.immuneCycle = m.cycle + 5; //player is immune to damage for 5 cycles + Matter.Body.setPosition(player, history.position); + Matter.Body.setVelocity(player, { + x: history.velocity.x, + y: history.velocity.y + }); + if (m.health < history.health) { + m.health = history.health + if (m.health > m.maxHealth) m.health = m.maxHealth + m.displayHealth(); + } + m.yOff = history.yOff + if (m.yOff < 48) { + m.doCrouch() + } else { + m.undoCrouch() + } + if (tech.isRewindBot && !(this.rewindCount % 60)) { + for (let i = 0; i < tech.isRewindBot; i++) { + b.randomBot(m.pos, false, false) + bullet[bullet.length - 1].endCycle = simulation.cycle + 300 + Math.floor(180 * Math.random()) //8-9 seconds + } + } + if (tech.isRewindGrenade && !(this.rewindCount % 30)) { + b.grenade(m.pos, this.rewindCount) //Math.PI / 2 + const who = bullet[bullet.length - 1] + who.endCycle = simulation.cycle + 120 + } + } + } + m.wakeCheck(); + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.pickUp(); + this.rewindCount = 0; + m.wakeCheck(); + } else if (tech.isTimeStop && player.speed < 1 && m.onGround && !input.fire) { + timeStop(); + this.rewindCount = 0; + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + this.rewindCount = 0; + m.wakeCheck(); + } + m.drawRegenEnergy() // this calls m.regenEnergy(); also + } + } else { + m.fieldFire = true; + m.isTimeDilated = false; + m.hold = function () { + if (m.isHolding) { + m.wakeCheck(); + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if (input.field && m.fieldCDcycle < m.cycle) { + const drain = 0.0026 / (1 + 0.03 * m.coupling) + if (m.energy > drain) m.energy -= drain + m.grabPowerUp(); + m.lookForPickUp(); //this drains energy 0.001 + if (m.energy > drain) { + timeStop(); + } else { //holding, but field button is released + m.fieldCDcycle = m.cycle + 120; + m.energy = 0; + m.wakeCheck(); + m.wakeCheck(); + } + } else if (tech.isTimeStop && player.speed < 1 && m.onGround && m.fireCDcycle < m.cycle && !input.fire) { + timeStop(); + //makes things move at 1/5 time rate, but has an annoying flicker for mob graphics, and other minor bugs + // if (!(m.cycle % 4)) { + // // requestAnimationFrame(() => { + // m.wakeCheck(); + // // simulation.timePlayerSkip(1) + // // }); //wrapping in animation frame prevents errors, probably + // ctx.globalCompositeOperation = "saturation" + // ctx.fillStyle = "#ccc"; + // ctx.fillRect(-100000, -100000, 200000, 200000) + // ctx.globalCompositeOperation = "source-over" + // } else { + // timeStop(); + // } + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding, but field button is released + m.wakeCheck(); + m.pickUp(); + } else { + m.wakeCheck(); + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + } + m.drawRegenEnergy() + } + } + }, + effect() { + if (tech.isTimeStop) { + m.fieldHarmReduction = 0.6; + } else { + m.fieldHarmReduction = 1; + } + this.set(); + } + }, + { + name: "metamaterial cloaking", + description: `0.3x damage taken while cloaked
after decloaking 4.5x damage for 2 s
6 energy per second`, + effect: () => { + m.fieldFire = true; + m.fieldMeterColor = "#333"; + m.eyeFillColor = m.fieldMeterColor + m.fieldPhase = 0; + m.isCloak = false + m.fieldDrawRadius = 0 + m.isSneakAttack = true; + m.sneakAttackCycle = 0; + m.enterCloakCycle = 0; + m.drawCloakedM = function () { + m.walk_cycle -= m.flipLegs * m.Vx; + m.pos.x += 4 + m.draw(); + } + m.drawCloak = function () { + m.fieldPhase += 0.007 + const wiggle = 0.15 * Math.sin(m.fieldPhase * 0.5) + ctx.beginPath(); + ctx.ellipse(m.pos.x, m.pos.y, m.fieldDrawRadius * (1 - wiggle), m.fieldDrawRadius * (1 + wiggle), m.fieldPhase, 0, 2 * Math.PI); + ctx.fillStyle = "#fff" + ctx.lineWidth = 2; + ctx.strokeStyle = "#000" + // ctx.stroke() + ctx.globalCompositeOperation = "destination-in"; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + ctx.clip(); + } + m.hold = function () { + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if (input.field && m.fieldCDcycle < m.cycle) { //not hold and field button is pressed + if (m.energy > m.fieldRegen) m.energy -= m.fieldRegen + m.grabPowerUp(); + m.lookForPickUp(); + } else if (m.holdingTarget && m.fieldCDcycle < m.cycle) { //holding target exists, and field button is not pressed + m.pickUp(); + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + } + //not shooting (or using field) enable cloak + if (m.energy < 0.05 && m.fireCDcycle < m.cycle && !input.fire) m.fireCDcycle = m.cycle + if (m.fireCDcycle + 10 < m.cycle && !input.fire) { //automatically cloak if not firing + // const drain = 0.02 + if (!m.isCloak) { //&& m.energy > drain + 0.03 + // m.energy -= drain + m.isCloak = true //enter cloak + m.fieldHarmReduction = 0.3; + m.enterCloakCycle = m.cycle + if (tech.isCloakHealLastHit && m.lastHit > 0) { + const heal = Math.min(0.75 * m.lastHit, m.energy) + m.addHealth(heal); //heal from last hit + m.lastHit = 0 + simulation.drawList.push({ //add dmg to draw queue + x: m.pos.x, + y: m.pos.y, + radius: Math.sqrt(heal) * 200, + color: "rgba(0,255,200,0.6)", + time: 16 + }); + } + if (tech.isIntangible) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType && bullet[i].botType !== "orbit") bullet[i].collisionFilter.mask = cat.map | cat.bullet | cat.mobBullet | cat.mobShield + } + } + } + } else if (m.isCloak) { //exit cloak + m.sneakAttackCycle = m.cycle + m.isCloak = false + m.fieldHarmReduction = 1 + + if (tech.isIntangible) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType && bullet[i].botType !== "orbit") bullet[i].collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield + } + } + if (tech.isCloakStun) { //stun nearby mobs after exiting cloak + let isMobsAround = false + const stunRange = m.fieldDrawRadius * 1.25 + // const drain = 0.01 + // if (m.energy > drain) { + for (let i = 0, len = mob.length; i < len; ++i) { + if (Vector.magnitude(Vector.sub(mob[i].position, m.pos)) < stunRange && Matter.Query.ray(map, mob[i].position, m.pos).length === 0 && !mob[i].isBadTarget) { + isMobsAround = true + mobs.statusStun(mob[i], 120) + } + } + // if (isMobsAround) { + // m.energy -= drain + // simulation.drawList.push({ + // x: m.pos.x, + // y: m.pos.y, + // radius: stunRange, + // color: "hsla(0,50%,100%,0.7)", + // time: 7 + // }); + // } + // } + } + } + + if (m.isCloak) { + m.fieldRange = m.fieldRange * 0.85 + 130 + m.fieldDrawRadius = m.fieldRange * 1.1 //* 0.88 //* Math.min(1, 0.3 + 0.5 * Math.min(1, energy * energy)); + m.drawCloak() + // ctx.globalCompositeOperation = "lighter"; + // m.drawCloakedM() + // ctx.globalCompositeOperation = "source-over"; + + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 35, 0, 2 * Math.PI); + ctx.strokeStyle = "rgba(255,255,255,0.25)";//"rgba(0,0,0,0.7)";//"rgba(255,255,255,0.7)";//"rgba(255,0,100,0.7)"; + ctx.lineWidth = 10 + ctx.stroke(); + + } else if (m.fieldRange < 4000) { + m.fieldRange += 90 + m.fieldDrawRadius = m.fieldRange //* Math.min(1, 0.3 + 0.5 * Math.min(1, energy * energy)); + m.drawCloak() + } + if (tech.isIntangible) { + if (m.isCloak) { + player.collisionFilter.mask = cat.map + let inPlayer = Matter.Query.region(mob, player.bounds) + if (inPlayer.length > 0) { + for (let i = 0; i < inPlayer.length; i++) { + if (m.energy > 0) { + if (!inPlayer[i].isUnblockable) m.energy -= 0.003; + if (inPlayer[i].shield) m.energy -= 0.011; + } + } + } + } else { + player.collisionFilter.mask = cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield //normal collisions + } + } + this.drawRegenEnergyCloaking() + if (m.isSneakAttack && m.sneakAttackCycle + Math.min(100, 0.66 * (m.cycle - m.enterCloakCycle)) > m.cycle) { //show sneak attack status + m.fieldDamage = 4.5 * (1 + 0.05 * m.coupling) + const timeLeft = (m.sneakAttackCycle + Math.min(100, 0.66 * (m.cycle - m.enterCloakCycle)) - m.cycle) * 0.5 + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 32, 0, 2 * Math.PI); + ctx.strokeStyle = "rgba(180,30,70,0.5)";//"rgba(0,0,0,0.7)";//"rgba(255,255,255,0.7)";//"rgba(255,0,100,0.7)"; + ctx.lineWidth = Math.max(Math.min(10, timeLeft), 3); + ctx.stroke(); + // ctx.globalCompositeOperation = "multiply"; + // m.drawCloakedM() + // ctx.globalCompositeOperation = "source-over"; + } else { + m.fieldDamage = 1 + } + } + } + }, + { + name: "pilot wave", + description: `use energy to guide blocks
,
, and
have +3 choices
10 energy per second`, + effect: () => { + m.fieldMeterColor = "#333" + m.eyeFillColor = m.fieldMeterColor + + m.fieldPhase = 0; + m.fieldPosition = { + x: simulation.mouseInGame.x, + y: simulation.mouseInGame.y + } + m.lastFieldPosition = { + x: simulation.mouseInGame.x, + y: simulation.mouseInGame.y + } + m.fieldOn = false; + m.fieldRadius = 0; + m.drop(); + m.hold = function () { + if (tech.isPrinter) { + //spawn blocks if field and crouch + if (input.field && m.fieldCDcycle < m.cycle && input.down && !m.isHolding) { + m.printBlock() + } + //if holding block grow it + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + if (tech.isPrinter && m.holdingTarget.isPrinted && input.field) { + // if (Math.random() < 0.004 && m.holdingTarget.vertices.length < 12) m.holdingTarget.vertices.push({ x: 0, y: 0 }) //small chance to increase the number of vertices + m.holdingTarget.radius += Math.min(1.1, 1.3 / m.holdingTarget.mass) //grow up to a limit + const r1 = m.holdingTarget.radius * (1 + 0.12 * Math.sin(m.cycle * 0.11)) + const r2 = m.holdingTarget.radius * (1 + 0.12 * Math.cos(m.cycle * 0.11)) + let angle = (m.cycle * 0.01) % (2 * Math.PI) //rotate the object + let vertices = [] + for (let i = 0, len = m.holdingTarget.vertices.length; i < len; i++) { + angle += 2 * Math.PI / len + vertices.push({ x: m.holdingTarget.position.x + r1 * Math.cos(angle), y: m.holdingTarget.position.y + r2 * Math.sin(angle) }) + } + Matter.Body.setVertices(m.holdingTarget, vertices) + m.definePlayerMass(m.defaultMass + m.holdingTarget.mass * m.holdingMassScale) + } + m.throwBlock() + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + } + //if releasing field throw it + + } + if (input.field) { + if (m.fieldCDcycle < m.cycle) { + const scale = 25 + const bounds = { + min: { + x: m.fieldPosition.x - scale, + y: m.fieldPosition.y - scale + }, + max: { + x: m.fieldPosition.x + scale, + y: m.fieldPosition.y + scale + } + } + const isInMap = Matter.Query.region(map, bounds).length + // const isInMap = Matter.Query.point(map, m.fieldPosition).length + + if (!m.fieldOn) { // if field was off, and it starting up, teleport to new mouse location + m.fieldOn = true; + // m.fieldPosition = { //smooth the mouse position, set to starting at player + // x: m.pos.x, + // y: m.pos.y + // } + m.fieldPosition = { //smooth the mouse position, set to mouse's current location + x: simulation.mouseInGame.x, + y: simulation.mouseInGame.y + } + m.lastFieldPosition = { //used to find velocity of field changes + x: m.fieldPosition.x, + y: m.fieldPosition.y + } + } else { //when field is on it smoothly moves towards the mouse + m.lastFieldPosition = { //used to find velocity of field changes + x: m.fieldPosition.x, + y: m.fieldPosition.y + } + const smooth = isInMap ? 0.985 : 0.96; + m.fieldPosition = { //smooth the mouse position + x: m.fieldPosition.x * smooth + simulation.mouseInGame.x * (1 - smooth), + y: m.fieldPosition.y * smooth + simulation.mouseInGame.y * (1 - smooth), + } + } + + //grab power ups into the field + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (tech.isEnergyNoAmmo && powerUp[i].name === "ammo") continue + + const dxP = m.fieldPosition.x - powerUp[i].position.x; + const dyP = m.fieldPosition.y - powerUp[i].position.y; + const dist2 = dxP * dxP + dyP * dyP + 200; + // float towards field if looking at and in range or if very close to player + if ( + dist2 < m.fieldRadius * m.fieldRadius && + (m.lookingAt(powerUp[i]) || dist2 < 16000) + ) { + powerUp[i].force.x += 0.05 * (dxP / Math.sqrt(dist2)) * powerUp[i].mass; + powerUp[i].force.y += 0.05 * (dyP / Math.sqrt(dist2)) * powerUp[i].mass - powerUp[i].mass * simulation.g; //negate gravity + //extra friction + Matter.Body.setVelocity(powerUp[i], { x: powerUp[i].velocity.x * 0.11, y: powerUp[i].velocity.y * 0.11 }); + if ( + dist2 < 5000 && + !simulation.isChoosing && + (tech.isOverHeal || powerUp[i].name !== "heal" || m.maxHealth - m.health > 0.01) + // (powerUp[i].name !== "heal" || m.health < 0.94 * m.maxHealth) + // (powerUp[i].name !== "ammo" || b.guns[b.activeGun].ammo !== Infinity) + ) { //use power up if it is close enough + powerUps.onPickUp(powerUp[i]); + powerUp[i].effect(); + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + // m.fieldRadius += 50 + break; //because the array order is messed up after splice + } + } + } + //grab power ups normally too + m.grabPowerUp(); + + if (m.energy > 0.01) { + //find mouse velocity + const diff = Vector.sub(m.fieldPosition, m.lastFieldPosition) + const speed = Vector.magnitude(diff) + const velocity = Vector.mult(Vector.normalise(diff), Math.min(speed, 60)) //limit velocity + let radius, radiusSmooth + if (Matter.Query.ray(map, m.fieldPosition, player.position).length) { //is there something block the player's view of the field + radius = 0 + radiusSmooth = Math.max(0, isInMap ? 0.96 - 0.02 * speed : 0.995); //0.99 + } else { + radius = Math.max(50, 250 - 2 * speed) + radiusSmooth = 0.97 + } + m.fieldRadius = m.fieldRadius * radiusSmooth + radius * (1 - radiusSmooth) + + for (let i = 0, len = body.length; i < len; ++i) { + if (Vector.magnitude(Vector.sub(body[i].position, m.fieldPosition)) < m.fieldRadius && !body[i].isNotHoldable) { + const DRAIN = speed * body[i].mass * 0.0000035 // * (1 + m.energy * m.energy) //drain more energy when you have more energy + if (m.energy > DRAIN) { + m.energy -= DRAIN; + Matter.Body.setVelocity(body[i], velocity); //give block mouse velocity + Matter.Body.setAngularVelocity(body[i], body[i].angularVelocity * 0.8) + // body[i].force.y -= body[i].mass * simulation.g; //remove gravity effects + //blocks drift towards center of pilot wave + const sub = Vector.sub(m.fieldPosition, body[i].position) + const push = Vector.mult(Vector.normalise(sub), 0.0001 * body[i].mass * Vector.magnitude(sub)) + body[i].force.x += push.x + body[i].force.y += push.y - body[i].mass * simulation.g //remove gravity effects + // if (body[i].collisionFilter.category !== cat.bullet) { + // body[i].collisionFilter.category = cat.bullet; + // } + } else { + m.fieldCDcycle = m.cycle + 120; + m.fieldOn = false + m.fieldRadius = 0 + break + } + } + } + + + // m.holdingTarget.collisionFilter.category = cat.bullet; + // m.holdingTarget.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet | cat.mobShield; + // //check every second to see if player is away from thrown body, and make solid + // const solid = function(that) { + // const dx = that.position.x - player.position.x; + // const dy = that.position.y - player.position.y; + // if (that.speed < 3 && dx * dx + dy * dy > 10000 && that !== m.holdingTarget) { + // that.collisionFilter.category = cat.body; //make solid + // that.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet; //can hit player now + // } else { + // setTimeout(solid, 40, that); + // } + // }; + // setTimeout(solid, 200, m.holdingTarget); + + + + // if (tech.isFreezeMobs) { + // for (let i = 0, len = mob.length; i < len; ++i) { + // if (!mob[i].isMobBullet && !mob[i].shield && !mob[i].isShielded && Vector.magnitude(Vector.sub(mob[i].position, m.fieldPosition)) < m.fieldRadius + mob[i].radius) { + // const ICE_DRAIN = 0.0005 + // if (m.energy > ICE_DRAIN) m.energy -= ICE_DRAIN; + // mobs.statusSlow(mob[i], 180) + // } + // } + // } + + ctx.beginPath(); + const rotate = m.cycle * 0.008; + m.fieldPhase += 0.2 // - 0.5 * Math.sqrt(Math.min(m.energy, 1)); + const off1 = 1 + 0.06 * Math.sin(m.fieldPhase); + const off2 = 1 - 0.06 * Math.sin(m.fieldPhase); + ctx.beginPath(); + ctx.ellipse(m.fieldPosition.x, m.fieldPosition.y, 1.2 * m.fieldRadius * off1, 1.2 * m.fieldRadius * off2, rotate, 0, 2 * Math.PI); + ctx.globalCompositeOperation = "exclusion"; //"exclusion" "difference"; + ctx.fillStyle = "#fff"; //"#eef"; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + ctx.beginPath(); + ctx.ellipse(m.fieldPosition.x, m.fieldPosition.y, 1.2 * m.fieldRadius * off1, 1.2 * m.fieldRadius * off2, rotate, 0, 2 * Math.PI * m.energy / m.maxEnergy); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 4; + ctx.stroke(); + } else { + m.fieldCDcycle = m.cycle + 120; + m.fieldOn = false + m.fieldRadius = 0 + } + } else { + m.grabPowerUp(); + } + } else { + m.fieldOn = false + m.fieldRadius = 0 + } + m.drawRegenEnergy("rgba(0,0,0,0.2)") + } + } + }, + { + name: "wormhole", + //wormholes attract blocks and power ups
+ description: "use energy to tunnel through a wormhole
+8% chance to duplicate spawned power ups
7 energy per second", //
bullets may also traverse wormholes + drain: 0, + effect: function () { + m.fieldMeterColor = "#bbf" //"#0c5" + m.eyeFillColor = m.fieldMeterColor + + m.duplicateChance = 0.08 + m.fieldRange = 0 + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + + m.hold = function () { + // m.hole = { //this is reset with each new field, but I'm leaving it here for reference + // isOn: false, + // isReady: true, + // pos1: {x: 0,y: 0}, + // pos2: {x: 0,y: 0}, + // angle: 0, + // unit:{x:0,y:0}, + // } + if (m.hole.isOn) { + // draw holes + m.fieldRange = 0.97 * m.fieldRange + 0.03 * (50 + 10 * Math.sin(simulation.cycle * 0.025)) + const semiMajorAxis = m.fieldRange + 30 + const edge1a = Vector.add(Vector.mult(m.hole.unit, semiMajorAxis), m.hole.pos1) + const edge1b = Vector.add(Vector.mult(m.hole.unit, -semiMajorAxis), m.hole.pos1) + const edge2a = Vector.add(Vector.mult(m.hole.unit, semiMajorAxis), m.hole.pos2) + const edge2b = Vector.add(Vector.mult(m.hole.unit, -semiMajorAxis), m.hole.pos2) + ctx.beginPath(); + ctx.moveTo(edge1a.x, edge1a.y) + ctx.bezierCurveTo(m.hole.pos1.x, m.hole.pos1.y, m.hole.pos2.x, m.hole.pos2.y, edge2a.x, edge2a.y); + ctx.lineTo(edge2b.x, edge2b.y) + ctx.bezierCurveTo(m.hole.pos2.x, m.hole.pos2.y, m.hole.pos1.x, m.hole.pos1.y, edge1b.x, edge1b.y); + ctx.fillStyle = `rgba(255,255,255,${200 / m.fieldRange / m.fieldRange})` //"rgba(0,0,0,0.1)" + ctx.fill(); + ctx.beginPath(); + ctx.ellipse(m.hole.pos1.x, m.hole.pos1.y, m.fieldRange, semiMajorAxis, m.hole.angle, 0, 2 * Math.PI) + ctx.ellipse(m.hole.pos2.x, m.hole.pos2.y, m.fieldRange, semiMajorAxis, m.hole.angle, 0, 2 * Math.PI) + ctx.fillStyle = `rgba(255,255,255,${32 / m.fieldRange})` + ctx.fill(); + + //suck power ups + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (tech.isEnergyNoAmmo && powerUp[i].name === "ammo") continue + //which hole is closer + const dxP1 = m.hole.pos1.x - powerUp[i].position.x; + const dyP1 = m.hole.pos1.y - powerUp[i].position.y; + const dxP2 = m.hole.pos2.x - powerUp[i].position.x; + const dyP2 = m.hole.pos2.y - powerUp[i].position.y; + let dxP, dyP, dist2 + if (dxP1 * dxP1 + dyP1 * dyP1 < dxP2 * dxP2 + dyP2 * dyP2) { + dxP = dxP1 + dyP = dyP1 + } else { + dxP = dxP2 + dyP = dyP2 + } + dist2 = dxP * dxP + dyP * dyP; + if (dist2 < 600000) { //&& !(m.health === m.maxHealth && powerUp[i].name === "heal") + powerUp[i].force.x += 4 * (dxP / dist2) * powerUp[i].mass; // float towards hole + powerUp[i].force.y += 4 * (dyP / dist2) * powerUp[i].mass - powerUp[i].mass * simulation.g; //negate gravity + Matter.Body.setVelocity(powerUp[i], { x: powerUp[i].velocity.x * 0.05, y: powerUp[i].velocity.y * 0.05 }); + if (dist2 < 1000 && !simulation.isChoosing) { //use power up if it is close enough + m.fieldRange *= 0.8 + powerUps.onPickUp(powerUp[i]); + powerUp[i].effect(); + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + break; //because the array order is messed up after splice + } + } + } + //suck and shrink blocks + const suckRange = 500 + const shrinkRange = 100 + const shrinkScale = 0.97; + const slowScale = 0.9 + for (let i = 0, len = body.length; i < len; i++) { + if (!body[i].isNotHoldable) { + const dist1 = Vector.magnitude(Vector.sub(m.hole.pos1, body[i].position)) + const dist2 = Vector.magnitude(Vector.sub(m.hole.pos2, body[i].position)) + if (dist1 < dist2) { + if (dist1 < suckRange) { + const pull = Vector.mult(Vector.normalise(Vector.sub(m.hole.pos1, body[i].position)), 1) + const slow = Vector.mult(body[i].velocity, slowScale) + Matter.Body.setVelocity(body[i], Vector.add(slow, pull)); + //shrink + if (Vector.magnitude(Vector.sub(m.hole.pos1, body[i].position)) < shrinkRange) { + Matter.Body.scale(body[i], shrinkScale, shrinkScale); + if (body[i].mass < 0.05) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + m.fieldRange *= 0.8 + if ((m.fieldMode === 0 || m.fieldMode === 9) && m.immuneCycle < m.cycle) m.energy += 0.02 * m.coupling * level.isReducedRegen + if (tech.isWormholeWorms) { //pandimensional spermia + b.worm(Vector.add(m.hole.pos2, Vector.rotate({ x: m.fieldRange * 0.4, y: 0 }, 2 * Math.PI * Math.random()))) + Matter.Body.setVelocity(bullet[bullet.length - 1], Vector.mult(Vector.rotate(m.hole.unit, Math.PI / 2), -10)); + // for (let i = 0, len = Math.ceil(1.25 * Math.random()); i < len; i++) { + // } + } + break + } + } + } + } else if (dist2 < suckRange) { + const pull = Vector.mult(Vector.normalise(Vector.sub(m.hole.pos2, body[i].position)), 1) + const slow = Vector.mult(body[i].velocity, slowScale) + Matter.Body.setVelocity(body[i], Vector.add(slow, pull)); + //shrink + if (Vector.magnitude(Vector.sub(m.hole.pos2, body[i].position)) < shrinkRange) { + Matter.Body.scale(body[i], shrinkScale, shrinkScale); + if (body[i].mass < 0.05) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + m.fieldRange *= 0.8 + if ((m.fieldMode === 0 || m.fieldMode === 9) && m.immuneCycle < m.cycle) m.energy += 0.02 * m.coupling * level.isReducedRegen + if (m.fieldMode === 0 || m.fieldMode === 9) m.energy += 0.02 * m.coupling * level.isReducedRegen + if (tech.isWormholeWorms) { //pandimensional spermia + b.worm(Vector.add(m.hole.pos1, Vector.rotate({ + x: m.fieldRange * 0.4, + y: 0 + }, 2 * Math.PI * Math.random()))) + Matter.Body.setVelocity(bullet[bullet.length - 1], Vector.mult(Vector.rotate(m.hole.unit, Math.PI / 2), 5)); + // for (let i = 0, len = Math.ceil(1.25 * Math.random()); i < len; i++) { + // } + } + break + } + } + } + } + } + if (tech.isWormHoleBullets) { + //teleport bullets + for (let i = 0, len = bullet.length; i < len; ++i) { //teleport bullets from hole1 to hole2 + if (!bullet[i].botType && !bullet[i].isInHole) { //don't teleport bots + if (Vector.magnitude(Vector.sub(m.hole.pos1, bullet[i].position)) < m.fieldRange) { //find if bullet is touching hole1 + Matter.Body.setPosition(bullet[i], Vector.add(m.hole.pos2, Vector.sub(m.hole.pos1, bullet[i].position))); + m.fieldRange += 5 + bullet[i].isInHole = true + } else if (Vector.magnitude(Vector.sub(m.hole.pos2, bullet[i].position)) < m.fieldRange) { //find if bullet is touching hole1 + Matter.Body.setPosition(bullet[i], Vector.add(m.hole.pos1, Vector.sub(m.hole.pos2, bullet[i].position))); + m.fieldRange += 5 + bullet[i].isInHole = true + } + } + } + // mobs get pushed away + for (let i = 0, len = mob.length; i < len; i++) { + if (Vector.magnitude(Vector.sub(m.hole.pos1, mob[i].position)) < 200) { + const pull = Vector.mult(Vector.normalise(Vector.sub(m.hole.pos1, mob[i].position)), -0.07) + Matter.Body.setVelocity(mob[i], Vector.add(mob[i].velocity, pull)); + } + if (Vector.magnitude(Vector.sub(m.hole.pos2, mob[i].position)) < 200) { + const pull = Vector.mult(Vector.normalise(Vector.sub(m.hole.pos2, mob[i].position)), -0.07) + Matter.Body.setVelocity(mob[i], Vector.add(mob[i].velocity, pull)); + } + } + } + } + + if (m.fieldCDcycle < m.cycle) { + const scale = 60 + const justPastMouse = Vector.add(Vector.mult(Vector.normalise(Vector.sub(simulation.mouseInGame, m.pos)), 50), simulation.mouseInGame) + const sub = Vector.sub(simulation.mouseInGame, m.pos) + const mag = Vector.magnitude(sub) + + if (input.field) { + if (tech.isWormHolePause) { + const drain = m.fieldRegen + 0.000035 + if (m.energy > drain) { + m.energy -= drain + if (m.immuneCycle < m.cycle + 1) m.immuneCycle = m.cycle + 1; //player is immune to damage for 1 cycle + m.isTimeDilated = true; + + function sleep(who) { + for (let i = 0, len = who.length; i < len; ++i) { + if (!who[i].isSleeping) { + who[i].storeVelocity = who[i].velocity + who[i].storeAngularVelocity = who[i].angularVelocity + } + Matter.Sleeping.set(who[i], true) + } + } + sleep(mob); + sleep(body); + sleep(bullet); + simulation.cycle--; //pause all functions that depend on game cycle increasing + Matter.Body.setVelocity(player, { //keep player frozen + x: 0, + y: -55 * player.mass * simulation.g //undo gravity before it is added + }); + player.force.x = 0 + player.force.y = 0 + } else { + m.wakeCheck(); + m.energy = 0; + } + } + + m.grabPowerUp(); + //draw possible wormhole + if (tech.isWormholeMapIgnore && Matter.Query.ray(map, m.pos, justPastMouse).length !== 0) { + this.drain = (0.05 + 0.005 * Math.sqrt(mag)) * 2 + } else { + this.drain = tech.isFreeWormHole ? 0 : 0.05 + 0.005 * Math.sqrt(mag) + } + const unit = Vector.perp(Vector.normalise(sub)) + const where = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle) } + m.fieldRange = 0.97 * m.fieldRange + 0.03 * (50 + 10 * Math.sin(simulation.cycle * 0.025)) + const edge2a = Vector.add(Vector.mult(unit, 1.5 * m.fieldRange), simulation.mouseInGame) + const edge2b = Vector.add(Vector.mult(unit, -1.5 * m.fieldRange), simulation.mouseInGame) + ctx.beginPath(); + ctx.moveTo(where.x, where.y) + ctx.bezierCurveTo(where.x, where.y, simulation.mouseInGame.x, simulation.mouseInGame.y, edge2a.x, edge2a.y); + ctx.moveTo(where.x, where.y) + ctx.bezierCurveTo(where.x, where.y, simulation.mouseInGame.x, simulation.mouseInGame.y, edge2b.x, edge2b.y); + if ( + mag > 250 && m.energy > this.drain && + (tech.isWormholeMapIgnore || Matter.Query.ray(map, m.pos, justPastMouse).length === 0) && + Matter.Query.region(map, { + min: { + x: simulation.mouseInGame.x - scale, + y: simulation.mouseInGame.y - scale + }, + max: { + x: simulation.mouseInGame.x + scale, + y: simulation.mouseInGame.y + scale + } + }).length === 0 + ) { + m.hole.isReady = true; + // ctx.fillStyle = "rgba(255,255,255,0.5)" + // ctx.fill(); + ctx.lineWidth = 1 + ctx.strokeStyle = "#000" + ctx.stroke(); + } else { + m.hole.isReady = false; + ctx.lineWidth = 1 + ctx.strokeStyle = "#000" + ctx.lineDashOffset = 30 * Math.random() + ctx.setLineDash([20, 40]); + ctx.stroke(); + ctx.setLineDash([]); + } + } else { + if (tech.isWormHolePause && m.isTimeDilated) m.wakeCheck(); + + //make new wormhole + if ( + m.hole.isReady && mag > 250 && m.energy > this.drain && + (tech.isWormholeMapIgnore || Matter.Query.ray(map, m.pos, justPastMouse).length === 0) && + Matter.Query.region(map, { + min: { + x: simulation.mouseInGame.x - scale, + y: simulation.mouseInGame.y - scale + }, + max: { + x: simulation.mouseInGame.x + scale, + y: simulation.mouseInGame.y + scale + } + }).length === 0 + ) { + m.energy -= this.drain + m.hole.isReady = false; + m.fieldRange = 0 + Matter.Body.setPosition(player, simulation.mouseInGame); + // simulation.translatePlayerAndCamera(simulation.mouseInGame) //too jerky + m.buttonCD_jump = 0 //this might fix a bug with jumping + const velocity = Vector.mult(Vector.normalise(sub), 20) + Matter.Body.setVelocity(player, { + x: velocity.x, + y: velocity.y - 4 //an extra vertical kick so the player hangs in place longer + }); + if (m.immuneCycle < m.cycle + 5) m.immuneCycle = m.cycle + 5; //player is immune to damage for 1/4 seconds + // move bots to player + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + x: 250 * (Math.random() - 0.5), + y: 250 * (Math.random() - 0.5) + })); + Matter.Body.setVelocity(bullet[i], { + x: 0, + y: 0 + }); + } + } + + //set holes + m.hole.isOn = true; + m.hole.pos1.x = m.pos.x + m.hole.pos1.y = m.pos.y + m.hole.pos2.x = player.position.x + m.hole.pos2.y = player.position.y + m.hole.angle = Math.atan2(sub.y, sub.x) + m.hole.unit = Vector.perp(Vector.normalise(sub)) + + if (tech.isWormholeDamage) { + who = Matter.Query.ray(mob, m.pos, simulation.mouseInGame, 100) + for (let i = 0; i < who.length; i++) { + if (who[i].body.alive) { + mobs.statusDoT(who[i].body, 1, 420) + mobs.statusStun(who[i].body, 360) + } + } + } + } + } + + // if (true && m.energy > 0.5) { //teleport away low mass mobs + // // && !(m.cycle % 1) + // const hit = Matter.Query.region(mob, { + // min: { + // x: m.pos.x - 80, + // y: m.pos.y - 80 + // }, + // max: { + // x: m.pos.x + 80, + // y: m.pos.y + 160 + // } + // }) + + // // find incoming mob with low mass + // for (let i = 0; i < hit.length; i++) { + // if (hit[i].mass < 4 && m.energy > hit[i].mass * 0.06) { + // //is the mob moving towards the player? + + // // console.log('found one', hit[i].mass) + // const unit = Vector.normalise(hit[i].velocity) + // const jump = Vector.mult(unit, 200) + // const where = Vector.add(hit[i].position, jump) + // if (Matter.Query.ray(map, hit[i].position, where).length === 0) { // check if space 180 from mob is clear of body and map + // // m.energy -= hit[i].mass * 0.06 + // // m.fieldCDcycle = m.cycle + 30; + // simulation.drawList.push({ x: hit[i].position.x, y: hit[i].position.y, radius: 20, color: "#fff", time: 16 }); + // Matter.Body.setPosition(hit[i], where); + // simulation.drawList.push({ x: hit[i].position.x, y: hit[i].position.y, radius: 20, color: "#fff", time: 16 }); + // } + // // break + // } + // } + // } + } + // if (input.field && m.fieldCDcycle < m.cycle) { //not hold but field button is pressed + // const justPastMouse = Vector.add(Vector.mult(Vector.normalise(Vector.sub(simulation.mouseInGame, m.pos)), 50), simulation.mouseInGame) + // const scale = 60 + // const sub = Vector.sub(simulation.mouseInGame, m.pos) + // const mag = Vector.magnitude(sub) + // const drain = tech.isFreeWormHole ? 0 : 0.06 + 0.006 * Math.sqrt(mag) + // if (m.hole.isReady && mag > 250 && m.energy > drain) { + // if ( + // Matter.Query.region(map, { + // min: { + // x: simulation.mouseInGame.x - scale, + // y: simulation.mouseInGame.y - scale + // }, + // max: { + // x: simulation.mouseInGame.x + scale, + // y: simulation.mouseInGame.y + scale + // } + // }).length === 0 && + // Matter.Query.ray(map, m.pos, justPastMouse).length === 0 + // // Matter.Query.ray(map, m.pos, simulation.mouseInGame).length === 0 && + // // Matter.Query.ray(map, player.position, simulation.mouseInGame).length === 0 && + // // Matter.Query.ray(map, player.position, justPastMouse).length === 0 + // ) { + // m.energy -= drain + // m.hole.isReady = false; + // m.fieldRange = 0 + // Matter.Body.setPosition(player, simulation.mouseInGame); + // m.buttonCD_jump = 0 //this might fix a bug with jumping + // const velocity = Vector.mult(Vector.normalise(sub), 20) + // Matter.Body.setVelocity(player, { + // x: velocity.x, + // y: velocity.y - 4 //an extra vertical kick so the player hangs in place longer + // }); + // if (m.immuneCycle < m.cycle + 15) m.immuneCycle = m.cycle + 15; //player is immune to damage for 1/4 seconds + // // move bots to player + // for (let i = 0; i < bullet.length; i++) { + // if (bullet[i].botType) { + // Matter.Body.setPosition(bullet[i], Vector.add(player.position, { + // x: 250 * (Math.random() - 0.5), + // y: 250 * (Math.random() - 0.5) + // })); + // Matter.Body.setVelocity(bullet[i], { + // x: 0, + // y: 0 + // }); + // } + // } + + // //set holes + // m.hole.isOn = true; + // m.hole.pos1.x = m.pos.x + // m.hole.pos1.y = m.pos.y + // m.hole.pos2.x = player.position.x + // m.hole.pos2.y = player.position.y + // m.hole.angle = Math.atan2(sub.y, sub.x) + // m.hole.unit = Vector.perp(Vector.normalise(sub)) + + // if (tech.isWormholeDamage) { + // who = Matter.Query.ray(mob, m.pos, simulation.mouseInGame, 100) + // for (let i = 0; i < who.length; i++) { + // if (who[i].body.alive) { + // mobs.statusDoT(who[i].body, 1, 420) + // mobs.statusStun(who[i].body, 360) + // } + // } + // } + // } else { + // //draw failed wormhole + // const unit = Vector.perp(Vector.normalise(Vector.sub(simulation.mouseInGame, m.pos))) + // const where = { x: m.pos.x + 30 * Math.cos(m.angle), y: m.pos.y + 30 * Math.sin(m.angle), } + // m.fieldRange = 0.97 * m.fieldRange + 0.03 * (50 + 10 * Math.sin(simulation.cycle * 0.025)) + // const edge2a = Vector.add(Vector.mult(unit, 1.5 * m.fieldRange), simulation.mouseInGame) + // const edge2b = Vector.add(Vector.mult(unit, -1.5 * m.fieldRange), simulation.mouseInGame) + // ctx.beginPath(); + // ctx.moveTo(where.x, where.y) + // ctx.bezierCurveTo(where.x, where.y, simulation.mouseInGame.x, simulation.mouseInGame.y, edge2a.x, edge2a.y); + // ctx.lineTo(edge2b.x, edge2b.y) + // ctx.bezierCurveTo(simulation.mouseInGame.x, simulation.mouseInGame.y, where.x, where.y, where.x, where.y); + // // ctx.fillStyle = "rgba(255,255,255,0.5)" + // // ctx.fill(); + // ctx.lineWidth = 1 + // ctx.strokeStyle = "#000" + // ctx.lineDashOffset = 30 * Math.random() + // ctx.setLineDash([20, 40]); + // ctx.stroke(); + // ctx.setLineDash([]); + // } + // } + // m.grabPowerUp(); + // } else { + // m.hole.isReady = true; + // } + m.drawRegenEnergy() + } + }, + + // rewind: function() { + // if (input.down) { + // if (input.field && m.fieldCDcycle < m.cycle) { //not hold but field button is pressed + // const DRAIN = 0.01 + // if (this.rewindCount < 289 && m.energy > DRAIN) { + // m.energy -= DRAIN + + + // if (this.rewindCount === 0) { + // const shortPause = function() { + // if (m.defaultFPSCycle < m.cycle) { //back to default values + // simulation.fpsCap = simulation.fpsCapDefault + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // // document.getElementById("dmg").style.transition = "opacity 1s"; + // // document.getElementById("dmg").style.opacity = "0"; + // } else { + // requestAnimationFrame(shortPause); + // } + // }; + // if (m.defaultFPSCycle < m.cycle) requestAnimationFrame(shortPause); + // simulation.fpsCap = 4 //1 is longest pause, 4 is standard + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // m.defaultFPSCycle = m.cycle + // } + + + // this.rewindCount += 10; + // simulation.wipe = function() { //set wipe to have trails + // // ctx.fillStyle = "rgba(255,255,255,0)"; + // ctx.fillStyle = `rgba(221,221,221,${0.004})`; + // ctx.fillRect(0, 0, canvas.width, canvas.height); + // } + // let history = m.history[(m.cycle - this.rewindCount) % 300] + // Matter.Body.setPosition(player, history.position); + // Matter.Body.setVelocity(player, { x: history.velocity.x, y: history.velocity.y }); + // if (history.health > m.health) { + // m.health = history.health + // m.displayHealth(); + // } + // //grab power ups + // for (let i = 0, len = powerUp.length; i < len; ++i) { + // const dxP = player.position.x - powerUp[i].position.x; + // const dyP = player.position.y - powerUp[i].position.y; + // if (dxP * dxP + dyP * dyP < 50000 && !simulation.isChoosing && !(m.health === m.maxHealth && powerUp[i].name === "heal")) { + // powerUps.onPickUp(player.position); + // powerUp[i].effect(); + // Matter.Composite.remove(engine.world, powerUp[i]); + // powerUp.splice(i, 1); + // const shortPause = function() { + // if (m.defaultFPSCycle < m.cycle) { //back to default values + // simulation.fpsCap = simulation.fpsCapDefault + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // // document.getElementById("dmg").style.transition = "opacity 1s"; + // // document.getElementById("dmg").style.opacity = "0"; + // } else { + // requestAnimationFrame(shortPause); + // } + // }; + // if (m.defaultFPSCycle < m.cycle) requestAnimationFrame(shortPause); + // simulation.fpsCap = 3 //1 is longest pause, 4 is standard + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // m.defaultFPSCycle = m.cycle + // break; //because the array order is messed up after splice + // } + // } + // m.immuneCycle = m.cycle + 5; //player is immune to damage for 30 cycles + // } else { + // m.fieldCDcycle = m.cycle + 30; + // // m.resetHistory(); + // } + // } else { + // if (this.rewindCount !== 0) { + // m.fieldCDcycle = m.cycle + 30; + // m.resetHistory(); + // this.rewindCount = 0; + // simulation.wipe = function() { //set wipe to normal + // ctx.clearRect(0, 0, canvas.width, canvas.height); + // } + // } + // m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + // } + // } + // m.drawRegenEnergy() + // }, + }, + { + name: "grappling hook", + description: `use energy to fire a hook that pulls you
0.5x damage taken
9 energy per second`, + effect: () => { + m.fieldFire = true; + // m.holdingMassScale = 0.01; //can hold heavier blocks with lower cost to jumping + // m.fieldMeterColor = "#789"//"#456" + m.eyeFillColor = m.fieldMeterColor + m.fieldHarmReduction = 0.5; //40% reduction + m.grabPowerUpRange2 = 300000 //m.grabPowerUpRange2 = 200000; + + m.hold = function () { + if (m.isHolding) { + m.drawHold(m.holdingTarget); + m.holding(); + m.throwBlock(); + } else if (input.field) { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + if (m.fieldCDcycle < m.cycle) { + if (m.energy > 0.02) m.energy -= 0.02 + b.grapple({ x: m.pos.x + 40 * Math.cos(m.angle), y: m.pos.y + 40 * Math.sin(m.angle) }, m.angle) + if (m.fieldCDcycle < m.cycle + 20) m.fieldCDcycle = m.cycle + 20 + } + m.grabPowerUp(); + } else { + m.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists) + if (tech.isHookDefense && m.energy > 0.15 && m.fieldCDcycle < m.cycle) { + const range = 300 + for (let i = 0; i < mob.length; i++) { + if (!mob[i].isBadTarget && + !mob[i].isInvulnerable && + Vector.magnitude(Vector.sub(m.pos, mob[i].position)) < range && + Matter.Query.ray(map, m.pos, mob[i].position).length === 0 + ) { + m.energy -= 0.1 + if (m.fieldCDcycle < m.cycle + 30) m.fieldCDcycle = m.cycle + 30 + const angle = Math.atan2(mob[i].position.y - player.position.y, mob[i].position.x - player.position.x); + b.harpoon(m.pos, mob[i], angle, 0.75, true, 20) // harpoon(where, target, angle = m.angle, harpoonSize = 1, isReturn = false, totalCycles = 35, isReturnAmmo = true, thrust = 0.1) { + bullet[bullet.length - 1].drain = 0 + const maxCount = 6 + for (let j = maxCount - 1; j > 0; j--) { + b.harpoon(m.pos, mob[i], angle + j * 2 * Math.PI / maxCount, 0.75, true, 10) + bullet[bullet.length - 1].drain = 0 + } + break + } + } + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, range, 0, 2 * Math.PI); + ctx.strokeStyle = "#000"; + ctx.lineWidth = 0.25; + ctx.setLineDash([10, 30]); + ctx.stroke(); + ctx.setLineDash([]); + } + } + m.drawRegenEnergy() + //look for nearby mobs and fire harpoons at them + } + } + }, + ], + //************************************************************************************ + //************************************************************************************ + //************************************* SHIP *************************************** + //************************************************************************************ + //************************************************************************************ + isShipMode: false, + shipMode(thrust = 0.03, drag = 0.99, torque = 1.15, rotationDrag = 0.92) { // m.shipMode() //thrust = 0.03, drag = 0.99, torque = 1.15, rotationDrag = 0.92 + if (!m.isShipMode) { + //if wires remove them + for (let i = 0; i < mob.length; i++) { + if (!mob[i].freeOfWires) mob[i].freeOfWires = true + } + m.isShipMode = true + // simulation.isCheating = true + const points = [{ + x: 29.979168754143455, + y: 4.748337243898336 + }, + { + x: 27.04503734408824, + y: 13.7801138209198 + }, + { + x: 21.462582474874278, + y: 21.462582475257523 + }, + { + x: 13.780113820536943, + y: 27.045037344471485 + }, + { + x: 4.74833724351507, + y: 29.979168754526473 + }, + { + x: -4.748337245049098, + y: 29.979168754526473 + }, + { + x: -13.780113822071026, + y: 27.045037344471485 + }, + { + x: -21.46258247640829, + y: 21.462582475257523 + }, + { + x: -27.045037345621797, + y: 13.7801138209198 + }, + { + x: -29.979168755677012, + y: 4.748337243898336 + }, + { + x: -29.979168755677012, + y: -4.7483372446656045 + }, + { + x: -27.045037345621797, + y: -13.78011382168726 + }, + { + x: -21.46258247640829, + y: -21.462582476024817 + }, + { + x: -13.780113822071026, + y: -27.045037345239006 + }, + { + x: -4.748337245049098, + y: -29.97916875529422 + }, + { + x: 4.74833724351507, + y: -29.97916875529422 + }, + { + x: 13.780113820536943, + y: -27.045037345239006 + }, + { + x: 21.462582474874278, + y: -21.462582476024817 + }, + { + x: 27.04503734408824, + y: -13.78011382168726 + }, + { + x: 29.979168754143455, + y: -4.7483372446656045 + } + ] + // + Matter.Body.setVertices(player, Matter.Vertices.create(points, player)) + player.parts.pop() + player.parts.pop() + player.parts.pop() + player.parts.pop() + // Matter.Body.setDensity(player, 0.01); //extra dense //normal is 0.001 //makes effective life much larger + m.defaultMass = 30 + Matter.Body.setMass(player, m.defaultMass); + player.friction = 0.01 + player.restitution = 0.2 + // player.frictionStatic = 0.1 + // Matter.Body.setInertia(player, Infinity); //disable rotation + + // const circle = Bodies.polygon(player.position.x, player.position.x, 30, 30) + // player.parts[0] = circle + // Matter.Body.setVertices(player.parts[0], Matter.Vertices.create(points, player.parts[0])) + m.spin = 0 + // m.groundControl = () => {} //disable entering ground + m.onGround = false + m.lastOnGroundCycle = 0 + // playerOnGroundCheck = () => {} + m.airControl = () => { //tank controls + player.force.y -= player.mass * simulation.g; //undo gravity + Matter.Body.setVelocity(player, { + x: drag * player.velocity.x, + y: drag * player.velocity.y + }); + if (input.up) { //forward thrust + player.force.x += thrust * Math.cos(m.angle) * m.squirrelJump + player.force.y += thrust * Math.sin(m.angle) * m.squirrelJump + } else if (input.down) { + player.force.x -= 0.6 * thrust * Math.cos(m.angle) + player.force.y -= 0.6 * thrust * Math.sin(m.angle) + } + //rotation + Matter.Body.setAngularVelocity(player, player.angularVelocity * rotationDrag) + if (input.right) { + player.torque += torque + } else if (input.left) { + player.torque -= torque + } + m.angle += m.spin + m.angle = player.angle + } + + + + + + // level.exit.drawAndCheck = () => { //fix this + // if ( + // player.position.x > level.exit.x && + // player.position.x < level.exit.x + 100 && + // player.position.y > level.exit.y - 150 && + // player.position.y < level.exit.y + 40 + // ) { + // level.nextLevel() + // } + // } + m.move = () => { + m.pos.x = player.position.x; + m.pos.y = player.position.y; + m.Vx = player.velocity.x; + m.Vy = player.velocity.y; + + //tracks the last 10s of player information + m.history.splice(m.cycle % 600, 1, { + position: { + x: player.position.x, + y: player.position.y, + }, + velocity: { + x: player.velocity.x, + y: player.velocity.y + }, + yOff: m.yOff, + angle: m.angle, + health: m.health, + energy: m.energy, + activeGun: b.activeGun + }); + } + + m.look = () => { //disable mouse aiming + const scale = 0.8; + m.transSmoothX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale; + m.transSmoothY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale; + + m.transX += (m.transSmoothX - m.transX) * 0.07; + m.transY += (m.transSmoothY - m.transY) * 0.07; + } + + simulation.camera = () => { + const dx = simulation.mouse.x / window.innerWidth - 0.5 //x distance from mouse to window center scaled by window width + const dy = simulation.mouse.y / window.innerHeight - 0.5 //y distance from mouse to window center scaled by window height + const d = Math.max(dx * dx, dy * dy) + simulation.edgeZoomOutSmooth = (1 + 4 * d * d) * 0.04 + simulation.edgeZoomOutSmooth * 0.96 + + ctx.save(); + ctx.translate(canvas.width2, canvas.height2); //center + ctx.scale(simulation.zoom / simulation.edgeZoomOutSmooth, simulation.zoom / simulation.edgeZoomOutSmooth); //zoom in once centered + ctx.translate(-canvas.width2 + m.transX, -canvas.height2 + m.transY); //translate + //calculate in game mouse position by undoing the zoom and translations + simulation.mouseInGame.x = (simulation.mouse.x - canvas.width2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.width2 - m.transX; + simulation.mouseInGame.y = (simulation.mouse.y - canvas.height2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.height2 - m.transY; + } + + m.draw = () => { //just draw the circle + ctx.save(); + ctx.globalAlpha = (m.immuneCycle < m.cycle) ? 1 : 0.5 + ctx.translate(player.position.x, player.position.y); + ctx.rotate(player.angle); + + //thrust + if (input.up) { + var grd2 = ctx.createLinearGradient(0, 0, -150, 0); + // grd2.addColorStop(0, 'rgba(255, 255, 155, 0.8)'); + // grd2.addColorStop(1, 'rgba(255, 200, 0, 0.1)'); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(-18, -25); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(-18, 25); + ctx.lineTo(-50 - 100 * Math.random(), 0); + ctx.fill(); + } else if (input.down) { + var grd2 = ctx.createLinearGradient(0, 0, 80, 0); + grd2.addColorStop(0, 'rgba(150, 200, 255, 0.7)'); + grd2.addColorStop(1, 'rgba(150, 200, 255, 0)'); + ctx.fillStyle = grd2; + ctx.beginPath(); + ctx.moveTo(20, -16); + //10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5) + ctx.lineTo(20, 16); + ctx.lineTo(35 + 43 * Math.random(), 0); + ctx.fill(); + } + + //body + ctx.beginPath(); + ctx.arc(0, 0, 30, 0, 2 * Math.PI); + ctx.fillStyle = m.bodyGradient + ctx.fill(); + ctx.arc(15, 0, 4, 0, 2 * Math.PI); + ctx.strokeStyle = "#333"; + ctx.lineWidth = 2; + ctx.stroke(); + + ctx.restore(); + } + + //fix collisions + collisionChecks = function (event) { + const pairs = event.pairs; + for (let i = 0, j = pairs.length; i != j; i++) { + //mob + (player,bullet,body) collisions + for (let k = 0; k < mob.length; k++) { + if (mob[k].alive && m.alive) { + if (pairs[i].bodyA === mob[k]) { + collideMob(pairs[i].bodyB); + break; + } else if (pairs[i].bodyB === mob[k]) { + collideMob(pairs[i].bodyA); + break; + } + + function collideMob(obj) { + //player + mob collision + if ( + m.immuneCycle < m.cycle && + // (obj === playerBody || obj === playerHead) && + (obj === player) && + !mob[k].isSlowed && !mob[k].isStunned + ) { + mob[k].foundPlayer(); + let dmg = Math.min(Math.max(0.025 * Math.sqrt(mob[k].mass), 0.05), 0.3) * simulation.dmgScale; //player damage is capped at 0.3*dmgScale of 1.0 + if (tech.isRewindAvoidDeath && (m.energy + 0.05) > Math.min(0.95, m.maxEnergy) && dmg > 0.01) { //CPT reversal runs in m.damage, but it stops the rest of the collision code here too + m.damage(dmg); + return + } + m.damage(dmg); + if (tech.isPiezo) m.energy += 20.48 * level.isReducedRegen; + if (tech.isStimulatedEmission) powerUps.ejectTech() + if (mob[k].onHit) mob[k].onHit(); + if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + //extra kick between player and mob //this section would be better with forces but they don't work... + let angle = Math.atan2(player.position.y - mob[k].position.y, player.position.x - mob[k].position.x); + Matter.Body.setVelocity(player, { + x: player.velocity.x + 8 * Math.cos(angle), + y: player.velocity.y + 8 * Math.sin(angle) + }); + Matter.Body.setVelocity(mob[k], { + x: mob[k].velocity.x - 8 * Math.cos(angle), + y: mob[k].velocity.y - 8 * Math.sin(angle) + }); + + if (tech.isAnnihilation && !mob[k].shield && !mob[k].isShielded && !mob[k].isBoss && mob[k].isDropPowerUp && m.energy > 0.34 * m.maxEnergy) { + m.energy -= 0.33 * Math.max(m.maxEnergy, m.energy) + m.immuneCycle = 0; //player doesn't go immune to collision damage + mob[k].death(); + simulation.drawList.push({ //add dmg to draw queue + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: dmg * 2000, + color: "rgba(255,0,255,0.2)", + time: simulation.drawTime + }); + } else { + simulation.drawList.push({ //add dmg to draw queue + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: dmg * 500, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + } + return; + // } + } + //mob + bullet collisions + if (obj.classType === "bullet" && obj.speed > obj.minDmgSpeed) { + obj.beforeDmg(mob[k]); //some bullets do actions when they hits things, like despawn //forces don't seem to work here + let dmg = m.dmgScale * (obj.dmg + 0.15 * obj.mass * Vector.magnitude(Vector.sub(mob[k].velocity, obj.velocity))) + if (tech.isCrit && mob[k].isStunned) dmg *= 4 + mob[k].damage(dmg); + if (mob[k].alive) mob[k].foundPlayer(); + if (mob[k].damageReduction) { + simulation.drawList.push({ //add dmg to draw queue + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: Math.log(dmg + 1.1) * 40 * mob[k].damageReduction + 3, + color: simulation.playerDmgColor, + time: simulation.drawTime + }); + } + return; + } + //mob + body collisions + if (obj.classType === "body" && obj.speed > 6) { + const v = Vector.magnitude(Vector.sub(mob[k].velocity, obj.velocity)); + if (v > 9) { + let dmg = tech.blockDamage * m.dmgScale * v * obj.mass * (tech.isMobBlockFling ? 2 : 1); + if (mob[k].isShielded) dmg *= 0.7 + mob[k].damage(dmg, true); + if (tech.isBlockPowerUps && !mob[k].alive && mob[k].isDropPowerUp && Math.random() < 0.5) { + let type = "ammo" + if (Math.random() < 0.4) { + type = "heal" + } else if (Math.random() < 0.4 && !tech.isSuperDeterminism) { + type = "research" + } + powerUps.spawn(mob[k].position.x, mob[k].position.y, type); + // for (let i = 0, len = Math.ceil(2 * Math.random()); i < len; i++) {} + } + + const stunTime = dmg / Math.sqrt(obj.mass) + if (stunTime > 0.5) mobs.statusStun(mob[k], 30 + 60 * Math.sqrt(stunTime)) + if (mob[k].alive && mob[k].distanceToPlayer2() < 1000000 && !m.isCloak) mob[k].foundPlayer(); + if (tech.fragments && obj.speed > 10 && !obj.hasFragmented) { + obj.hasFragmented = true; + b.targetedNail(obj.position, tech.fragments * 4) + } + if (mob[k].damageReduction) { + simulation.drawList.push({ + x: pairs[i].activeContacts[0].vertex.x, + y: pairs[i].activeContacts[0].vertex.y, + radius: Math.log(dmg + 1.1) * 40 * mob[k].damageReduction + 3, + color: simulation.playerDmgColor, + time: simulation.drawTime + }); + } + return; + } + } + } + } + } + } + } + } + }, +}; \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/powerup.js b/WebGames-master/WebGames-master/n-gon-master/js/powerup.js new file mode 100644 index 00000000..213eb8df --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/powerup.js @@ -0,0 +1,1827 @@ +let powerUp = []; + +const powerUps = { + ejectGraphic(color = "68, 102, 119") { + simulation.drawList.push({ + x: m.pos.x, + y: m.pos.y, + radius: 100, + color: `rgba(${color}, 0.8)`, + time: 4 + }); + simulation.drawList.push({ + x: m.pos.x, + y: m.pos.y, + radius: 75, + color: `rgba(${color}, 0.6)`, + time: 8 + }); + simulation.drawList.push({ + x: m.pos.x, + y: m.pos.y, + radius: 50, + color: `rgba(${color}, 0.3)`, + time: 12 + }); + simulation.drawList.push({ + x: m.pos.x, + y: m.pos.y, + radius: 25, + color: `rgba(${color}, 0.15)`, + time: 16 + }); + }, + healGiveMaxEnergy: false, //for tech 1st ionization energy + orb: { + research(num = 1) { + if (num === 1) return `
` + let text = '' + for (let i = 0; i < num; i++) { + text += `
` + } + text += '
    ' + for (let i = 0; i < num; i++) { + text += '  ' + } + return text + }, + ammo(num = 1) { + switch (num) { + case 1: + return `
` + } + let text = '' + for (let i = 0; i < num; i++) { + text += `
` + } + text += '
    ' + for (let i = 0; i < num; i++) { + text += '  ' + } + return text + }, + heal(num = 1) { + if (powerUps.healGiveMaxEnergy) { + if (num === 1) return `
` + + let text = '' + for (let i = 0; i < num; i++) { + text += `
` + } + text += '
    ' + for (let i = 0; i < num; i++) text += '  ' + return text + } else { + if (num === 1) return `
` + + let text = '' + for (let i = 0; i < num; i++) { + text += `
` + } + text += '
    ' + for (let i = 0; i < num; i++) text += '  ' + return text + } + }, + tech(num = 1) { + return `
tech
` + }, + field(num = 1) { + return `
field
` + }, + gun(num = 1) { + return `
gun
` + }, + gunTech(num = 1) { + return `
guntech
+
guntech
` + }, + fieldTech(num = 1) { + return `
fieldtech
+
fieldtech
` + }, + coupling(num = 1) { + switch (num) { + case 1: + return `
` + } + let text = '' + for (let i = 0; i < num; i++) { + text += `
` + } + text += '
   ' + for (let i = 0; i < num; i++) { + text += '  ' + } + return text + }, + boost(num = 1) { + switch (num) { + case 1: + return `
` + } + let text = '' + for (let i = 0; i < num; i++) { + text += `
` + } + text += '
    ' + for (let i = 0; i < num; i++) { + text += '  ' + } + return text + }, + }, + totalPowerUps: 0, //used for tech that count power ups at the end of a level + do() { }, + setPowerUpMode() { + if (tech.duplicationChance() > 0 || tech.isAnthropicTech) { + powerUps.draw = powerUps.drawDup + if (tech.isPowerUpsVanish) { + if (tech.isHealAttract) { + powerUps.do = () => { + powerUps.dupExplode(); + powerUps.draw(); + powerUps.attractHeal(); + } + } else { + powerUps.do = () => { + powerUps.dupExplode(); + powerUps.draw(); + } + } + } else if (tech.isHealAttract) { + powerUps.do = () => { + powerUps.draw(); + powerUps.attractHeal(); + } + } else { + powerUps.do = () => powerUps.draw(); + } + } else { + powerUps.draw = powerUps.drawCircle + if (tech.isHealAttract) { + powerUps.do = () => { + powerUps.draw(); + powerUps.attractHeal(); + } + } else { + powerUps.do = powerUps.draw + } + } + }, + draw() { }, + drawCircle() { + ctx.globalAlpha = 0.4 * Math.sin(simulation.cycle * 0.15) + 0.6; + for (let i = 0, len = powerUp.length; i < len; ++i) { + ctx.beginPath(); + ctx.arc(powerUp[i].position.x, powerUp[i].position.y, powerUp[i].size, 0, 2 * Math.PI); + ctx.fillStyle = powerUp[i].color; + ctx.fill(); + } + ctx.globalAlpha = 1; + }, + drawDup() { + ctx.globalAlpha = 0.4 * Math.sin(simulation.cycle * 0.15) + 0.6; + for (let i = 0, len = powerUp.length; i < len; ++i) { + ctx.beginPath(); + if (powerUp[i].isDuplicated) { + let vertices = powerUp[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + } else { + ctx.arc(powerUp[i].position.x, powerUp[i].position.y, powerUp[i].size, 0, 2 * Math.PI); + } + ctx.fillStyle = powerUp[i].color; + ctx.fill(); + } + ctx.globalAlpha = 1; + }, + attractHeal() { + for (let i = 0; i < powerUp.length; i++) { //attract heal power ups to player + if (powerUp[i].name === "heal") { + let attract = Vector.mult(Vector.normalise(Vector.sub(m.pos, powerUp[i].position)), 0.015 * powerUp[i].mass) + powerUp[i].force.x += attract.x; + powerUp[i].force.y += attract.y - powerUp[i].mass * simulation.g; //negate gravity + Matter.Body.setVelocity(powerUp[i], Vector.mult(powerUp[i].velocity, 0.7)); + } + } + }, + dupExplode() { + for (let i = 0, len = powerUp.length; i < len; ++i) { + if (powerUp[i].isDuplicated) { + if (Math.random() < 0.003 && !m.isTimeDilated) { // (1-0.003)^240 = chance to be removed after 4 seconds, 240 = 4 seconds * 60 cycles per second + b.explosion(powerUp[i].position, 175 + (11 + 3 * Math.random()) * powerUp[i].size); + if (powerUp[i]) { + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + } + break + } + if (Math.random() < 0.3) { //draw electricity + const mag = Math.max(1, 4 + powerUp[i].size / 5) + let unit = Vector.rotate({ x: mag, y: mag }, 2 * Math.PI * Math.random()) + let path = { x: powerUp[i].position.x + unit.x, y: powerUp[i].position.y + unit.y } + ctx.beginPath(); + ctx.moveTo(path.x, path.y); + for (let i = 0; i < 6; i++) { + unit = Vector.rotate(unit, 4 * (Math.random() - 0.5)) + path = Vector.add(path, unit) + ctx.lineTo(path.x, path.y); + } + ctx.lineWidth = 0.5 + 2 * Math.random(); + ctx.strokeStyle = "#000" + ctx.stroke(); + } + } + } + }, + choose(type, index) { + if (type === "gun") { + b.giveGuns(index) + let text = `
  b.giveGuns("${b.guns[index].name}")` + if (b.inventory.length === 1) text += `
input.key.gun: ["MouseLeft"]` + if (b.inventory.length === 2) text += ` +
input.key.nextGun: ["${input.key.nextGun}","MouseWheel"] +
input.key.previousGun: ["${input.key.previousGun}","MouseWheel"]` + simulation.inGameConsole(text); + } else if (type === "field") { + m.setField(index) + } else if (type === "tech") { + simulation.inGameConsole(`
  tech.giveTech("${tech.tech[index].name}")`); + tech.giveTech(index) + } + powerUps.endDraft(type); + }, + showDraft() { + //disable clicking for 1/2 a second to prevent mistake clicks + document.getElementById("choose-grid").style.pointerEvents = "none"; + document.body.style.cursor = "none"; + setTimeout(() => { + document.body.style.cursor = "auto"; + document.getElementById("choose-grid").style.pointerEvents = "auto"; + document.getElementById("choose-grid").style.transitionDuration = "0s"; + }, 400); + simulation.isChoosing = true; //stops p from un pausing on key down + + if (!simulation.paused) { + if (tech.isNoDraftPause || level.isNoPause) { + document.getElementById("choose-grid").style.opacity = "1" + } else { + simulation.paused = true; + document.getElementById("choose-grid").style.opacity = "1" + } + document.getElementById("choose-grid").style.transitionDuration = "0.5s"; //how long is the fade in on + document.getElementById("choose-grid").style.visibility = "visible" + + requestAnimationFrame(() => { + ctx.fillStyle = `rgba(150,150,150,0.9)`; //`rgba(221,221,221,0.6)`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + }); + } + }, + endDraft(type, isCanceled = false) { //type should be a gun, tech, or field + if (isCanceled) { + if (tech.isCancelDuplication) { + const value = 0.06 + tech.duplication += value + simulation.inGameConsole(`tech.duplicationChance() += ${value}`) + simulation.circleFlare(value); + } + if (tech.isCancelRerolls) { + for (let i = 0, len = 8 + 4 * Math.random(); i < len; i++) { + let spawnType + if (Math.random() < 0.4) { + spawnType = "ammo" + } else if (Math.random() < 0.33 && !tech.isSuperDeterminism) { + spawnType = "research" + } else { + spawnType = "heal" + } + powerUps.spawn(m.pos.x + 40 * (Math.random() - 0.5), m.pos.y + 40 * (Math.random() - 0.5), spawnType, false); + } + } + if (tech.isCancelCouple) powerUps.spawnDelay("coupling", 8) + if (tech.isCancelTech && tech.cancelTechCount === 0 && type !== "entanglement") { + tech.cancelTechCount++ + // powerUps.research.use('tech') + powerUps[type].effect(); + return + } + } + + if (tech.isAnsatz && powerUps.research.count < 1) { + for (let i = 0; i < 3; i++) powerUps.spawn(m.pos.x + 40 * (Math.random() - 0.5), m.pos.y + 40 * (Math.random() - 0.5), "research", false); + } + // document.getElementById("choose-grid").style.display = "none" + document.getElementById("choose-grid").style.visibility = "hidden" + document.getElementById("choose-grid").style.opacity = "0" + + document.body.style.cursor = "none"; + // document.body.style.overflow = "hidden" + // if (m.alive){} + if (simulation.paused) requestAnimationFrame(cycle); + if (m.alive) simulation.paused = false; + simulation.isChoosing = false; //stops p from un pausing on key down + build.unPauseGrid() + if (m.immuneCycle < m.cycle + 15) m.immuneCycle = m.cycle + 15; //player is immune to damage for 30 cycles + if (m.holdingTarget) m.drop(); + }, + animatePowerUpGrab(color) { + simulation.ephemera.push({ + // name: "", + count: 25, //cycles before it self removes + do() { + this.count -= 2 + if (this.count < 5) simulation.removeEphemera(this.name) + + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, Math.max(3, this.count), 0, 2 * Math.PI); + ctx.fillStyle = color + ctx.fill(); + // ctx.strokeStyle = "hsla(200,50%,61%,0.18)"; + // ctx.stroke(); + }, + }) + + }, + instructions: { + name: "instructions", + color: "rgba(100,125,140,0.35)", + size() { + return 130 + }, + effect() { + Matter.Body.setVelocity(player, { x: 0, y: 0 });//power up is so big it launches the player, this stops that + requestAnimationFrame(() => { //add a background behind the power up menu + ctx.fillStyle = `rgba(150,150,150,0.9)`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + }); + powerUps.animatePowerUpGrab('rgba(0, 0, 0,0.6)') + + if (!simulation.paused) { + simulation.paused = true; + simulation.isChoosing = true; //stops p from un pausing on key down + document.body.style.cursor = "auto"; + document.getElementById("choose-grid").style.pointerEvents = "auto"; + document.getElementById("choose-grid").style.transitionDuration = "0s"; + } + //build level info + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + document.getElementById("choose-grid").style.gridTemplateColumns = "800px"//adjust this to increase the width of the whole menu, but mostly the center column + let lore = localSettings.loreCount > 0 ? "lore.unlockTesting() //press T to enter testing" : "" + let text = `
 //console commands
+ powerUps.instructions.effect()     //reproduce this message
+ powerUps.warp.effect()             //warp to any level
+ tech.giveTech("name")              //replace "name" with tech name
+ m.setField("name")                 //standing wave  perfect diamagnetism  negative mass  molecular assembler  plasma torch  time dilation  metamaterial cloaking  pilot wave  wormhole  grappling hook
+ b.giveGuns("name")                 //nail gun  shotgun  super balls  wave  missiles  grenades  spores  drones  foam  harpoon  mine  laser
+ tech.damage *= 2                   //2x damage
+ m.immuneCycle = Infinity           //immune to damage            
+ m.coyoteCycles = Infinity          //air jumps
+ m.energy = 0                       //set energy
+ m.health = 1                       //set health
+ m.maxHealth = 1                    //set max health
+ m.maxEnergy = 1                    //set max energy
+ simulation.enableConstructMode()   //press T to build with mouse
+ ${lore}
+
+ Matter.Body.setPosition(player, simulation.mouseInGame);
+ spawn.bodyRect(simulation.mouseInGame.x, simulation.mouseInGame.y, 50, 50)
+ spawn.randomLevelBoss(simulation.mouseInGame.x, simulation.mouseInGame.y) 
+ powerUps.spawn(m.pos.x, m.pos.y, "name") //tech gun field heal ammo research coupling boost instructions entanglement
+ 
+ //this URL downloads newest version of n-gon 
+ https://codeload.github.com/landgreen/n-gon/zip/refs/heads/master
+
+              chrome                     firefox
+ Win/Linux: Ctrl + Shift + J        Ctrl + Shift + J
+       Mac: Cmd + Option + J        Cmd + Shift + J
exit
` + document.getElementById("choose-grid").innerHTML = text + //show level info + document.getElementById("choose-grid").style.opacity = "1" + document.getElementById("choose-grid").style.transitionDuration = "0.3s"; //how long is the fade in on + document.getElementById("choose-grid").style.visibility = "visible" + document.getElementById("exit").addEventListener("click", () => { + level.unPause() + document.body.style.cursor = "none"; + //reset hide image style + if (localSettings.isHideImages) { + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + } else { + document.getElementById("choose-grid").classList.add('choose-grid'); + document.getElementById("choose-grid").classList.remove('choose-grid-no-images'); + } + }); + }, + }, + warp: { + name: "warp", + color: "rgb(110,155,160)", + size() { + return 30 + }, + load(name) { + level.levels[level.onLevel + 1] = name + powerUps.warp.exit() + level.nextLevel(); + // simulation.clearNow = true + }, + exit() { + level.unPause() + document.body.style.cursor = "none"; + //reset hide image style + if (localSettings.isHideImages) { + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + } else { + document.getElementById("choose-grid").classList.add('choose-grid'); + document.getElementById("choose-grid").classList.remove('choose-grid-no-images'); + } + }, + effect() { + requestAnimationFrame(() => { //add a background behind the power up menu + ctx.fillStyle = `rgba(150,150,150,0.9)`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + }); + powerUps.animatePowerUpGrab('rgba(0, 0, 0,0.6)') + + if (!simulation.paused) { + simulation.paused = true; + simulation.isChoosing = true; //stops p from un pausing on key down + document.body.style.cursor = "auto"; + document.getElementById("choose-grid").style.pointerEvents = "auto"; + document.getElementById("choose-grid").style.transitionDuration = "0s"; + } + //build level info + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + document.getElementById("choose-grid").style.gridTemplateColumns = "200px"//adjust this to increase the width of the whole menu, but mostly the center column + let text = `
WARP
` + text += `
cancel
` + text += `
level.uniqueLevels
` + for (let i = 0; i < level.uniqueLevels.length; i++) { + text += `
${level.uniqueLevels[i]}
` //id="uniqueLevels-warp-${i}" + } + text += `
level.playableLevels
` + for (let i = 0; i < level.playableLevels.length; i++) { + text += `
${level.playableLevels[i]}
` + } + text += `
level.communityLevels
` + for (let i = 0; i < level.communityLevels.length; i++) { + text += `
${level.communityLevels[i]}
` + } + text += `
level.trainingLevels
` + for (let i = 0; i < level.trainingLevels.length; i++) { + text += `
${level.trainingLevels[i]}
` + } + document.getElementById("choose-grid").innerHTML = text + //show level info + document.getElementById("choose-grid").style.opacity = "1" + document.getElementById("choose-grid").style.transitionDuration = "0.3s"; //how long is the fade in on + document.getElementById("choose-grid").style.visibility = "visible" + + document.getElementById("exit").addEventListener("click", () => { + powerUps.warp.exit() + }); + }, + }, + difficulty: { + name: "difficulty", + color: "#000", + size() { + return 80 / Math.pow(localSettings.difficultyMode, 1.5); + }, + effect() { + const initialDifficultyMode = simulation.difficultyMode + requestAnimationFrame(() => { //add a background behind the power up menu + ctx.fillStyle = `rgba(150,150,150,0.9)`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + }); + powerUps.animatePowerUpGrab('rgba(0, 0, 0,0.6)') + + if (!simulation.paused) { + simulation.paused = true; + simulation.isChoosing = true; //stops p from un pausing on key down + document.body.style.cursor = "auto"; + document.getElementById("choose-grid").style.pointerEvents = "auto"; + document.getElementById("choose-grid").style.transitionDuration = "0s"; + } + //build level info + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + document.getElementById("choose-grid").style.gridTemplateColumns = "390px" //adjust this to increase the width of the whole menu, but mostly the center column + + //
0.87x damage, 1.22x damage taken per level
+1 boss on each level
+ //
more mobs per level
faster mobs per level
+ //
0.87x damage, 1.22x damage taken per level
+1 random constraint on each level
+ //
+1 boss on each level
bosses spawn 1 fewer ${powerUps.orb.tech()}
+ //
0.87x damage, 1.22x damage taken per level
+1 random constraint on each level
+ //
0.5x initial damage
2x initial damage taken
+ + let text = `
+
+
+ + + + + + + + + + +
+
+
0.85x damage per level
1.25x damage taken per level
+
spawn more mobs
mobs move faster
+
spawn a 2nd boss each level
bosses spawn 0.5x power ups
+
0.85x damage per level
1.25x damage taken per level
+
+1 random constraint each level
fewer initial power ups
+
0.5x initial damage
2x initial damage taken
+
+1 random constraint each level
fewer ${powerUps.orb.tech()} spawn
+
+
+
${localSettings.difficultyCompleted[1] ? "⚆" : " "}
+
${localSettings.difficultyCompleted[2] ? "⚆" : " "}
+
${localSettings.difficultyCompleted[3] ? "⚆" : " "}
+
${localSettings.difficultyCompleted[4] ? "⚆" : " "}
+
${localSettings.difficultyCompleted[5] ? "⚆" : " "}
+
${localSettings.difficultyCompleted[6] ? "⚇" : " "}
+
${localSettings.difficultyCompleted[7] ? "⚇" : " "}
+
+
+
+ confirm difficulty parameters +
+
` + document.getElementById("choose-grid").innerHTML = text + //show level info + document.getElementById("choose-grid").style.opacity = "1" + document.getElementById("choose-grid").style.transitionDuration = "0.3s"; //how long is the fade in on + document.getElementById("choose-grid").style.visibility = "visible" + document.getElementById("choose-difficulty").addEventListener("click", () => { + level.unPause() + document.body.style.cursor = "none"; + //reset hide image style + if (localSettings.isHideImages) { + document.getElementById("choose-grid").classList.add('choose-grid-no-images'); + document.getElementById("choose-grid").classList.remove('choose-grid'); + } else { + document.getElementById("choose-grid").classList.add('choose-grid'); + document.getElementById("choose-grid").classList.remove('choose-grid-no-images'); + } + if (level.levelsCleared === 0 && initialDifficultyMode !== simulation.difficultyMode) { + //remove and respawn all power ups if difficulty mode was changed + for (let i = 0; i < powerUp.length; ++i) Matter.Composite.remove(engine.world, powerUp[i]); + powerUp = []; + level.initialPowerUps() + simulation.trails(30) + } + }); + + let setDifficultyText = function (isReset = true) { + for (let i = 1; i < 8; i++) { + const id = document.getElementById("constraint-" + i) + if (simulation.difficultyMode < i) { + id.style.opacity = "0.15" + } else { + id.style.opacity = "1" + } + } + if (isReset) { + lore.setTechGoal() + localSettings.difficultyMode = simulation.difficultyMode + localSettings.levelsClearedLastGame = 0 //after changing difficulty, reset run history + localSettings.entanglement = undefined //after changing difficulty, reset stored tech + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + } + setDifficultyText(false) + document.getElementById("difficulty-slider").value = simulation.difficultyMode + document.getElementById("difficulty-slider").addEventListener("input", () => { + simulation.difficultyMode = document.getElementById("difficulty-slider").value + setDifficultyText() + level.setConstraints() + }); + for (let i = 1; i < 8; i++) { + document.getElementById("constraint-" + i).addEventListener("click", () => { + simulation.difficultyMode = i + document.getElementById("difficulty-slider").value = simulation.difficultyMode + setDifficultyText() + level.setConstraints() + }); + } + }, + }, + coupling: { + name: "coupling", + color: "#0ae", //"#0cf", + size() { + return 13; + }, + effect() { + powerUps.animatePowerUpGrab('rgba(0, 170, 238,0.3)') + + m.couplingChange(1) + }, + // spawnDelay(num) { + // let count = num + // let respawnDrones = () => { + // if (count > 0) { + // requestAnimationFrame(respawnDrones); + // if (!simulation.paused && !simulation.isChoosing) { //&& !(simulation.cycle % 2) + // count-- + // const where = { x: m.pos.x + 50 * (Math.random() - 0.5), y: m.pos.y + 50 * (Math.random() - 0.5) } + // powerUps.spawn(where.x, where.y, "coupling"); + // } + // } + // } + // requestAnimationFrame(respawnDrones); + // } + }, + boost: { + name: "boost", + color: "#f55", //"#0cf", + size() { + return 11; + }, + endCycle: 0, + duration: null, //set by "tech: band gap" + damage: null, //set by "tech: band gap" + isDefense: false, + effect() { + powerUps.animatePowerUpGrab('rgba(255, 0, 0, 0.5)') + powerUps.boost.endCycle = simulation.cycle + Math.floor(Math.max(0, powerUps.boost.endCycle - simulation.cycle) * 0.6) + powerUps.boost.duration //duration+seconds plus 2/3 of current time left + }, + draw() { + // console.log(this.endCycle) + // if (powerUps.boost.endCycle > m.cycle) { + // ctx.strokeStyle = "rgba(255,0,0,0.8)" //m.fieldMeterColor; //"rgba(255,255,0,0.2)" //ctx.strokeStyle = `rgba(0,0,255,${0.5+0.5*Math.random()})` + // ctx.beginPath(); + // const arc = (powerUps.boost.endCycle - m.cycle) / powerUps.boost.duration + // ctx.arc(m.pos.x, m.pos.y, 28, m.angle - Math.PI * arc, m.angle + Math.PI * arc); //- Math.PI / 2 + // ctx.lineWidth = 4 + // ctx.stroke(); + // } + + if (powerUps.boost.endCycle > simulation.cycle) { + //gel that acts as if the wind is blowing it when player moves + ctx.save(); + ctx.translate(m.pos.x, m.pos.y); + m.velocitySmooth = Vector.add(Vector.mult(m.velocitySmooth, 0.8), Vector.mult(player.velocity, 0.2)) + ctx.rotate(Math.atan2(m.velocitySmooth.y, m.velocitySmooth.x)) + ctx.beginPath(); + const radius = 40 + const mag = 8 * Vector.magnitude(m.velocitySmooth) + radius + ctx.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2); + ctx.bezierCurveTo(-radius, radius, -radius, 0, -mag, 0); // bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) + ctx.bezierCurveTo(-radius, 0, -radius, -radius, 0, -radius); + const time = Math.min(0.5, (powerUps.boost.endCycle - simulation.cycle) / powerUps.boost.duration) + ctx.fillStyle = `rgba(255,0,200,${time})` + ctx.fill() + ctx.strokeStyle = "#f09" + ctx.lineWidth = 0.3 + 4 * time + ctx.stroke(); + ctx.restore(); + } + }, + }, + research: { + count: 0, + name: "research", + color: "#f7b", + size() { + return 20; + }, + effect() { + powerUps.animatePowerUpGrab('rgba(255, 119, 187,0.3)') + powerUps.research.changeRerolls(1) + }, + isMakingBots: false, //to prevent bot fabrication from running 2 sessions at once + changeRerolls(amount) { + if (amount !== 0) powerUps.research.count += amount + if (tech.isRerollBots && !this.isMakingBots) { + let cycle = () => { + const cost = 2 + Math.floor(b.totalBots() / 3) + if (m.alive && powerUps.research.count >= cost) { + requestAnimationFrame(cycle); + this.isMakingBots = true + + if (!simulation.paused && !simulation.isChoosing && !(simulation.cycle % 60)) { + powerUps.research.count -= cost + b.randomBot() + if (tech.renormalization) { + for (let i = 0; i < cost; i++) { + if (Math.random() < 0.47) { + m.fieldCDcycle = m.cycle + 20; + powerUps.spawn(m.pos.x + 100 * (Math.random() - 0.5), m.pos.y + 100 * (Math.random() - 0.5), "research"); + } + } + } + } + } else { + this.isMakingBots = false + } + } + requestAnimationFrame(cycle); + } + + if (tech.isDeathAvoid && document.getElementById("tech-anthropic")) { + document.getElementById("tech-anthropic").innerHTML = `-${powerUps.research.count}` + } + if (tech.renormalization && Math.random() < 0.47 && amount < 0) { + for (let i = 0, len = -amount; i < len; i++) powerUps.spawn(m.pos.x, m.pos.y, "research"); + } + if (tech.isRerollHaste) { + if (powerUps.research.count === 0) { + tech.researchHaste = 0.5; + b.setFireCD(); + } else { + tech.researchHaste = 1; + b.setFireCD(); + } + } + }, + currentRerollCount: 0, + use(type) { //runs when you actually research a list of selections, type can be field, gun, or tech + if (tech.isJunkResearch && powerUps.research.currentRerollCount < 2) { + tech.addJunkTechToPool(0.01) + } else { + powerUps.research.changeRerolls(-1) + } + if (tech.isResearchDamage) { + tech.damage *= 1.05 + simulation.inGameConsole(`tech.damage *= ${1.05} //peer review`); + tech.addJunkTechToPool(0.01) + } + powerUps.research.currentRerollCount++ + if (tech.isResearchReality) { + m.switchWorlds("Ψ(t) collapse") + simulation.trails() + simulation.inGameConsole(`simulation.amplitude = ${Math.random()}`); + } + powerUps[type].effect(); + }, + }, + heal: { + name: "heal", + color: "#0eb", + size() { + return Math.sqrt(0.1 + 0.25) * 40 * (simulation.healScale ** 0.25) * Math.sqrt(tech.largerHeals * (tech.isHalfHeals ? 0.5 : 1)); //(simulation.healScale ** 0.25) gives a smaller radius as heal scale goes down + }, + effect() { + if (!tech.isEnergyHealth && m.alive) { + powerUps.animatePowerUpGrab('rgba(0, 238, 187,0.25)') + let heal = (this.size / 40 / (simulation.healScale ** 0.25)) ** 2 //simulation.healScale is undone here because heal scale is already properly affected on m.addHealth() + if (heal > 0) { + let overHeal = m.health + heal * simulation.healScale - m.maxHealth //used with tech.isOverHeal + const healOutput = Math.min(m.maxHealth - m.health, heal) * simulation.healScale + m.addHealth(heal); + if (healOutput > 0) simulation.inGameConsole(`
  m.health += ${(healOutput).toFixed(3)}`) //
${m.health.toFixed(3)} + if (tech.isOverHeal && overHeal > 0) { //tech quenching + tech.extraMaxHealth += 0.5 * overHeal //increase max health + m.setMaxHealth(); + simulation.inGameConsole(`
  m.maxHealth += ${(0.3 * overHeal).toFixed(3)}`) + simulation.drawList.push({ //add dmg to draw queue + x: m.pos.x, + y: m.pos.y, + radius: overHeal * 100 * simulation.healScale, + color: "#0eb", + time: simulation.drawTime + }); + + // overHeal *= 2 //double the over heal converted to max health + // //make sure overHeal doesn't kill player + // if (m.health - overHeal * m.defense() < 0) overHeal = m.health - 0.01 + // if (overHeal > m.maxHealth) overHeal = m.maxHealth //just in case overHeal gets too big + // tech.extraMaxHealth += overHeal //increase max health + // m.setMaxHealth(); + // m.damage(overHeal); + // overHeal *= m.defense() // account for defense after m.damage() so the text log is accurate + // simulation.inGameConsole(`
  m.health -= ${(overHeal).toFixed(3)}`) //
${m.health.toFixed(3)} + // simulation.drawList.push({ //add dmg to draw queue + // x: m.pos.x, + // y: m.pos.y, + // radius: overHeal * 500 * simulation.healScale, + // color: simulation.mobDmgColor, + // time: simulation.drawTime + // }); + } else if (overHeal > 0.2) { //if leftover heals spawn a new spammer heal power up + requestAnimationFrame(() => { + powerUps.directSpawn(this.position.x, this.position.y, "heal", true, Math.min(1, overHeal) * 40 * (simulation.healScale ** 0.25))// directSpawn(x, y, name, moving = true, mode = null, size = powerUps[name].size()) { + }); + } + if (tech.isHealBrake) { + const totalTime = 1020 + //check if you already have this effect + let foundActiveEffect = false + for (let i = 0; i < simulation.ephemera.length; i++) { + if (simulation.ephemera[i].name === "healPush") { + foundActiveEffect = true + simulation.ephemera[i].count = 0.5 * simulation.ephemera[i].count + totalTime //add time + simulation.ephemera[i].scale = 0.5 * (simulation.ephemera[i].scale + Math.min(Math.max(0.6, heal * 6), 2.3)) //take average of scale + } + } + if (!foundActiveEffect) { + simulation.ephemera.push({ + name: "healPush", + count: totalTime, //cycles before it self removes + range: 0, + scale: Math.min(Math.max(0.7, heal * 4), 2.2), //typically heal is 0.35 + do() { + this.count-- + if (this.count < 0) simulation.removeEphemera(this.name) + this.range = this.range * 0.99 + 0.01 * (300 * this.scale + 100 * Math.sin(m.cycle * 0.022)) + if (this.count < 120) this.range -= 5 * this.scale + this.range = Math.max(this.range, 1) //don't go negative + // const range = 300 + 100 * Math.sin(m.cycle * 0.022) + for (let i = 0; i < mob.length; i++) { + const distance = Vector.magnitude(Vector.sub(m.pos, mob[i].position)) + if (distance < this.range) { + const cap = mob[i].isShielded ? 3 : 1 + if (mob[i].speed > cap && Vector.dot(mob[i].velocity, Vector.sub(m.pos, mob[i].position)) > 0) { // if velocity is directed towards player + Matter.Body.setVelocity(mob[i], Vector.mult(Vector.normalise(mob[i].velocity), cap)); //set velocity to cap, but keep the direction + } + } + } + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, this.range, 0, 2 * Math.PI); + ctx.fillStyle = "hsla(200,50%,61%,0.18)"; + ctx.fill(); + }, + }) + } + } + } + } + if (powerUps.healGiveMaxEnergy) { + tech.healMaxEnergyBonus += 0.14 * tech.largerHeals * (tech.isHalfHeals ? 0.5 : 1) + m.setMaxEnergy(); + } + }, + spawn(x, y, size) { //used to spawn a heal with a specific size / heal amount, not normally used + powerUps.directSpawn(x, y, "heal", false, size) + if (!level.isNextLevelPowerUps && Math.random() < tech.duplicationChance()) { + powerUps.directSpawn(x, y, "heal", false, size) + powerUp[powerUp.length - 1].isDuplicated = true + } + } + }, + ammo: { + name: "ammo", + color: "#467", + size() { + return 17; + }, + effect() { + const couplingExtraAmmo = (m.fieldMode === 10 || m.fieldMode === 0) ? 1 + 0.04 * m.coupling : 1 + if (b.inventory.length > 0) { + powerUps.animatePowerUpGrab('rgba(68, 102, 119,0.25)') + if (tech.isAmmoForGun && (b.activeGun !== null && b.activeGun !== undefined)) { //give extra ammo to one gun only with tech logistics + const name = b.guns[b.activeGun] + if (name.ammo !== Infinity) { + if (tech.ammoCap) { + name.ammo = Math.ceil(2 * name.ammoPack * tech.ammoCap * couplingExtraAmmo) + } else { + name.ammo += Math.ceil(2 * (Math.random() + Math.random()) * name.ammoPack * couplingExtraAmmo) + } + } + } else { //give ammo to all guns in inventory + for (let i = 0, len = b.inventory.length; i < len; i++) { + const name = b.guns[b.inventory[i]] + if (name.ammo !== Infinity) { + if (tech.ammoCap) { + name.ammo = Math.ceil(name.ammoPack * tech.ammoCap * couplingExtraAmmo) + } else { //default ammo behavior + name.ammo += Math.ceil((Math.random() + Math.random()) * name.ammoPack * couplingExtraAmmo) + } + } + } + } + simulation.updateGunHUD(); + } + } + }, + cancelText(type) { + if (tech.isSuperDeterminism) { + return `
` + } else if (tech.isCancelTech && tech.cancelTechCount === 0) { + return `
randomize
` + } else if (level.levelsCleared === 0 && localSettings.isTrainingNotAttempted && b.inventory.length === 0) { //don't show cancel if on initial level and haven't done tutorial + return `` + } else { + return `
cancel
` + } + }, + researchText(type) { + let text = "" + if (type === "entanglement") { + text += `
entanglement
` + } else if (tech.isJunkResearch && powerUps.research.currentRerollCount < 2) { + text += `
` // style = "margin-left: 192px; margin-right: -192px;" + text += `
` + text += `
` + text += `
  pseudoscience
` + } else if (powerUps.research.count > 0) { + text += `
` // style = "margin-left: 192px; margin-right: -192px;" + text += `
` + for (let i = 0, len = Math.min(powerUps.research.count, 30); i < len; i++) text += `
` + text += `
  ${tech.isResearchReality ? "alternate reality" : "research"}
` + } else { + text += `
` + } + return text + }, + researchAndCancelText(type) { + let text = `
` + if (type === "entanglement") { + text += `entanglement` + } else if (tech.isJunkResearch && powerUps.research.currentRerollCount < 2) { + text += `` // style = "margin-left: 192px; margin-right: -192px;" + text += `
` + text += `
` + text += `
  ${tech.isResearchReality ? "alternate reality" : "research"}
` + } else if (powerUps.research.count > 0) { + text += `` // style = "margin-left: 192px; margin-right: -192px;" + text += `
` + let researchCap = 18 + if (tech.isCancelTech && tech.cancelTechCount === 0) researchCap -= 2 + if (canvas.width < 1951) researchCap -= 3 + if (canvas.width < 1711) researchCap -= 4 + for (let i = 0, len = Math.min(powerUps.research.count, researchCap); i < len; i++) { + text += `
` + } + text += `
  ${tech.isResearchReality ? "alternate reality" : "research"}
` + } else { + text += `research` //‌ + } + if (tech.isSuperDeterminism) { + text += `cancel` + } else if (tech.isCancelTech && tech.cancelTechCount === 0) { + text += `randomize` + } else if (level.levelsCleared === 0 && localSettings.isTrainingNotAttempted && b.inventory.length === 0) { + text += `` //don't show cancel if on initial level and haven't done tutorial + } else { + text += `cancel` + } + return text + "
" + }, + buildColumns(totalChoices, type) { + let width + if (canvas.width < 1710) { + width = "285px" + } else if (canvas.width < 1950) { + width = "340px" + } else { + width = "384px" + } + + let text = "" + if (localSettings.isHideImages) { + document.getElementById("choose-grid").style.gridTemplateColumns = width + text += powerUps.researchAndCancelText(type) + } else if (totalChoices === 0) { + document.getElementById("choose-grid").style.gridTemplateColumns = width + text += powerUps.researchAndCancelText(type) + } else if (totalChoices === 1 || canvas.width < 1200) { + document.getElementById("choose-grid").style.gridTemplateColumns = width + text += powerUps.researchAndCancelText(type) + // console.log('hi') + // text += powerUps.cancelText(type) + // text += powerUps.researchText(type) + } else if (totalChoices === 2) { + document.getElementById("choose-grid").style.gridTemplateColumns = `repeat(2, ${width})` + text += powerUps.researchText(type) + text += powerUps.cancelText(type) + } else { + document.getElementById("choose-grid").style.gridTemplateColumns = `repeat(3, ${width})` + text += "
" + text += powerUps.researchText(type) + text += powerUps.cancelText(type) + } + return text + }, + hideStyle: `style="height:auto; border: none; background-color: transparent;"`, + gunText(choose, click) { + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/gun/${b.guns[choose].name}.webp');"` + return `
+
+
  ${b.guns[choose].name}
+ ${b.guns[choose].descriptionFunction()}
` + }, + fieldText(choose, click) { + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/field/${m.fieldUpgrades[choose].name}${choose === 0 ? Math.floor(Math.random() * 10) : ""}.webp');"` + return `
+
+
  ${m.fieldUpgrades[choose].name}
+ ${m.fieldUpgrades[choose].description}
` + }, + techText(choose, click) { + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages || tech.tech[choose].isLore ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + return `
+
+
  ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + }, + instantTechText(choose, click) { + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages || tech.tech[choose].isLore ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + //
+ return `
+
+
  ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + }, + skinTechText(choose, click) { + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + return `
+
+
+ +
+
+
+         ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + }, + fieldTechText(choose, click) { + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + return `
+
+
+ +
+
+
+           ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + }, + gunTechText(choose, click) { + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + return `
+
+
+ +
+
+
+           ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + }, + junkTechText(choose, click) { + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-size: contain;background-repeat: no-repeat;background-image: url('img/junk.webp');"` + if (!localSettings.isHideImages) { + // setTimeout(() => { //delay so that the html element exists + // if (tech.tech[choose].url === undefined) { //if on url has been set yet + // const url = `https://api.openverse.engineering/v1/images/?q=${tech.tech[choose].name}`; + // fetch(url, { signal: AbortSignal.timeout(1000) }) //give up if it takes over 1 second + // .then((response) => response.json()) + // .then((responseJson) => { + // if (responseJson.results.length > 0) { + // const index = Math.floor(Math.random() * responseJson.results.length) //randomly choose from the images + // tech.tech[choose].url = responseJson.results[index].url //store the url + // document.getElementById(`junk-${choose}`).style.backgroundImage = `url('${tech.tech[choose].url}')` //make the url the background image + // } + // }); + // } else { + // document.getElementById(`junk-${choose}`).style.backgroundImage = `url('${tech.tech[choose].url}')` + // } + // }, 1); + // setTimeout(() => { //delay so that the html element exists + // document.getElementById(`junk-${choose}`).style.backgroundImage = `url('${tech.tech[choose].url}')` + // }, 1); + } + return `
+
+
  ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + }, + incoherentTechText(choose, click) { + // text += `
${tech.tech[choose].name} - incoherent
` + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + return `
+
+
incoherent


+
` + }, + gun: { + name: "gun", + color: "#26a", + size() { + return 35; + }, + effect() { + if (m.alive) { + let options = []; + for (let i = 0; i < b.guns.length; i++) { + if (!b.guns[i].have) options.push(i); + } + // console.log(options.length) + if (options.length > 0 || !tech.isSuperDeterminism) { + let totalChoices = 2 + tech.extraChoices + 3 * (m.fieldMode === 8) - level.fewerChoices + if (tech.isCancelTech && tech.cancelTechCount === 1) { + totalChoices *= 3 + tech.cancelTechCount++ + } + if (tech.isDeterminism) totalChoices = 1 + totalChoices = Math.min(totalChoices, options.length) + function removeOption(index) { + for (let i = 0; i < options.length; i++) { + if (options[i] === index) { + options.splice(i, 1) //remove a previous choice from option pool + return + } + } + } + //check for guns that were a choice last time and remove them + for (let i = 0; i < b.guns.length; i++) { + if (options.length - 1 < totalChoices) break //you have to repeat choices if there are not enough choices left to display + if (b.guns[i].isRecentlyShown) removeOption(i) + } + for (let i = 0; i < b.guns.length; i++) b.guns[i].isRecentlyShown = false //reset recently shown back to zero + // if (options.length > 0) { + let text = powerUps.buildColumns(totalChoices, "gun") + for (let i = 0; i < totalChoices; i++) { + const choose = options[Math.floor(Math.seededRandom(0, options.length))] //pick an element from the array of options + // text += `
  ${b.guns[choose].name}
${b.guns[choose].description}
` + text += powerUps.gunText(choose, `powerUps.choose('gun',${choose})`) + + b.guns[choose].isRecentlyShown = true + removeOption(choose) + if (options.length < 1) break + } + if (tech.isExtraBotOption) { + const botTech = [] //make an array of bot options + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isBotTech && tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed()) botTech.push(i) + } + if (botTech.length > 0) { //pick random bot tech + const choose = botTech[Math.floor(Math.random() * botTech.length)]; + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + text += `
+
+
⭓▸●■   ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + } + } + if (tech.isOneGun && b.inventory.length > 0) text += `
replaces your current gun
` + document.getElementById("choose-grid").innerHTML = text + powerUps.showDraft(); + } + // } + } + }, + }, + field: { + name: "field", + color: "#0cf", + size() { + return 45; + }, + effect() { + if (m.alive) { + let options = []; + for (let i = 1; i < m.fieldUpgrades.length; i++) { //skip field emitter + if (i !== m.fieldMode) options.push(i); + } + let totalChoices = 2 + tech.extraChoices + 3 * (m.fieldMode === 8) - level.fewerChoices + if (tech.isCancelTech && tech.cancelTechCount === 1) { + totalChoices *= 3 + tech.cancelTechCount++ + } + if (tech.isDeterminism) totalChoices = 1 + totalChoices = Math.max(1, Math.min(totalChoices, options.length)) + function removeOption(index) { + for (let i = 0; i < options.length; i++) { + if (options[i] === index) { + options.splice(i, 1) //remove a previous choice from option pool + return + } + } + } + //check for fields that were a choice last time and remove them + for (let i = 0; i < m.fieldUpgrades.length; i++) { + if (options.length - 1 < totalChoices) break //you have to repeat choices if there are not enough choices left to display + if (m.fieldUpgrades[i].isRecentlyShown) removeOption(i) + } + for (let i = 0; i < m.fieldUpgrades.length; i++) m.fieldUpgrades[i].isRecentlyShown = false //reset recently shown back to zero + + if (options.length > 0 || tech.isExtraBotOption) { + let text = powerUps.buildColumns(totalChoices, "field") + for (let i = 0; i < totalChoices; i++) { + const choose = options[Math.floor(Math.seededRandom(0, options.length))] //pick an element from the array of options + //text += `
  ${m.fieldUpgrades[choose].name}
${m.fieldUpgrades[choose].description}
` //default + text += powerUps.fieldText(choose, `powerUps.choose('field',${choose})`) + m.fieldUpgrades[choose].isRecentlyShown = true + removeOption(choose) + if (options.length < 1) break + } + if (tech.isExtraBotOption) { + const botTech = [] //make an array of bot options + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isBotTech && tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed()) botTech.push(i) + } + if (botTech.length > 0) { //pick random bot tech + const choose = botTech[Math.floor(Math.random() * botTech.length)]; + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + text += `
+
+
⭓▸●■   ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + } + } + document.getElementById("choose-grid").innerHTML = text + powerUps.showDraft(); + } + } + }, + }, + tech: { + name: "tech", + color: "hsl(246,100%,77%)", //"#a8f", + size() { + return 42; + }, + effect() { + if (m.alive) { + // powerUps.animatePowerUpGrab('hsla(246, 100%, 77%,0.5)') + let options = []; //generate all options + optionLengthNoDuplicates = 0 + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isBanished) { + if (tech.tech[i].frequency > 0) optionLengthNoDuplicates++ + for (let j = 0, len = tech.tech[i].frequency; j < len; j++) options.push(i); + } + } + function removeOption(index) { + for (let i = options.length - 1; i > -1; i--) { + if (index === options[i]) { + options.splice(i, 1) //remove all copies of that option form the options array (some tech are in the options array multiple times because of frequency) + optionLengthNoDuplicates-- + } + if (options.length < 1) return; + } + } + //set total choices + let totalChoices = 3 + tech.extraChoices + 3 * (m.fieldMode === 8) - level.fewerChoices + if (tech.isCancelTech && tech.cancelTechCount === 1) { + totalChoices *= 3 + tech.cancelTechCount++ + } + if (tech.isDeterminism) totalChoices = 1 + totalChoices = Math.max(1, Math.min(totalChoices, options.length)) + + if (optionLengthNoDuplicates < totalChoices + 1) { //if not enough options for all the choices + totalChoices = optionLengthNoDuplicates + if (tech.isBanish) { //when you run out of options eject banish + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].name === "decoherence") powerUps.ejectTech(i, true) + } + simulation.inGameConsole(`decoherence tech ejected
options reset`) + } + } + if (tech.tooManyTechChoices) { + tech.tooManyTechChoices = false + totalChoices = optionLengthNoDuplicates + } + if (optionLengthNoDuplicates > totalChoices) { //check for tech that were a choice last time and remove them + for (let i = 0; i < tech.tech.length; i++) { + if (optionLengthNoDuplicates > totalChoices) { + if (tech.tech[i].isRecentlyShown) removeOption(i) + } else { + break //you have to repeat choices if there are not enough choices left to display + } + + } + } + for (let i = 0; i < tech.tech.length; i++) tech.tech[i].isRecentlyShown = false //reset recently shown back to zero + if (options.length > 0) { + let text = powerUps.buildColumns(totalChoices, "tech") + + addTech = (choose) => { + if (tech.tech[choose].isFieldTech) { + text += powerUps.fieldTechText(choose, `powerUps.choose('tech',${choose})`) + } else if (tech.tech[choose].isGunTech) { + text += powerUps.gunTechText(choose, `powerUps.choose('tech',${choose})`) + } else if (tech.tech[choose].isJunk) { + text += powerUps.junkTechText(choose, `powerUps.choose('tech',${choose})`) + } else if (tech.tech[choose].isSkin) { + text += powerUps.skinTechText(choose, `powerUps.choose('tech',${choose})`) + } else if (tech.tech[choose].isInstant) { + text += powerUps.instantTechText(choose, `powerUps.choose('tech',${choose})`) + } else { //normal tech + text += powerUps.techText(choose, `powerUps.choose('tech',${choose})`) + } + } + if (tech.isRetain) { + for (let i = 0, len = powerUps.retainList.length; i < len; i++) { + //find index from name and add tech to options + for (let j = 0, len = tech.tech.length; j < len; j++) { + if (tech.tech[j].name === powerUps.retainList[i] && tech.tech[j].count < tech.tech[j].maxCount && tech.tech[j].allowed() && tech.tech[j].frequency > 0) { //&& !tech.tech[j].isRecentlyShown + addTech(j) + } + } + } + } + for (let i = 0; i < totalChoices; i++) { + if (options.length < 1) break + if (Math.random() < tech.junkChance + level.junkAdded) { // choose is set to a random JUNK tech + const list = [] + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].isJunk) list.push(i) + } + chooseJUNK = list[Math.floor(Math.random() * list.length)] + if (tech.isRetain) powerUps.retainList.push(tech.tech[chooseJUNK].name) + text += powerUps.junkTechText(chooseJUNK, `powerUps.choose('tech',${chooseJUNK})`) + } else { + const choose = options[Math.floor(Math.seededRandom(0, options.length))] //pick an element from the array of options + if (tech.isBanish) { + tech.tech[choose].isBanished = true + if (i === 0) simulation.inGameConsole(`options.length = ${optionLengthNoDuplicates} //removed from pool by decoherence`) + } + removeOption(choose) //remove from future options pool to avoid repeats on this selection + + //this flag prevents this option from being shown the next time you pick up a tech power up + //check if not extra choices from "path integral" + tech.tech[choose].isRecentlyShown = true + if (tech.isRetain && !powerUps.retainList.includes(tech.tech[choose].name)) powerUps.retainList.push(tech.tech[choose].name) + addTech(choose) + } + } + if (tech.isExtraBotOption) { + const botTech = [] //make an array of bot options + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isBotTech && tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isRecentlyShown) botTech.push(i) + } + if (botTech.length > 0) { //pick random bot tech + // const choose = botTech[Math.floor(Math.random() * botTech.length)]; + // const isCount = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count+1}x)` : ""; + // text += `
⭓▸●■   ${tech.tech[choose].name} ${isCount}
${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + const choose = botTech[Math.floor(Math.random() * botTech.length)]; + const techCountText = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + text += `
+
+
⭓▸●■   ${tech.tech[choose].name} ${techCountText}
+ ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + } + } + if (tech.isMassProduction) { + // const techOptions = [] //make an array of bot options + // for (let i = 0, len = tech.tech.length; i < len; i++) { + // if (tech.tech[i].isMassProduction) techOptions.push(i) + // } + // if (techOptions.length > 0) { //pick random bot tech + // const choose = techOptions[Math.floor(Math.random() * techOptions.length)]; + // const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[choose].name}.webp');"` + // text += `
+ //
+ //
${tech.tech[choose].name}
+ // ${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + // } + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isMassProduction) { + const style = localSettings.isHideImages ? powerUps.hideStyle : `style="background-image: url('img/${tech.tech[i].name}.webp');"` + text += `
+
+
${tech.tech[i].name}
+ ${tech.tech[i].descriptionFunction ? tech.tech[i].descriptionFunction() : tech.tech[i].description}
` + } + } + } + if (tech.isExtraGunField) { + if (Math.random() > 0.5 && b.inventory.length < b.guns.length) { + let gunOptions = []; + for (let i = 0; i < b.guns.length; i++) { + if (!b.guns[i].have) gunOptions.push(i); + } + const pick = gunOptions[Math.floor(Math.seededRandom(0, gunOptions.length))] //pick an element from the array of options + // text += `
  ${b.guns[pick].name}
${b.guns[pick].description}
` + text += powerUps.gunText(pick, `powerUps.choose('gun',${pick})`) + } else { + let fieldOptions = []; + for (let i = 1; i < m.fieldUpgrades.length; i++) { //skip field emitter + if (i !== m.fieldMode) fieldOptions.push(i); + } + const pick = fieldOptions[Math.floor(Math.seededRandom(0, fieldOptions.length))] //pick an element from the array of options + // text += `
  ${m.fieldUpgrades[pick].name}
${m.fieldUpgrades[pick].description}
` + text += powerUps.fieldText(pick, `powerUps.choose('field',${pick})`) + } + } + if (tech.isBrainstorm && !tech.isBrainstormActive && !simulation.isChoosing) { + tech.isBrainstormActive = true + let count = 1 + let timeStart = performance.now() + const cycle = (timestamp) => { + // if (timeStart === undefined) timeStart = timestamp + // console.log(timestamp, timeStart) + if (timestamp - timeStart > tech.brainStormDelay * count && simulation.isChoosing) { + count++ + powerUps.tech.effect(); + document.getElementById("choose-grid").style.pointerEvents = "auto"; //turn off the normal 500ms delay + document.body.style.cursor = "auto"; + document.getElementById("choose-grid").style.transitionDuration = "0s"; + } + if (count < 10 && simulation.isChoosing) { + requestAnimationFrame(cycle); + } else { + tech.isBrainstormActive = false + } + } + requestAnimationFrame(cycle); + } + document.getElementById("choose-grid").innerHTML = text + powerUps.showDraft(); + } + } + }, + }, + retainList: [], + entanglement: { + name: "entanglement", + color: "#fff", //"hsl(248,100%,65%)", + size() { + return 40 + }, + effect() { + if (m.alive && localSettings.entanglement) { + // let text = "" + // document.getElementById("choose-grid").style.gridTemplateColumns = "384px 384px 384px" + let text = powerUps.buildColumns(3, "entanglement") + + // text += powerUps.researchText('tech') + // text += "
" + // text += "
entanglement
" + // text += `
cancel
` //powerUps.cancelText('tech') + if (localSettings.entanglement.fieldIndex && localSettings.entanglement.fieldIndex !== m.fieldMode) { + const choose = localSettings.entanglement.fieldIndex //add field + text += powerUps.fieldText(choose, `powerUps.choose('field',${choose})`) + } + for (let i = 0; i < localSettings.entanglement.gunIndexes.length; i++) { //add guns + const choose = localSettings.entanglement.gunIndexes[i] + //check if you always have this gun + let alreadyHasGun = false + for (let j = 0; j < b.inventory.length; j++) { + if (b.inventory[j] === choose) alreadyHasGun = true + } + // text += `
  ${b.guns[gun].name}
${b.guns[gun].description}
` + if (!alreadyHasGun) text += powerUps.gunText(choose, `powerUps.choose('gun',${choose})`) + } + for (let i = 0; i < localSettings.entanglement.techIndexes.length; i++) { //add tech + let found = false; + let choose = undefined + for (let j = 0; j < tech.tech.length; j++) { + if (localSettings.entanglement.techIndexes[i] === tech.tech[j].name) { + choose = j; + found = true; + break; + } + } + if (found && tech.tech[choose]) { + const isCount = tech.tech[choose].count > 0 ? `(${tech.tech[choose].count + 1}x)` : ""; + if (choose === null || tech.tech[choose].count + 1 > tech.tech[choose].maxCount || !tech.tech[choose].allowed()) { + text += powerUps.incoherentTechText(choose) + } else { + if (tech.tech[choose].isFieldTech) { + text += powerUps.fieldTechText(choose, `powerUps.choose('tech',${choose})`) + } else if (tech.tech[choose].isGunTech) { + text += powerUps.gunTechText(choose, `powerUps.choose('tech',${choose})`) + } else if (tech.tech[choose].isLore) { + text += `
  ${tech.tech[choose].name} ${isCount}
${tech.tech[choose].descriptionFunction ? tech.tech[choose].descriptionFunction() : tech.tech[choose].description}
` + } else if (tech.tech[choose].isJunk) { + text += powerUps.junkTechText(choose, `powerUps.choose('tech',${choose})`) + } else if (tech.tech[choose].isSkin) { + text += powerUps.skinTechText(choose, `powerUps.choose('tech',${choose})`) + } else if (tech.tech[choose].isInstant) { + text += powerUps.instantTechText(choose, `powerUps.choose('tech',${choose})`) + } else { //normal tech + text += powerUps.techText(choose, `powerUps.choose('tech',${choose})`) + } + } + } + } + document.getElementById("choose-grid").innerHTML = text + powerUps.showDraft(); + localSettings.entanglement = undefined + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + }, + }, + spawnDelay(type, count, delay = 2) { + count *= delay + let cycle = () => { + if (count > 0) { + if (m.alive) requestAnimationFrame(cycle); + if (!simulation.paused && !simulation.isChoosing && powerUp.length < 300) { //&& !(simulation.cycle % 2) + count-- + if (!(count % delay)) { + const where = { x: m.pos.x + 50 * (Math.random() - 0.5), y: m.pos.y + 50 * (Math.random() - 0.5) } + powerUps.spawn(where.x, where.y, type); + } + } + } + } + requestAnimationFrame(cycle); + }, + onPickUp(who) { + powerUps.research.currentRerollCount = 0 + if (tech.isTechDamage && who.name === "tech") m.damage(0.1) + if (tech.isMassEnergy) m.energy += 2 * level.isReducedRegen; + if (tech.isMineDrop && bullet.length < 150 && Math.random() < 0.5) { + if (tech.isLaserMine && input.down) { + b.laserMine(who.position) + } else { + b.mine(who.position, { x: 0, y: 0 }, 0) + } + } + if (level.isNoDamage) level.noDamageCycle = m.cycle + }, + spawnRandomPowerUp(x, y) { //mostly used after mob dies, doesn't always return a power up + if (!tech.isEnergyHealth && (Math.random() * Math.random() - 0.3 > Math.sqrt(m.health)) || Math.random() < 0.04) { //spawn heal chance is higher at low health + powerUps.spawn(x, y, "heal"); + return; + } + if (Math.random() < 0.15 && b.inventory.length > 0) { + powerUps.spawn(x, y, "ammo"); + return; + } + if (Math.random() < 0.0007 * (3 - b.inventory.length)) { //a new gun has a low chance for each not acquired gun up to 3 + powerUps.spawn(x, y, "gun"); + return; + } + if (Math.random() < 0.0016) { + powerUps.spawn(x, y, "field"); + return; + } + if (tech.isCouplingPowerUps && Math.random() < 0.17) { + powerUps.spawn(x, y, "coupling"); + return; + } + if (Math.random() < 0.02 || (tech.isBoostPowerUps && Math.random() < 0.14)) { + powerUps.spawn(x, y, "boost"); + return; + } + }, + randomPowerUpCounter: 0, + isFieldSpawned: false, //makes it so a field spawns once but not more times + spawnBossPowerUp(x, y) { //boss spawns field and gun tech upgrades + if (level.levels[level.onLevel] !== "final") { + if (!powerUps.isFieldSpawned) { + powerUps.isFieldSpawned = true + powerUps.spawn(x, y, "field") + } else { + powerUpChance() + } + if (simulation.difficultyMode < 3) {//don't spawn second power up on difficulties with a second boss + powerUpChance() + } + function powerUpChance() { + powerUps.randomPowerUpCounter++ + if (powerUps.randomPowerUpCounter > Math.max(level.levelsCleared, 9) * 0.1 * Math.random()) { + powerUps.randomPowerUpCounter = 0; //reset odds + if (Math.random() < 0.97) { + powerUps.spawn(x, y, "tech") + } else { + powerUps.spawn(x, y, "gun") + } + } else { + if (m.health < 0.65 && !tech.isEnergyHealth) { + powerUps.spawn(x, y, "heal"); + powerUps.spawn(x, y, "heal"); + } else { + powerUps.spawn(x, y, "ammo"); + powerUps.spawn(x, y, "ammo"); + } + } + } + if (tech.isAddRemoveMaxHealth) { + powerUps.spawn(x + 20, y, "tech", false) + powerUps.spawn(x - 20, y, "research", false) + powerUps.spawn(x - 40, y, "research", false) + powerUps.spawn(x + 40, y, "research", false) + powerUps.spawn(x, y + 20, "research", false) + powerUps.spawn(x, y - 20, "heal", false) + powerUps.spawn(x, y + 40, "heal", false) + powerUps.spawn(x, y - 40, "heal", false) + } + if (tech.isResearchReality) powerUps.spawnDelay("research", 6) + if (tech.isBanish) powerUps.spawnDelay("research", 3) + if (tech.isCouplingNoHit) powerUps.spawnDelay("coupling", 9) + // if (tech.isRerollDamage) powerUps.spawnDelay("research", 1) + } + }, + chooseRandomPowerUp(x, y) { //100% chance to drop a random power up //used in spawn.debris + if (Math.random() < 0.5) { + powerUps.spawn(x, y, "heal", false); + } else { + powerUps.spawn(x, y, "ammo", false); + } + }, + addResearchToLevel() { //add a random power up to a location that has a mob, mostly used to give each level a research + if ((level.levelsCleared < 17 - simulation.difficultyMode * 3) && mob.length) { //don't spawn late game + const index = Math.floor(Math.random() * mob.length) + powerUps.spawn(mob[index].position.x, mob[index].position.y, "research"); + } + }, + spawnStartingPowerUps(x, y) { //used for map specific power ups, mostly to give player a starting gun + if (level.levelsCleared < 4) { //runs on first 4 levels on all difficulties + if (level.levelsCleared > 1 && simulation.difficultyMode < 7) powerUps.spawn(x, y, "tech") + if (b.inventory.length === 0) { + powerUps.spawn(x, y, "gun", false); //first gun + } else if (tech.totalCount === 0) { //first tech + powerUps.spawn(x, y, "tech", false); + } else if (b.inventory.length === 1) { //second gun or extra ammo + if (Math.random() < 0.4) { + powerUps.spawn(x, y, "gun", false); + } else { + for (let i = 0; i < 5; i++) powerUps.spawn(x, y, "ammo", false); + } + } else { + for (let i = 0; i < 4; i++) powerUps.spawnRandomPowerUp(x, y); + } + } else { //after the first 4 levels just spawn a random power up + for (let i = 0; i < 3; i++) powerUps.spawnRandomPowerUp(x, y); + } + }, + ejectTech(choose = 'random', isOverride = false) { + if (!simulation.isChoosing || isOverride) { + // console.log(tech.tech[choose].name, tech.tech[choose].count, tech.tech[choose].isInstant) + //find which tech you have + if (choose === 'random') { + const have = [] + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].count > 0 && !tech.tech[i].isInstant) have.push(i) + } + // if (have.length === 0) { + // for (let i = 0; i < tech.tech.length; i++) { + // if (tech.tech[i].count > 0) have.push(i) + // } + // } + + if (have.length) { + choose = have[Math.floor(Math.random() * have.length)] + simulation.inGameConsole(`tech.remove("${tech.tech[choose].name}")`) + + for (let i = 0; i < tech.tech[choose].count; i++) { + powerUps.directSpawn(m.pos.x, m.pos.y, "tech"); + } + // remove a random tech from the list of tech you have + tech.removeCount += tech.tech[choose].count + tech.tech[choose].remove(); + tech.totalCount -= tech.tech[choose].count + tech.tech[choose].count = 0; + tech.tech[choose].isLost = true; + simulation.updateTechHUD(); + m.fieldCDcycle = m.cycle + 30; //disable field so you can't pick up the ejected tech + return true + } else { + return false + } + } else if (tech.tech[choose].count && !tech.tech[choose].isInstant) { + simulation.inGameConsole(`tech.remove("${tech.tech[choose].name}")`) + + for (let i = 0; i < tech.tech[choose].count; i++) { + powerUps.directSpawn(m.pos.x, m.pos.y, "tech"); + } + // remove a random tech from the list of tech you have + tech.tech[choose].remove(); + tech.totalCount -= tech.tech[choose].count + tech.removeCount += tech.tech[choose].count + tech.tech[choose].count = 0; + tech.tech[choose].isLost = true; + simulation.updateTechHUD(); + m.fieldCDcycle = m.cycle + 30; //disable field so you can't pick up the ejected tech + return true + } else { + return false + } + } + }, + pauseEjectTech(index) { + if ((tech.isPauseEjectTech || simulation.testing) && !simulation.isChoosing && !tech.tech[index].isInstant) { + // if (tech.tech[index].bonusResearch !== undefined && tech.tech[index].bonusResearch > powerUps.research.count) { + // tech.removeTech(index) + // } else { + // } + tech.tech[index].frequency = 0 //banish tech + powerUps.ejectTech(index) + if (m.immuneCycle < m.cycle) m.damage(tech.pauseEjectTech * 0.01, false) + tech.pauseEjectTech *= 1.3 + document.getElementById(`${index}-pause-tech`).style.textDecoration = "line-through" + document.getElementById(`${index}-pause-tech`).style.animation = "" + document.getElementById(`${index}-pause-tech`).onclick = null + } + }, + randomize(where) { //makes a random power up convert into a random different power up + //put 10 power ups close together + const len = Math.min(10, powerUp.length) + for (let i = 0; i < len; i++) { //collide the first 10 power ups + const unit = Vector.rotate({ x: 1, y: 0 }, 6.28 * Math.random()) + Matter.Body.setPosition(powerUp[i], Vector.add(where, Vector.mult(unit, 20 + 25 * Math.random()))); + Matter.Body.setVelocity(powerUp[i], Vector.mult(unit, 20)); + } + + //count big power ups and small power ups + let options = ["heal", "research", tech.isBoostReplaceAmmo ? "boost" : "ammo"] + if (m.coupling) options.push("coupling") + if (tech.isBoostPowerUps) options.push("boost") + + let bigIndexes = [] + let smallIndexes = [] + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "tech" || powerUp[i].name === "gun" || powerUp[i].name === "field") { + bigIndexes.push(i) + } else { + smallIndexes.push(i) + } + } + + + if (smallIndexes.length > 2 && Math.random() < 0.66) { // console.log("no big, at least 3 small can combine") + for (let j = 0; j < 3; j++) { + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "heal" || powerUp[i].name === "research" || powerUp[i].name === "ammo" || powerUp[i].name === "coupling" || powerUp[i].name === "boost") { + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + break + } + } + } + + options = ["tech", "gun", "field"] + powerUps.directSpawn(where.x, where.y, options[Math.floor(Math.random() * options.length)], false) + } else if (bigIndexes.length > 0 && Math.random() < 0.5) { // console.log("at least 1 big can spilt") + const index = bigIndexes[Math.floor(Math.random() * bigIndexes.length)] + for (let i = 0; i < 3; i++) powerUps.directSpawn(where.x, where.y, options[Math.floor(Math.random() * options.length)], false) + + Matter.Composite.remove(engine.world, powerUp[index]); + powerUp.splice(index, 1); + } else if (smallIndexes.length > 0) { // console.log("no big, at least 1 small will swap flavors") + const index = Math.floor(Math.random() * powerUp.length) + options = options.filter(e => e !== powerUp[index].name); //don't repeat the current power up type + powerUps.directSpawn(where.x, where.y, options[Math.floor(Math.random() * options.length)], false) + Matter.Composite.remove(engine.world, powerUp[index]); + powerUp.splice(index, 1); + } + }, + spawn(x, y, name, moving = true, size = powerUps[name].size()) { + if ((!tech.isSuperDeterminism || (name !== 'research'))) { + if (tech.isBoostReplaceAmmo && name === 'ammo') { + name = 'boost' + size = powerUps[name].size() + } + powerUps.directSpawn(x, y, name, moving, size) + if (!level.isNextLevelPowerUps && Math.random() < tech.duplicationChance()) { + powerUps.directSpawn(x, y, name, moving, size, true) + powerUp[powerUp.length - 1].isDuplicated = true + if (tech.isDupEnergy) m.energy *= 2 + } + } + }, + directSpawn(x, y, name, moving = true, size = powerUps[name].size(), isDuplicated = false) { + if (level.isNextLevelPowerUps) { + powerUps.powerUpStorage.push({ name: name, size: size }) + return + } + let index = powerUp.length; + let properties = { + density: 0.001, + frictionAir: 0.03, + restitution: 0.85, + collisionFilter: { + group: 0, + category: cat.powerUp, + mask: cat.map | cat.powerUp + }, + color: powerUps[name].color, + effect: powerUps[name].effect, + name: powerUps[name].name, + size: size + } + let polygonSides + if (isDuplicated) { + polygonSides = tech.isPowerUpsVanish ? 3 : Math.floor(4 + 2 * Math.random()) + properties.isDuplicated = true + } else { + properties.inertia = Infinity //prevents rotation for circles only + polygonSides = 12 + } + powerUp[index] = Matter.Bodies.polygon(x, y, polygonSides, size, properties); + if (moving) Matter.Body.setVelocity(powerUp[index], { x: (Math.random() - 0.5) * 15, y: Math.random() * -9 - 3 }); + Composite.add(engine.world, powerUp[index]); + }, + powerUpStorage: [],//used when power ups are sent to the next level (for the constraint, level.isNextLevelPowerUps) +}; \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/simulation.js b/WebGames-master/WebGames-master/n-gon-master/js/simulation.js new file mode 100644 index 00000000..df225849 --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/simulation.js @@ -0,0 +1,2231 @@ +// game Object ******************************************************** +//********************************************************************* +const simulation = { + loop() { }, //main game loop, gets set to normal or testing loop + // normalLoop() { + // try { + // simulation.gravity(); + // Engine.update(engine, simulation.delta); + // simulation.wipe(); + // simulation.textLog(); + // if (m.onGround) { + // m.groundControl() + // } else { + // m.airControl() + // } + // m.move(); + // m.look(); + // simulation.camera(); + // level.custom(); + // powerUps.do(); + // mobs.draw(); + // simulation.draw.cons(); + // simulation.draw.body(); + // if (!m.isTimeDilated) mobs.loop(); + // mobs.healthBar(); + // m.draw(); + // m.hold(); + // level.customTopLayer(); + // simulation.draw.drawMapPath(); + // b.fire(); + // b.bulletRemove(); + // b.bulletDraw(); + // if (!m.isTimeDilated) b.bulletDo(); + // simulation.drawCircle(); + // simulation.runEphemera(); + // ctx.restore(); + // } catch (error) { + // simulation.inGameConsole(`ERROR: ${(error.stack && error.stack.replace(/\n/g, "
")) || (error.message + ` ${error.filename}:${error.lineno}`)}`); + // } finally { + // simulation.drawCursor(); + // } + // }, + // testingLoop() { + // try { + // simulation.gravity(); + // Engine.update(engine, simulation.delta); + // simulation.wipe(); + // simulation.textLog(); + // if (m.onGround) { + // m.groundControl() + // } else { + // m.airControl() + // } + // m.move(); + // m.look(); + // simulation.camera(); + // level.custom(); + // m.draw(); + // m.hold(); + // level.customTopLayer(); + // simulation.draw.wireFrame(); + // if (input.fire && m.fireCDcycle < m.cycle) { + // m.fireCDcycle = m.cycle + 15; //fire cooldown + // for (let i = 0, len = mob.length; i < len; i++) { + // if (Vector.magnitudeSquared(Vector.sub(mob[i].position, simulation.mouseInGame)) < mob[i].radius * mob[i].radius) { + // console.log(mob[i]) + // } + // } + // } + // simulation.draw.cons(); + // simulation.draw.testing(); + // simulation.drawCircle(); + // simulation.runEphemera(); + // simulation.constructCycle() + // } catch (error) { + // simulation.inGameConsole(`ERROR: ${(error.stack && error.stack.replace(/\n/g, "
")) || (error.message + ` ${error.filename}:${error.lineno}`)}`); + // } finally { + // ctx.restore(); + // simulation.testingOutput(); + // simulation.drawCursor(); + // } + // }, + normalLoop() { + simulation.gravity(); + Engine.update(engine, simulation.delta); + simulation.wipe(); + simulation.textLog(); + if (m.onGround) { + m.groundControl() + } else { + m.airControl() + } + m.move(); + m.look(); + simulation.camera(); + level.custom(); + powerUps.do(); + mobs.draw(); + simulation.draw.cons(); + simulation.draw.body(); + if (!m.isTimeDilated) mobs.loop(); + mobs.healthBar(); + m.draw(); + m.hold(); + level.customTopLayer(); + simulation.draw.drawMapPath(); + b.fire(); + b.bulletRemove(); + b.bulletDraw(); + if (!m.isTimeDilated) b.bulletDo(); + simulation.drawCircle(); + simulation.runEphemera(); + ctx.restore(); + simulation.drawCursor(); + }, + testingLoop() { + simulation.gravity(); + Engine.update(engine, simulation.delta); + simulation.wipe(); + simulation.textLog(); + if (m.onGround) { + m.groundControl() + } else { + m.airControl() + } + m.move(); + m.look(); + simulation.camera(); + level.custom(); + m.draw(); + m.hold(); + level.customTopLayer(); + simulation.draw.wireFrame(); + if (input.fire && m.fireCDcycle < m.cycle) { + m.fireCDcycle = m.cycle + 15; //fire cooldown + for (let i = 0, len = mob.length; i < len; i++) { + if (Vector.magnitudeSquared(Vector.sub(mob[i].position, simulation.mouseInGame)) < mob[i].radius * mob[i].radius) { + console.log(mob[i]) + } + } + } + simulation.draw.cons(); + simulation.draw.testing(); + simulation.drawCircle(); + simulation.runEphemera(); + simulation.constructCycle() + ctx.restore(); + simulation.testingOutput(); + simulation.drawCursor(); + }, + isTimeSkipping: false, + timeSkip(cycles = 60) { + simulation.isTimeSkipping = true; + for (let i = 0; i < cycles; i++) { + simulation.cycle++; + m.cycle++; + simulation.gravity(); + Engine.update(engine, simulation.delta); + if (m.onGround) { + m.groundControl() + } else { + m.airControl() + } + m.move(); + level.custom(); + mobs.loop(); + m.walk_cycle += m.flipLegs * m.Vx; + m.hold(); + level.customTopLayer(); + b.fire(); + b.bulletRemove(); + b.bulletDo(); + simulation.runEphemera(); + } + simulation.isTimeSkipping = false; + }, + timePlayerSkip(cycles = 60) { + simulation.isTimeSkipping = true; + for (let i = 0; i < cycles; i++) { + simulation.cycle++; + // m.walk_cycle += (m.flipLegs * m.Vx) * 0.5; //makes the legs look like they are moving fast this is just gonna run for each method call since it needs some tweaking + simulation.gravity(); + Engine.update(engine, simulation.delta); + // level.custom(); + // level.customTopLayer(); + if (!m.isTimeDilated) mobs.loop(); + if (m.fieldMode !== 7) m.hold(); + b.bulletRemove(); + if (!m.isTimeDilated) b.bulletDo(); + simulation.runEphemera(); + } + simulation.isTimeSkipping = false; + }, + ephemera: [], //array that is used to store ephemera objects + removeEphemera: function (name) { + for (let i = 0, len = simulation.ephemera.length; i < len; i++) { + if (simulation.ephemera[i].name === name) { + simulation.ephemera.splice(i, 1); + break; + } + } + }, + runEphemera() { + for (let i = 0; i < simulation.ephemera.length; i++) { + simulation.ephemera[i].do(); + } + }, + // timeMobSkip() { + // simulation.gravity(); + // Engine.update(engine, simulation.delta); + // simulation.wipe(); + // simulation.textLog(); + // if (m.onGround) { + // m.groundControl() + // } else { + // m.airControl() + // } + // m.move(); + // m.look(); + // simulation.camera(); + // level.custom(); + // powerUps.do(); + // mobs.draw(); + // simulation.draw.cons(); + // simulation.draw.body(); + // if (!m.isTimeDilated) { + // // mobs.loop(); + // } + // mobs.healthBar(); + // m.draw(); + // m.hold(); + // // v.draw(); //working on visibility work in progress + // level.customTopLayer(); + // simulation.draw.drawMapPath(); + // b.fire(); + // b.bulletRemove(); + // b.bulletDraw(); + // if (!m.isTimeDilated) b.bulletDo(); + // simulation.drawCircle(); + // // simulation.clip(); + // ctx.restore(); + // simulation.drawCursor(); + // // simulation.pixelGraphics(); + // }, + mouse: { + x: canvas.width / 2, + y: canvas.height / 2 + }, + mouseInGame: { + x: 0, + y: 0 + }, + g: 0.0024, // applies to player, bodies, and power ups (not mobs) + onTitlePage: true, + isCheating: false, + isTraining: false, + paused: false, + isChoosing: false, + testing: false, //testing mode: shows wire frame and some variables + cycle: 0, //total cycles, 60 per second + fpsCap: null, //limits frames per second to 144/2=72, on most monitors the fps is capped at 60fps by the hardware + fpsCapDefault: 72, //use to change fpsCap back to normal after a hit from a mob + isCommunityMaps: false, + cyclePaused: 0, + fallHeight: 6000, //below this y position the player will teleport to start, take damage, or teleport to the sky based on the value of level.fallMode + lastTimeStamp: 0, //tracks time stamps for measuring delta + delta: 1000 / 60, //speed of game engine //looks like it has to be 16.6666 to match player input + buttonCD: 0, + isHorizontalFlipped: false, //makes some maps flipped horizontally + levelsCleared: 0, + difficultyMode: 2, //normal difficulty is 2 + difficulty: 0, + constraint: 0, + dmgScale: null, + healScale: 1, + accelScale: null, + CDScale: null, + molecularMode: Math.floor(4 * Math.random()), //0 spores, 1 missile, 2 ice IX, 3 drones //randomize molecular assembler field type + // dropFPS(cap = 40, time = 15) { + // simulation.fpsCap = cap + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // simulation.defaultFPSCycle = simulation.cycle + time + // const normalFPS = function () { + // if (simulation.defaultFPSCycle < simulation.cycle) { + // simulation.fpsCap = 72 + // simulation.fpsInterval = 1000 / simulation.fpsCap; + // } else { + // requestAnimationFrame(normalFPS); + // } + // }; + // requestAnimationFrame(normalFPS); + // }, + // clip() { + + // }, + pixelGraphics() { + //copy current canvas pixel data + let imgData = ctx.getImageData(0, 0, canvas.width, canvas.height); + let data = imgData.data; + //change pixel data + + + // const off = 4 * Math.floor(x) + 4 * canvas.width * Math.floor(y); + // multiple windows + for (let i = data.length / 2; i < data.length; i += 4) { + index = i % (canvas.width * canvas.height * 2) // + canvas.width*4*canvas.height + + data[i + 0] = data[index + 0]; // red + data[i + 1] = data[index + 1]; // red + data[i + 2] = data[index + 2]; // red + data[i + 3] = data[index + 3]; // red + } + + for (let x = 0; x < len; x++) { + + } + + + + // const startX = 2 * canvas.width + 2 * canvas.width * canvas.height + // const endX = 4 * canvas.width + 4 * canvas.width * canvas.height + // const startY = 2 * canvas.width + 2 * canvas.width * canvas.height + // const endY = 4 * canvas.width + 4 * canvas.width * canvas.height + // for (let x = startX; x < endX; x++) { + // for (let y = startY; y < endY; y++) { + + // } + // } + + + + + //strange draw offset + // const off = canvas.height * canvas.width * 4 / 2 + // for (let index = 0; index < data.length; index += 4) { + // data[index + 0] = data[index + 0 + off]; // red + // data[index + 1] = data[index + 1 + off]; // red + // data[index + 2] = data[index + 2 + off]; // red + // data[index + 3] = data[index + 3 + off]; // red + // } + + //change all pixels + // for (let index = 0; index < data.length; index += 4) { + // data[index + 0] = 255; // red + // data[index + 1] = 255; // green + // data[index + 2] = 255; // blue + // data[index + 3] = 255; // alpha + // } + + //change random pixels + // for (let i = 0, len = Math.floor(data.length / 10); i < len; ++i) { + // const index = Math.floor((Math.random() * data.length) / 4) * 4; + // data[index + 0] = 255; // red + // data[index + 1] = 0; // green + // data[index + 2] = 0; // blue + // data[index + 3] = 255 //Math.floor(Math.random() * Math.random() * 255); // alpha + // } + + // //change random pixels + // for (let i = 0, len = Math.floor(data.length / 1000); i < len; ++i) { + // const index = Math.floor((Math.random() * data.length) / 4) * 4; + // // data[index] = data[index] ^ 255; // Invert Red + // // data[index + 1] = data[index + 1] ^ 255; // Invert Green + // // data[index + 2] = data[index + 2] ^ 255; // Invert Blue + // data[index + 0] = 0; // red + // data[index + 1] = 0; // green + // data[index + 2] = 0; // blue + // // data[index + 3] = 255 //Math.floor(Math.random() * Math.random() * 255); // alpha + // } + + //draw new pixel data to canvas + ctx.putImageData(imgData, 0, 0); + }, + drawCursor() { + const size = 10; + ctx.beginPath(); + ctx.moveTo(simulation.mouse.x - size, simulation.mouse.y); + ctx.lineTo(simulation.mouse.x + size, simulation.mouse.y); + ctx.moveTo(simulation.mouse.x, simulation.mouse.y - size); + ctx.lineTo(simulation.mouse.x, simulation.mouse.y + size); + ctx.lineWidth = 2; + ctx.strokeStyle = "#000"; //'rgba(0,0,0,0.4)' + ctx.stroke(); // Draw it + }, + drawCursorBasic() { + const size = 10; + ctx.beginPath(); + ctx.moveTo(simulation.mouse.x - size, simulation.mouse.y); + ctx.lineTo(simulation.mouse.x + size, simulation.mouse.y); + ctx.moveTo(simulation.mouse.x, simulation.mouse.y - size); + ctx.lineTo(simulation.mouse.x, simulation.mouse.y + size); + ctx.lineWidth = 2; + ctx.strokeStyle = "#000"; //'rgba(0,0,0,0.4)' + ctx.stroke(); // Draw it + }, + drawCursorCoolDown() { + const size = 10; + ctx.lineWidth = 2; + ctx.strokeStyle = "#000"; //'rgba(0,0,0,0.4)' + ctx.beginPath(); + if (m.fireCDcycle > m.cycle) { + ctx.strokeStyle = "#000"; //'rgba(0,0,0,0.4)' + ctx.arc(simulation.mouse.x, simulation.mouse.y, size + 1, 0, 2 * Math.PI); + } else { + ctx.strokeStyle = "#000"; //'rgba(0,0,0,0.4)' + } + ctx.moveTo(simulation.mouse.x - size, simulation.mouse.y); + ctx.lineTo(simulation.mouse.x + size, simulation.mouse.y); + ctx.moveTo(simulation.mouse.x, simulation.mouse.y - size); + ctx.lineTo(simulation.mouse.x, simulation.mouse.y + size); + ctx.stroke(); // Draw it + }, + drawList: [], //so you can draw a first frame of explosions.. I know this is bad + drawTime: 8, //how long circles are drawn. use to push into drawlist.time + mobDmgColor: "rgba(255,0,0,0.7)", //color when a mob damages the player // set by mass-energy tech + playerDmgColor: "rgba(0,0,0,0.7)", //color when the player damages a mob + drawCircle() { + //draws a circle for two cycles, used for showing damage mostly + let i = simulation.drawList.length; + while (i--) { + ctx.beginPath(); //draw circle + ctx.arc(simulation.drawList[i].x, simulation.drawList[i].y, simulation.drawList[i].radius, 0, 2 * Math.PI); + ctx.fillStyle = simulation.drawList[i].color; + ctx.fill(); + if (simulation.drawList[i].time) { + simulation.drawList[i].time--; + } else { + if (!m.isTimeDilated) simulation.drawList.splice(i, 1); //remove when timer runs out + } + } + }, + circleFlare(dup, loops = 100) { + boltNum = dup * 300 + const bolts = [] + colors = [powerUps.research.color, powerUps.ammo.color, powerUps.heal.color, powerUps.tech.color, powerUps.field.color, powerUps.gun.color] + for (let i = 0; i < boltNum; ++i) { + const mag = 6 + 20 * Math.random() + const angle = 2 * Math.PI * Math.random() + bolts.push({ + x: m.pos.x, + y: m.pos.y, + Vx: mag * Math.cos(angle), + Vy: mag * Math.sin(angle), + color: colors[Math.floor(Math.random() * colors.length)] + }) + } + let count = 0 + loop = () => { //draw electricity + if (count++ < loops) requestAnimationFrame(loop) + for (let i = 0, len = bolts.length; i < len; ++i) { + bolts[i].x += bolts[i].Vx + bolts[i].y += bolts[i].Vy + if (Math.random() < 0.2) { + simulation.drawList.push({ + x: bolts[i].x, + y: bolts[i].y, + radius: 1.5 + 5 * Math.random(), + // color: "rgba(0,155,155,0.7)", + color: bolts[i].color, + time: Math.floor(9 + 25 * Math.random() * Math.random()) + }); + } + } + } + requestAnimationFrame(loop) + }, + boldActiveGunHUD() { + if (b.inventory.length > 0) { + for (let i = 0, len = b.inventory.length; i < len; ++i) { + if (b.inventory[i] === b.activeGun && document.getElementById(b.activeGun)) { + document.getElementById(b.inventory[i]).style.opacity = "1"; + } else { + document.getElementById(b.inventory[i]).style.opacity = "0.3"; + } + } + } + }, + updateGunHUD() { + for (let i = 0, len = b.inventory.length; i < len; ++i) { + document.getElementById(b.inventory[i]).innerHTML = `${b.guns[b.inventory[i]].name} - ${b.guns[b.inventory[i]].ammo}` + } + }, + makeGunHUD() { + //remove all nodes + const myNode = document.getElementById("guns"); + while (myNode.firstChild) { + myNode.removeChild(myNode.firstChild); + } + //add nodes + for (let i = 0, len = b.inventory.length; i < len; ++i) { + const node = document.createElement("div"); + node.setAttribute("id", b.inventory[i]); + const textNode = document.createTextNode(`${b.guns[b.inventory[i]].name} - ${b.guns[b.inventory[i]].ammo}`); //b.guns[b.inventory[i]].name + " - " + b.guns[b.inventory[i]].ammo); + node.appendChild(textNode); + document.getElementById("guns").appendChild(node); + } + simulation.boldActiveGunHUD(); + }, + // updateTechHUD() { + // let text = "" + // for (let i = 0, len = tech.tech.length; i < len; i++) { //add tech + // if (tech.tech[i].isLost) { + // if (text) text += "
" //add a new line, but not on the first line + // text += `${tech.tech[i].name}` + // } else if (tech.tech[i].count > 0 && !tech.tech[i].isInstant) { + // if (text) text += "
" //add a new line, but not on the first line + // text += `${tech.tech[i].name}${tech.tech[i].count > 1 ? ` (${tech.tech[i].count}x)` : ""}` + + // // document.getElementById(tech.tech[i].name).style.fontWeight = 'bold'; + // // simulation.ephemera.push({ + // // name: "bold", + // // count: 180, + // // do() { + // // this.count-- + // // if (this.count < 0) { + // // simulation.removeEphemera(this.name) + // // if (document.getElementById(tech.tech[i].name)) document.getElementById(tech.tech[i].name).style.fontWeight = 'normal'; + // // } + // // } + // // }) + // } + // } + // document.getElementById("right-HUD").innerHTML = text + // }, + updateTechHUD() { + let text = "" + for (let i = 0, len = tech.tech.length; i < len; i++) { //add tech + if (tech.tech[i].isLost) { + if (text) text += "
" //add a new line, but not on the first line + text += `${tech.tech[i].name}` + } else if (tech.tech[i].count > 0 && !tech.tech[i].isInstant) { + if (text) text += "
" //add a new line, but not on the first line + text += tech.tech[i].name + if (tech.tech[i].count > 1) text += ` (${tech.tech[i].count}x)` + } + } + document.getElementById("right-HUD").innerHTML = text + }, + lastLogTime: 0, + isTextLogOpen: true, + inGameConsole(text, time = 240) { + if (!localSettings.isHideHUD && simulation.isTextLogOpen && !build.isExperimentSelection) { + if (simulation.lastLogTime > m.cycle) { //if there is an older message + document.getElementById("text-log").innerHTML = document.getElementById("text-log").innerHTML + '
' + text; + simulation.lastLogTime = m.cycle + time; + } else { + document.getElementById("text-log").innerHTML = text; + document.getElementById("text-log").style.display = "inline"; + simulation.lastLogTime = m.cycle + time; + } + } + }, + textLog() { + if (simulation.lastLogTime && simulation.lastLogTime < m.cycle) { + simulation.lastLogTime = 0; + // document.getElementById("text-log").innerHTML = " "; + document.getElementById("text-log").style.display = "none"; + } + }, + nextGun() { + if (b.inventory.length > 1 && !(tech.isGunCycle || tech.isGunChoice)) { + b.inventoryGun++; + if (b.inventoryGun > b.inventory.length - 1) b.inventoryGun = 0; + simulation.switchGun(); + } + }, + previousGun() { + if (b.inventory.length > 1 && !(tech.isGunCycle || tech.isGunChoice)) { + b.inventoryGun--; + if (b.inventoryGun < 0) b.inventoryGun = b.inventory.length - 1; + simulation.switchGun(); + } + }, + switchToGunInInventory(num) { + if (b.inventory[num] !== undefined && b.inventoryGun !== num) { + b.inventoryGun = num + simulation.switchGun(); + } + }, + switchGun() { + if (tech.isLongitudinal && b.activeGun === 3) b.guns[3].waves = []; //empty array of wave bullets + if (tech.crouchAmmoCount) tech.crouchAmmoCount = 1 //this prevents hacking the tech by switching guns + if (b.inventory.length > 0) b.activeGun = b.inventory[b.inventoryGun]; + b.guns[8].charge = 0; // foam charge to 0 + simulation.updateGunHUD(); + simulation.boldActiveGunHUD(); + //set crosshairs + if (b.activeGun === 1) { + simulation.drawCursor = simulation.drawCursorCoolDown + } else { + simulation.drawCursor = simulation.drawCursorBasic + } + }, + zoom: null, + zoomScale: 1000, + isAutoZoom: true, + setZoom(zoomScale = simulation.zoomScale) { //use in window resize in index.js + simulation.zoomScale = zoomScale + simulation.zoom = canvas.height / zoomScale; //sets starting zoom scale + }, + zoomTransition(newZoomScale, step = 2) { + //old version + // if (simulation.isAutoZoom) { + // const isBigger = (newZoomScale - simulation.zoomScale > 0) ? true : false; + // requestAnimationFrame(zLoop); + // const currentLevel = level.onLevel + + // function zLoop() { + // if (currentLevel !== level.onLevel || simulation.isAutoZoom === false) return //stop the zoom if player goes to a new level + + // if (isBigger) { + // simulation.zoomScale += step + // if (simulation.zoomScale >= newZoomScale) { + // simulation.setZoom(newZoomScale); + // return + // } + // } else { + // simulation.zoomScale -= step + // if (simulation.zoomScale <= newZoomScale) { + // simulation.setZoom(newZoomScale); + // return + // } + // } + + // simulation.setZoom(); + // requestAnimationFrame(zLoop); + // } + // } + + + //rewrite using the ephemera system + if (simulation.isAutoZoom) { + simulation.ephemera.push({ + name: "zoom", + count: simulation.testing ? 0 : 120, //cycles before it self removes + currentLevel: level.onLevel, + do() { + this.count-- + const step = (newZoomScale - simulation.zoomScale) / this.count + simulation.zoomScale += step + if (this.count < 1 && this.currentLevel === level.onLevel && simulation.isAutoZoom) { + simulation.zoomScale = newZoomScale + simulation.removeEphemera(this.name) + } + simulation.setZoom(simulation.zoomScale); + }, + }) + } + }, + isInvertedVertical: false, + flipCameraVertical(frames = 1, passFunction = () => { }) { + if (!simulation.isInvertedVertical) { + if (frames > 0) { + let count = 0 + const loop = () => { + if (m.alive) { + if (simulation.paused) { + requestAnimationFrame(loop); + } else { + count++ + ctx.setTransform(1, 0, 0, 1, 0, 0); ///reset to avoid build up of transformations + if (count === frames) { + // Flip the canvas vertically + ctx.translate(0, canvas.height); // Move the origin down to the bottom + ctx.scale(1, -1); // Flip vertically + simulation.isInvertedVertical = true + //flip mouse Y again to make sure it caught + mouseMove = function (e) { + simulation.mouse.x = e.clientX; + simulation.mouse.y = window.innerHeight - e.clientY; + } + } else { + requestAnimationFrame(loop); + ctx.translate(0, canvas.height * count / frames); + ctx.scale(1, 1 - 2 * count / frames); + } + if (count === Math.floor(frames / 2)) { + //flip mouse Y at the 1/2 way point + mouseMove = function (e) { + simulation.mouse.x = e.clientX; + simulation.mouse.y = window.innerHeight - e.clientY; + } + //passFunction probably flips the map elements + passFunction() + } + } + } + } + requestAnimationFrame(loop); + } else { + // Flip the canvas vertically + ctx.translate(0, canvas.height); // Move the origin down to the bottom + ctx.scale(1, -1); // Flip vertically + //flip mouse Y + simulation.isInvertedVertical = true + mouseMove = function (e) { + simulation.mouse.x = e.clientX; + simulation.mouse.y = window.innerHeight - e.clientY; + } + } + } + }, + unFlipCameraVertical(frames = 0, passFunction = () => { }) { + if (frames) { + let count = 0 + const loop = () => { + if (m.alive) { + if (simulation.paused) { + requestAnimationFrame(loop); + } else { + count++ + ctx.setTransform(1, 0, 0, 1, 0, 0); ///reset to avoid build up of transformations + if (count === frames) { + // requestAnimationFrame(() => { ctx.reset(); }); + // ctx.translate(0, 0); + // ctx.scale(1, 1); + simulation.isInvertedVertical = false + //flip mouse Y again to make sure it caught + mouseMove = mouseMoveDefault + + } else { + requestAnimationFrame(loop); + ctx.translate(0, canvas.height - canvas.height * count / frames); + ctx.scale(1, -1 + 2 * count / frames); + } + if (count === Math.floor(frames / 2)) { + mouseMove = mouseMoveDefault//flip mouse Y at the 1/2 way point + passFunction()//passFunction probably draws new map elements + } + } + } + } + requestAnimationFrame(loop); + } else { + ctx.reset(); + ctx.font = "25px Arial"; + simulation.isInvertedVertical = false + mouseMove = mouseMoveDefault + } + }, + translatePlayerAndCamera(where, isTranslateBots = true) { + //infinite falling. teleport to sky after falling + const before = { x: player.position.x, y: player.position.y, } + Matter.Body.setPosition(player, { x: where.x, y: where.y }); + const change = { x: before.x - player.position.x, y: before.y - player.position.y } + // translate camera to preserve illusion to endless fall + m.transX += change.x + m.transY += change.y + simulation.mouseInGame.x = (simulation.mouse.x - canvas.width2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.width2 - m.transX; + simulation.mouseInGame.y = (simulation.mouse.y - canvas.height2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.height2 - m.transY; + + m.angle = Math.atan2(simulation.mouseInGame.y - m.pos.y, simulation.mouseInGame.x - m.pos.x); + + //is there a reason to update m.pos here? + // m.pos.x = player.position.x; + // m.pos.y = playerBody.position.y - m.yOff; + if (isTranslateBots) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + if (Vector.magnitudeSquared(Vector.sub(bullet[i].position, player.position)) > 1000000) { //far away bots teleport to player + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { x: 250 * (Math.random() - 0.5), y: 250 * (Math.random() - 0.5) })); + Matter.Body.setVelocity(bullet[i], { x: 0, y: 0 }); + } else { //close bots maintain relative distance to player on teleport + Matter.Body.setPosition(bullet[i], Vector.sub(bullet[i].position, change)); + } + } + } + } + }, + setupCamera() { //makes the camera not scroll after changing locations + // only works if velocity is zero + m.pos.x = player.position.x; + m.pos.y = playerBody.position.y - m.yOff; + const scale = 0.8; + m.transSmoothX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale; + m.transSmoothY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale; + m.transX += (m.transSmoothX - m.transX); + m.transY += (m.transSmoothY - m.transY); + }, + edgeZoomOutSmooth: 1, + camera() { + //zoom out when mouse gets near the edge of the window + const dx = simulation.mouse.x / window.innerWidth - 0.5 //x distance from mouse to window center scaled by window width + const dy = simulation.mouse.y / window.innerHeight - 0.5 //y distance from mouse to window center scaled by window height + const d = Math.max(dx * dx, dy * dy) + simulation.edgeZoomOutSmooth = (1 + 4 * d * d) * 0.04 + simulation.edgeZoomOutSmooth * 0.96 + + ctx.save(); + ctx.translate(canvas.width2, canvas.height2); //center + ctx.scale(simulation.zoom / simulation.edgeZoomOutSmooth, simulation.zoom / simulation.edgeZoomOutSmooth); //zoom in once centered + ctx.translate(-canvas.width2 + m.transX, -canvas.height2 + m.transY); //translate + // ctx.translate(-canvas.width2 + m.transX - player.velocity.x, -canvas.height2 + m.transY + player.velocity.y); //translate + //calculate in game mouse position by undoing the zoom and translations + simulation.mouseInGame.x = (simulation.mouse.x - canvas.width2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.width2 - m.transX; + simulation.mouseInGame.y = (simulation.mouse.y - canvas.height2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.height2 - m.transY; + }, + //for moving camera away from player + setCameraPosition(x, y, zoom = 1) { + ctx.restore(); + ctx.save(); + ctx.translate(canvas.width2, canvas.height2); //center + ctx.scale(zoom, zoom); //zoom in once centered + ctx.translate(- x, - y); //center + + // ctx.scale(simulation.zoom / simulation.edgeZoomOutSmooth, simulation.zoom / simulation.edgeZoomOutSmooth); //zoom in once centered + // ctx.translate(-canvas.width2, -canvas.height2); //translate + //calculate in game mouse position by undoing the zoom and translations + simulation.mouseInGame.x = (simulation.mouse.x - canvas.width2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.width2 - m.transX; + simulation.mouseInGame.y = (simulation.mouse.y - canvas.height2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.height2 - m.transY; + }, + cameraNoLook() { + ctx.save(); + ctx.translate(canvas.width2, canvas.height2); //center + // ctx.scale(simulation.zoom / simulation.edgeZoomOutSmooth, simulation.zoom / simulation.edgeZoomOutSmooth); //zoom in once centered + ctx.translate(-canvas.width2 + m.transX, -canvas.height2 + m.transY); //translate + //calculate in game mouse position by undoing the zoom and translations + simulation.mouseInGame.x = (simulation.mouse.x - canvas.width2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.width2 - m.transX; + simulation.mouseInGame.y = (simulation.mouse.y - canvas.height2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.height2 - m.transY; + }, + restoreCamera() { + ctx.restore(); + }, + trails(swapPeriod = 150) { + // const swapPeriod = 150 + const len = 30 + for (let i = 0; i < len; i++) { + setTimeout(function () { + simulation.wipe = function () { //set wipe to have trails + ctx.fillStyle = `rgba(221,221,221,${i * i * 0.0005 + 0.0025})`; + ctx.fillRect(0, 0, canvas.width, canvas.height); + } + }, (i) * swapPeriod); + } + + setTimeout(function () { + simulation.wipe = function () { //set wipe to normal + ctx.clearRect(0, 0, canvas.width, canvas.height); + } + }, len * swapPeriod); + }, + // warp(translation = 5, skew = 0.05, scale = 0.05) { + // if (simulation.cycle % 2) { //have to alternate frames or else successive rumbles over write the effects of the previous rumble + // requestAnimationFrame(() => { ctx.setTransform(1, 0, 0, 1, 0, 0); }) //reset + // requestAnimationFrame(() => { + // if (!simulation.paused && m.alive) { + // ctx.transform(1 - scale * (Math.random() - 0.5), skew * (Math.random() - 0.5), skew * (Math.random() - 0.5), 1 - scale * (Math.random() - 0.5), translation * (Math.random() - 0.5), translation * (Math.random() - 0.5)); //ctx.transform(Horizontal scaling. A value of 1 results in no scaling, Vertical skewing, Horizontal skewing, Vertical scaling. A value of 1 results in no scaling, Horizontal translation (moving), Vertical translation (moving)) //https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform + // } + // }) + + //reset + // ctx.transform(1, 0, 0, 1, 0, 0); //ctx.transform(Horizontal scaling. A value of 1 results in no scaling, Vertical skewing, Horizontal skewing, Vertical scaling. A value of 1 results in no scaling, Horizontal translation (moving), Vertical translation (moving)) //https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform + + // } + // const loop = () => { + // if (!simulation.paused && m.alive) { + // ctx.save(); + // ctx.transform(1 - scale * (Math.random() - 0.5), skew * (Math.random() - 0.5), skew * (Math.random() - 0.5), 1 - scale * (Math.random() - 0.5), translation * (Math.random() - 0.5), translation * (Math.random() - 0.5)); //ctx.transform(Horizontal scaling. A value of 1 results in no scaling, Vertical skewing, Horizontal skewing, Vertical scaling. A value of 1 results in no scaling, Horizontal translation (moving), Vertical translation (moving)) + // requestAnimationFrame(() => { ctx.restore(); }) + // } + // } + // requestAnimationFrame(loop); + + // function loop() { + // if (!simulation.paused && m.alive) { + // ctx.save(); + // ctx.transform(1 - scale * (Math.random() - 0.5), skew * (Math.random() - 0.5), skew * (Math.random() - 0.5), 1 - scale * (Math.random() - 0.5), translation * (Math.random() - 0.5), translation * (Math.random() - 0.5)); //ctx.transform(Horizontal scaling. A value of 1 results in no scaling, Vertical skewing, Horizontal skewing, Vertical scaling. A value of 1 results in no scaling, Horizontal translation (moving), Vertical translation (moving)) + // requestAnimationFrame(() => { ctx.restore(); }) + // } + // requestAnimationFrame(loop); + // } + // requestAnimationFrame(loop); + // }, + wipe() { }, //set in simulation.startGame + gravity() { + function addGravity(bodies, magnitude) { + for (var i = 0; i < bodies.length; i++) { + bodies[i].force.y += bodies[i].mass * magnitude; + } + } + if (!m.isTimeDilated) { + addGravity(powerUp, simulation.g); + addGravity(body, simulation.g); + } + player.force.y += player.mass * simulation.g; + }, + firstRun: true, + splashReturn() { + document.getElementById("previous-seed").innerHTML = `previous seed: ${Math.initialSeed}
` + document.getElementById("seed").value = Math.initialSeed = Math.seed //randomize initial seed + + //String(document.getElementById("seed").value) + // Math.seed = Math.abs(Math.hash(Math.initialSeed)) //update randomizer seed in case the player changed it + + + simulation.clearTimeouts(); + simulation.onTitlePage = true; + document.getElementById("splash").onclick = function () { + simulation.startGame(); + }; + document.getElementById("choose-grid").style.visibility = "hidden" + document.getElementById("choose-grid").style.opacity = "0" + document.getElementById("info").style.display = "inline"; + document.getElementById("info").style.opacity = "0"; + document.getElementById("experiment-button").style.display = "inline" + document.getElementById("experiment-button").style.opacity = "0"; + document.getElementById("training-button").style.display = "inline" + document.getElementById("training-button").style.opacity = "0"; + document.getElementById("start-button").style.display = "inline" + document.getElementById("start-button").style.opacity = "0"; + document.getElementById("experiment-grid").style.display = "none" + document.getElementById("pause-grid-left").style.display = "none" + document.getElementById("pause-grid-right").style.display = "none" + document.getElementById("splash").style.display = "inline"; + document.getElementById("splash").style.opacity = "0"; + document.getElementById("dmg").style.display = "none"; + document.getElementById("health-bg").style.display = "none"; + document.getElementById("defense-bar").style.display = "none" + document.getElementById("damage-bar").style.display = "none" + document.body.style.cursor = "auto"; + setTimeout(() => { + document.getElementById("experiment-button").style.opacity = "1"; + document.getElementById("training-button").style.opacity = "1"; + document.getElementById("start-button").style.opacity = "1"; + document.getElementById("info").style.opacity = "1"; + document.getElementById("splash").style.opacity = "1"; + }, 200); + }, + fpsInterval: 0, //set in startGame + then: null, + startGame(isBuildRun = false, isTrainingRun = false) { + simulation.isTextLogOpen = true + simulation.clearMap() + if (!isBuildRun) { //if a build run logic flow returns to "experiment-button").addEventListener + document.body.style.cursor = "none"; + document.body.style.overflow = "hidden" + } + if (isTrainingRun) { + simulation.isTraining = true + } else { + simulation.isTraining = false + } + simulation.onTitlePage = false; + // document.getElementById("choose-grid").style.display = "none" + document.getElementById("choose-grid").style.visibility = "hidden" + document.getElementById("choose-grid").style.opacity = "0" + document.getElementById("experiment-grid").style.display = "none" + document.getElementById("info").style.display = "none"; + document.getElementById("experiment-button").style.display = "none"; + document.getElementById("training-button").style.display = "none"; + document.getElementById("start-button").style.display = "none"; + // document.getElementById("experiment-button").style.opacity = "0"; + document.getElementById("splash").onclick = null; //removes the onclick effect so the function only runs once + document.getElementById("splash").style.display = "none"; //hides the element that spawned the function + document.getElementById("dmg").style.display = "inline"; + document.getElementById("health").style.display = "inline" + document.getElementById("health-bg").style.display = "inline"; + if (!localSettings.isHideHUD) { + document.getElementById("right-HUD").style.display = "inline" + document.getElementById("defense-bar").style.display = "inline" + document.getElementById("damage-bar").style.display = "inline" + } else { + document.getElementById("right-HUD").style.display = "none" + document.getElementById("defense-bar").style.display = "none" + document.getElementById("damage-bar").style.display = "none" + } + document.getElementById("guns").style.display = "inline" + document.getElementById("field").style.display = "inline" + + // document.body.style.overflow = "hidden" + document.getElementById("pause-grid-left").style.display = "none" + document.getElementById("pause-grid-right").style.display = "none" + document.getElementById("pause-grid-right").style.opacity = "1" + document.getElementById("pause-grid-left").style.opacity = "1" + ctx.globalCompositeOperation = "source-over" + ctx.shadowBlur = 0; + + mouseMove = mouseMoveDefault + requestAnimationFrame(() => { + ctx.setTransform(1, 0, 0, 1, 0, 0); //reset warp effect + ctx.setLineDash([]) //reset stroke dash effect + }) + // ctx.shadowColor = '#000'; + if (!m.isShipMode) { + m.resetSkin() //set the play draw to normal, undoing some junk tech + m.spawn(); //spawns the player + m.look = m.lookDefault + } else { + Composite.add(engine.world, [player]) + } + shuffle(level.constraint) + level.populateLevels() + input.endKeySensing(); + simulation.ephemera = [] + powerUps.powerUpStorage = [] + tech.resetAllTech(); //sets tech to default values + b.resetAllGuns(); + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "laser") b.guns[i].chooseFireMethod() + if (b.guns[i].name === "nail gun") b.guns[i].chooseFireMethod() + if (b.guns[i].name === "super balls") b.guns[i].chooseFireMethod() + if (b.guns[i].name === "harpoon") b.guns[i].chooseFireMethod() + if (b.guns[i].name === "foam") b.guns[i].chooseFireMethod() + } + b.zeroBotCount() + + m.isSwitchingWorlds = false + simulation.isChoosing = false; + b.setFireMethod() + b.setFireCD(); + for (let i = 0; i < b.guns.length; i++) b.guns[i].isRecentlyShown = false //reset recently shown back to zero + for (let i = 0; i < m.fieldUpgrades.length; i++) m.fieldUpgrades[i].isRecentlyShown = false //reset recently shown back to zero + for (let i = 0; i < tech.tech.length; i++) tech.tech[i].isRecentlyShown = false //reset recently shown back to zero + + powerUps.tech.choiceLog = []; + powerUps.gun.choiceLog = []; + powerUps.field.choiceLog = []; + powerUps.totalPowerUps = 0; + powerUps.research.count = 0; + powerUps.boost.endCycle = 0 + powerUps.isFieldSpawned = false + m.setFillColors(); + input.isPauseKeyReady = true + simulation.wipe = function () { //set wipe to normal + ctx.clearRect(0, 0, canvas.width, canvas.height); + } + m.lastHit = 0 + m.hole.isOn = false + simulation.paused = false; + engine.timing.timeScale = 1; + simulation.fpsCap = simulation.fpsCapDefault; + simulation.isAutoZoom = true; + simulation.makeGunHUD(); + simulation.lastLogTime = 0; + mobs.mobDeaths = 0 + level.isFlipped = false + level.onLevel = 0; + level.levelsCleared = 0; + level.updateDifficulty() + // level.setConstraints() + + simulation.clearNow = true; + document.getElementById("text-log").style.display = "none" + document.getElementById("fade-out").style.opacity = 0; + document.title = "n-gon"; + simulation.inGameConsole(`Math.seed = ${Math.initialSeed}`); + simulation.inGameConsole(`const engine = Engine.create(); //simulation begin`); + simulation.inGameConsole(`engine.timing.timeScale = 1`); + m.alive = true; + m.definePlayerMass(); + m.onGround = false + m.lastOnGroundCycle = 0 + m.health = 0; + level.isLowHeal = false + m.addHealth(0.25) + m.drop(); + m.holdingTarget = null + + //set to default field + tech.healMaxEnergyBonus = 0 + m.energy = 0 + m.immuneCycle = 0; + m.coupling = 0 + m.setField(0) //this calls m.couplingChange(), which sets max health and max energy + //exit testing + if (simulation.testing) { + simulation.testing = false; + simulation.loop = simulation.normalLoop + if (simulation.isConstructionMode) document.getElementById("construct").style.display = 'none' + } + simulation.isCheating = false + simulation.firstRun = false; + build.hasExperimentalMode = false + build.isExperimentSelection = false; + build.isExperimentRun = false; + + + //setup checks + if (!localSettings.isHideHUD) { + simulation.ephemera.push({ + name: "dmgDefBars", count: 0, do() { + if (!(m.cycle % 15)) { //4 times a second + const defense = m.defense() //* simulation.dmgScale //update defense bar + if (m.lastCalculatedDefense !== defense) { + document.getElementById("defense-bar").style.width = Math.floor(300 * m.maxHealth * (1 - defense)) + "px"; + m.lastCalculatedDefense = defense + } + const damage = tech.damageFromTech() //* m.dmgScale //update damage bar + if (m.lastCalculatedDamage !== damage) { + document.getElementById("damage-bar").style.height = Math.floor((Math.atan(0.25 * damage - 0.25) + 0.25) * 0.53 * canvas.height) + "px"; + m.lastCalculatedDamage = damage + } + } + }, + }) + } + simulation.ephemera.push({ + name: "uniqueName", count: 0, do() { + if (!(m.cycle % 60)) { //once a second + //energy overfill + if (m.energy > m.maxEnergy) { + m.energy = m.maxEnergy + (m.energy - m.maxEnergy) * tech.overfillDrain //every second energy above max energy loses 25% + if (m.energy > 1000000) m.energy = 1000000 + } + if (m.pos.y > simulation.fallHeight) { // if 4000px deep + if (level.fallMode === "start") { + //infinite falling. teleport to sky after falling + + simulation.ephemera.push({ + name: "slow player", + count: 160, //cycles before it self removes + do() { + this.count-- + if (this.count < 0 || m.onGround) simulation.removeEphemera(this.name) + if (player.velocity.y > 70) Matter.Body.setVelocity(player, { x: player.velocity.x * 0.99, y: player.velocity.y * 0.99 }); + if (player.velocity.y > 90) Matter.Body.setVelocity(player, { x: player.velocity.x * 0.99, y: player.velocity.y * 0.99 }); + }, + }) + + const before = { x: player.position.x, y: player.position.y, } + Matter.Body.setPosition(player, { x: level.enter.x, y: level.enter.y - 3000 }); + // Matter.Body.setPosition(player, level.fallPosition); + + const change = { x: before.x - player.position.x, y: before.y - player.position.y } + // translate camera smoothly to preserve illusion to endless fall + m.transX += change.x + m.transY += change.y + simulation.mouseInGame.x = (simulation.mouse.x - canvas.width2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.width2 - m.transX; + simulation.mouseInGame.y = (simulation.mouse.y - canvas.height2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.height2 - m.transY; + m.angle = Math.atan2(simulation.mouseInGame.y - m.pos.y, simulation.mouseInGame.x - m.pos.x); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) Matter.Body.setPosition(bullet[i], Vector.sub(bullet[i].position, change)); + } + } else if (level.fallMode === "position") { //fall and stay in the same horizontal position + simulation.ephemera.push({ + name: "slow player", + count: 180, //cycles before it self removes + do() { + this.count-- + if (this.count < 0 || m.onGround) simulation.removeEphemera(this.name) + if (player.velocity.y > 70) Matter.Body.setVelocity(player, { x: player.velocity.x * 0.99, y: player.velocity.y * 0.99 }); + if (player.velocity.y > 90) Matter.Body.setVelocity(player, { x: player.velocity.x * 0.99, y: player.velocity.y * 0.99 }); + }, + }) + const before = { x: player.position.x, y: player.position.y, } + const posXClamped = Math.min(Math.max(level.fallModeBounds.left, player.position.x), level.fallModeBounds.right) + Matter.Body.setPosition(player, { x: posXClamped, y: level.enter.y - 4000 }); + + // translate camera smoothly to preserve illusion to endless fall + const change = { x: before.x - posXClamped, y: before.y - player.position.y } + m.transX += change.x + m.transY += change.y + simulation.mouseInGame.x = (simulation.mouse.x - canvas.width2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.width2 - m.transX; + simulation.mouseInGame.y = (simulation.mouse.y - canvas.height2) / simulation.zoom * simulation.edgeZoomOutSmooth + canvas.height2 - m.transY; + m.angle = Math.atan2(simulation.mouseInGame.y - m.pos.y, simulation.mouseInGame.x - m.pos.x); + + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) Matter.Body.setPosition(bullet[i], Vector.sub(bullet[i].position, change)); + } + } else { //get hurt and go to start + Matter.Body.setVelocity(player, { x: 0, y: 0 }); + Matter.Body.setPosition(player, { x: level.enter.x + 50, y: level.enter.y - 20 }); + // move bots + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) { + Matter.Body.setPosition(bullet[i], Vector.add(player.position, { x: 250 * (Math.random() - 0.5), y: 250 * (Math.random() - 0.5) })); + Matter.Body.setVelocity(bullet[i], { x: 0, y: 0 }); + } + } + } + + + + + + } + if (isNaN(player.position.x)) m.death(); + if (m.lastKillCycle + 300 > m.cycle) { //effects active for 5 seconds after killing a mob + if (tech.isEnergyRecovery && m.immuneCycle < m.cycle) { + m.energy += m.maxEnergy * 0.05 * level.isReducedRegen + simulation.drawList.push({ //add dmg to draw queue + x: m.pos.x, + y: m.pos.y - 45, + radius: Math.sqrt(m.maxEnergy * 0.05) * 60, + color: "rgba(0, 204, 255,0.4)", //#0cf + time: 4 + }); + } + if (tech.isHealthRecovery) { + if (tech.isEnergyHealth) { + if (m.immuneCycle < m.cycle) { + m.energy += m.maxEnergy * 0.005 * level.isReducedRegen + simulation.drawList.push({ //add dmg to draw queue + x: m.pos.x, + y: m.pos.y, + radius: Math.sqrt(m.maxEnergy * 0.02) * 60, + color: "rgba(0, 204, 255,0.4)", //#0cf + time: 4 + }); + } + } else { + const heal = 0.005 * m.maxHealth + m.addHealth(heal) + simulation.drawList.push({ //add dmg to draw queue + x: m.pos.x, + y: m.pos.y, + radius: Math.sqrt(heal) * 150, + color: "rgba(0,255,200,0.5)", + time: 4 + }); + } + } + } + + if (!(m.cycle % 420)) { //once every 7 seconds + //check if player is inside the map + if (Matter.Query.point(map, m.pos).length > 0 || Matter.Query.point(map, player.position).length > 0) { + //check for the next few seconds to see if being stuck continues + simulation.ephemera.push({ + name: "stuck", + count: 240, //cycles before it self removes + do() { + if (Matter.Query.point(map, m.pos).length > 0 || Matter.Query.point(map, player.position).length > 0) { + this.count-- + + if (this.count < 0) { + simulation.removeEphemera(this.name) + Matter.Body.setVelocity(player, { x: 0, y: 0 }); + Matter.Body.setPosition(player, { x: level.enter.x + 50, y: level.enter.y - 20 }); + } + } else { + simulation.removeEphemera(this.name) + } + }, + }) + } + if (tech.isZeno) { + if (tech.isEnergyHealth) { + m.energy *= 0.95 + } else { + m.health *= 0.95 //remove 5% + m.displayHealth(); + } + + } + if (tech.cyclicImmunity && m.immuneCycle < m.cycle + tech.cyclicImmunity) m.immuneCycle = m.cycle + tech.cyclicImmunity; //player is immune to damage for 60 cycles + + + + let i = body.length; + while (i--) { + if (body[i].position.y > simulation.fallHeight) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + } + } + i = powerUp.length + while (i--) { + if (powerUp[i].position.y > simulation.fallHeight) { + Matter.Body.setVelocity(powerUp[i], { x: 0, y: 0 }); + if (level.fallMode === "position") { + const posXClamped = Math.min(Math.max(level.fallModeBounds.left, powerUp[i].position.x), level.fallModeBounds.right) + Matter.Body.setPosition(powerUp[i], { x: posXClamped, y: level.enter.y - 3000 }); + } else { + Matter.Body.setPosition(powerUp[i], { + x: level.exit.x + 30 * (Math.random() - 0.5), + y: level.exit.y + 30 * (Math.random() - 0.5) + }); + } + } + } + i = mob.length; + while (i--) { + if (mob[i].position.y > simulation.fallHeight) { + if (mob[i].isBoss && level.fallMode === "position") { + Matter.Body.setVelocity(mob[i], { x: 0, y: 0 }); + const posXClamped = Math.min(Math.max(level.fallModeBounds.left, mob[i].position.x), level.fallModeBounds.right) + Matter.Body.setPosition(mob[i], { x: posXClamped, y: level.enter.y - 3000 }); + } else { + mob[i].death(); + } + } + } + + } + } + }, + }) + + //setup FPS cap + simulation.fpsInterval = 1000 / simulation.fpsCap; + simulation.then = Date.now(); + requestAnimationFrame(cycle); //starts game loop + }, + clearTimeouts() { + let id = window.setTimeout(function () { }, 0); + while (id--) { + window.clearTimeout(id); // will do nothing if no timeout with id is present + } + }, + clearNow: false, + clearMap() { + level.isVerticalFLipLevel = false + level.isProcedural = false; + level.fallMode = ""; + simulation.unFlipCameraVertical() + ctx.setTransform(1, 0, 0, 1, 0, 0); + if (m.alive) { + if (tech.isLongitudinal) b.guns[3].waves = []; //empty array of wave bullets + if (b.guns[10].have) { //do you have mines as a gun + let count = 0; + for (i = 0, len = bullet.length; i < len; i++) { //count mines left on map + if ( + (bullet[i].bulletType === "mine" && (!tech.isMineSentry || bullet[i].shots === undefined)) || + bullet[i].bulletType === "laser mine") { + count++ + } + } + if (tech.crouchAmmoCount) count = Math.ceil(count / 2) + b.guns[10].ammo += count + if (tech.ammoCap) b.guns[10].ammo = Math.min(tech.ammoCap, b.guns[10].ammo) + simulation.updateGunHUD(); + } + + if (tech.isMutualism && !tech.isEnergyHealth) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].isMutualismActive) { + m.health += 0.01 + 0.01 * ((bullet[i].isSpore || bullet[i].isFlea) ? 0 : 1) + if (m.health > m.maxHealth) m.health = m.maxHealth; + m.displayHealth(); + } + } + } + if (tech.isEndLevelPowerUp) { + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "tech") { + tech.giveTech() + } else if (powerUp[i].name === "gun") { + if (!tech.isOneGun) b.giveGuns("random") + } else if (powerUp[i].name === "field") { + if (m.fieldMode === 0) m.setField(Math.ceil(Math.random() * (m.fieldUpgrades.length - 1))) //pick a random field, but not field 0 + } else { + powerUp[i].effect(); + } + } + } + } + simulation.lastLogTime = 0; //clear previous messages + spawn.allowShields = true; + powerUps.totalPowerUps = powerUp.length + let holdTarget = (m.holdingTarget) ? m.holdingTarget : undefined //if player is holding something this remembers it before it gets deleted + tech.deathSpawnsFromBoss = 0; + simulation.fallHeight = 3000; + document.body.style.backgroundColor = "#eee" //"#d8dadf"; + // color.map = "#444"; + // color.bullet = "#FFFFFF"; + color = { //light + // background: "#ddd", // used instead: document.body.style.backgroundColor + block: "rgba(140,140,140,0.85)", + blockS: "#222", + map: "#444", + bullet: "#000" + } + simulation.draw.drawMapPath = simulation.draw.drawMapPathDefault + m.fireCDcycle = 0 + m.drop(); + m.hole.isOn = false; + simulation.drawList = []; + mobs.maxMobBody = 40 + + if (tech.isHealAttract && m.alive) { //send health power ups to the next level + let healCount = 0 + for (let i = 0, len = powerUp.length; i < len; i++) { + if (powerUp[i].name === "heal" && Vector.magnitudeSquared(Vector.sub(powerUp[i].position, m.pos)) < 1000000) healCount++ + } + //respawn health in animation frame + let respawnHeal = () => { + if (healCount > 0) { + requestAnimationFrame(respawnHeal); + if (!simulation.paused && !simulation.isChoosing) { + healCount-- + powerUps.directSpawn(level.enter.x + 50 + 100 * (Math.random() - 0.5), level.enter.y - 60 + 100 * (Math.random() - 0.5), "heal"); + } + } + } + requestAnimationFrame(respawnHeal); + } + if (tech.isDronesTravel && m.alive) { + //count drones + let droneCount = 0 + let sporeCount = 0 + let wormCount = 0 + let fleaCount = 0 + let deliveryCount = 0 + for (let i = 0; i < bullet.length; ++i) { + if (bullet[i].isDrone) { + droneCount++ + if (bullet[i].isImproved) deliveryCount++ + } else if (bullet[i].isSpore) { + sporeCount++ + } else if (bullet[i].wormSize) { + wormCount++ + } else if (bullet[i].isFlea) { + fleaCount++ + } + } + + //respawn drones in animation frame + requestAnimationFrame(() => { b.delayDrones({ x: level.enter.x + 50, y: level.enter.y - 60 }, droneCount, deliveryCount) }); + + //respawn spores in animation frame + let respawnSpores = () => { + if (sporeCount > 0) { + requestAnimationFrame(respawnSpores); + if (!simulation.paused && !simulation.isChoosing) { + sporeCount-- + const where = { + x: level.enter.x + 50, + y: level.enter.y - 60 + } + b.spore({ + x: where.x + 100 * (Math.random() - 0.5), + y: where.y + 120 * (Math.random() - 0.5) + }) + } + } + } + requestAnimationFrame(respawnSpores); + + //respawn worms in animation frame + let respawnWorms = () => { + if (wormCount > 0) { + requestAnimationFrame(respawnWorms); + if (!simulation.paused && !simulation.isChoosing) { + wormCount-- + const where = { + x: level.enter.x + 50, + y: level.enter.y - 60 + } + b.worm({ + x: where.x + 100 * (Math.random() - 0.5), + y: where.y + 120 * (Math.random() - 0.5) + }) + } + } + } + requestAnimationFrame(respawnWorms); + + //respawn fleas in animation frame + let respawnFleas = () => { + if (fleaCount > 0) { + requestAnimationFrame(respawnFleas); + if (!simulation.paused && !simulation.isChoosing) { + fleaCount-- + const where = { + x: level.enter.x + 50, + y: level.enter.y - 60 + } + const speed = 6 + 3 * Math.random() + const angle = 2 * Math.PI * Math.random() + b.flea({ + x: where.x + 100 * (Math.random() - 0.5), + y: where.y + 120 * (Math.random() - 0.5) + }, { + x: speed * Math.cos(angle), + y: speed * Math.sin(angle) + }) + } + } + } + requestAnimationFrame(respawnFleas); + } + if (tech.isQuantumEraser && m.alive) { + let count = 0 + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isDropPowerUp && mob[i].alive) count++ + } + count *= 0.3 //to fake the 25% chance, this makes it not random, and more predictable + let cycle = () => { //run after waiting a cycle for the map to be cleared + const types = ["heal", "ammo", "heal", "ammo", "research", "coupling", "boost", "tech", "gun", "field"] + for (let i = 0; i < count; i++) powerUps.spawnDelay(types[Math.floor(Math.random() * types.length)], 1) + } + requestAnimationFrame(cycle); + } + + function removeAll(array) { + // for (let i = 0; i < array.length; ++i) Matter.Composite.remove(engine.world, array[i]); + for (let i = 0; i < array.length; ++i) Matter.Composite.remove(engine.world, array[i]); + } + removeAll(map); + map = []; + removeAll(body); + body = []; + removeAll(mob); + mob = []; + removeAll(powerUp); + powerUp = []; + removeAll(cons); + cons = []; + removeAll(consBB); + consBB = []; + removeAll(bullet); + bullet = []; + removeAll(composite); + composite = []; + // if player was holding something this makes a new copy to hold + if (holdTarget && m.alive) { + len = body.length; + body[len] = Matter.Bodies.fromVertices(0, 0, holdTarget.vertices, { + friction: holdTarget.friction, + frictionAir: holdTarget.frictionAir, + frictionStatic: holdTarget.frictionStatic + }); + Matter.Body.setPosition(body[len], m.pos); + m.isHolding = true + m.holdingTarget = body[len]; + m.holdingTarget.collisionFilter.category = 0; + m.holdingTarget.collisionFilter.mask = 0; + m.definePlayerMass(m.defaultMass + m.holdingTarget.mass * m.holdingMassScale) + Composite.add(engine.world, m.holdingTarget); //add to world + m.holdingTarget.classType = "body" + } + //set fps back to default + simulation.fpsCap = simulation.fpsCapDefault + simulation.fpsInterval = 1000 / simulation.fpsCap; + }, + // getCoords: { + // //used when building maps, outputs a draw rect command to console, only works in testing mode + // pos1: { + // x: 0, + // y: 0 + // }, + // pos2: { + // x: 0, + // y: 0 + // }, + // out() { + // if (keys[49]) { + // simulation.getCoords.pos1.x = Math.round(simulation.mouseInGame.x / 25) * 25; + // simulation.getCoords.pos1.y = Math.round(simulation.mouseInGame.y / 25) * 25; + // } + // if (keys[50]) { + // //press 1 in the top left; press 2 in the bottom right;copy command from console + // simulation.getCoords.pos2.x = Math.round(simulation.mouseInGame.x / 25) * 25; + // simulation.getCoords.pos2.y = Math.round(simulation.mouseInGame.y / 25) * 25; + // window.getSelection().removeAllRanges(); + // var range = document.createRange(); + // range.selectNode(document.getElementById("test")); + // window.getSelection().addRange(range); + // document.execCommand("copy"); + // window.getSelection().removeAllRanges(); + // } + // } + // }, + testingOutput() { + ctx.fillStyle = "#000"; + ctx.textAlign = "center"; + ctx.fillText(`(${simulation.mouseInGame.x.toFixed(1)}, ${simulation.mouseInGame.y.toFixed(1)})`, simulation.mouse.x, simulation.mouse.y - 20); + }, + sight: { //credit to Cornbread2100 for adding this algorithm to n-gon + // square: 0, + intersectMap: [], //this is precalculated in simulation.draw.lineOfSightPrecalculation() + getIntersection(v1, v1End, domain) { + const intersections = simulation.sight.getIntersections(v1, v1End, domain); + var best = { x: v1End.x, y: v1End.y, dist: (v1End.x - v1.x) ** 2 + (v1End.y - v1.y) ** 2 } + for (const intersection of intersections) { + const dist = (intersection.x - v1.x) ** 2 + (intersection.y - v1.y) ** 2; + if (dist < best.dist) best = { x: intersection.x, y: intersection.y, dist: dist } + } + best.dist = Math.sqrt(best.dist) + return best; + }, + getIntersections(v1, v1End, domain) { + const intersections = []; + for (const obj of domain) { + for (var i = 0; i < obj.vertices.length - 1; i++) { + results = simulation.checkLineIntersection(v1, v1End, obj.vertices[i], obj.vertices[i + 1]); + if (results.onLine1 && results.onLine2) intersections.push({ x: results.x, y: results.y }); + } + results = simulation.checkLineIntersection(v1, v1End, obj.vertices[obj.vertices.length - 1], obj.vertices[0]); + if (results.onLine1 && results.onLine2) intersections.push({ x: results.x, y: results.y }); + } + return intersections; + }, + circleLoS(pos, radius) { + function allCircleLineCollisions(c, radius, domain) { + var lines = []; + for (const obj of domain) { + for (var i = 0; i < obj.vertices.length - 1; i++) lines.push(circleLineCollisions(obj.vertices[i], obj.vertices[i + 1], c, radius)); + lines.push(circleLineCollisions(obj.vertices[obj.vertices.length - 1], obj.vertices[0], c, radius)); + } + const collisionLines = []; + for (const line of lines) { + if (line.length == 2) { + // const distance1 = Math.sqrt((line[0].x - c.x) ** 2 + (line[0].y - c.y) ** 2) + // const angle1 = Math.atan2(line[0].y - c.y, line[0].x - c.x); + // const queryPoint1 = { + // x: Math.cos(angle1) * (distance1 - 1) + c.x, + // y: Math.sin(angle1) * (distance1 - 1) + c.y + // } + // const distance2 = Math.sqrt((line[1].x - c.x) ** 2 + (line[1].y - c.y) ** 2) + // const angle2 = Math.atan2(line[1].y - c.y, line[1].x - c.x); + // const queryPoint2 = { + // x: Math.cos(angle2) * (distance2 - 1) + c.x, + // y: Math.sin(angle2) * (distance2 - 1) + c.y + // } + collisionLines.push(line) + } + } + + return collisionLines; + } + + function circleLineCollisions(a, b, c, radius) { + // calculate distances + const angleOffset = Math.atan2(b.y - a.y, b.x - a.x); + const sideB = Math.sqrt((a.x - c.x) ** 2 + (a.y - c.y) ** 2); + const sideC = Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); + const sideA = Math.sqrt((c.x - b.x) ** 2 + (c.y - b.y) ** 2); + + // calculate the closest point on line AB to point C + const angleA = Math.acos((sideB ** 2 + sideC ** 2 - sideA ** 2) / (2 * sideB * sideC)) * (a.x - c.x) / -Math.abs(a.x - c.x) + const sideAD = Math.cos(angleA) * sideB; + const d = { // closest point + x: Math.cos(angleOffset) * sideAD + a.x, + y: Math.sin(angleOffset) * sideAD + a.y + } + const distance = Math.sqrt((d.x - c.x) ** 2 + (d.y - c.y) ** 2); + if (distance == radius) { + // tangent + return [d]; + } else if (distance < radius) { + // secant + const angleOffset = Math.atan2(d.y - c.y, d.x - c.x); + const innerAngle = Math.acos(distance / radius); + const intersection1 = { + x: Math.cos(angleOffset + innerAngle) * radius + c.x, + y: Math.sin(angleOffset + innerAngle) * radius + c.y + } + + const intersection2 = { + x: Math.cos(angleOffset - innerAngle) * radius + c.x, + y: Math.sin(angleOffset - innerAngle) * radius + c.y + } + + const distance1 = { + a: Math.sqrt((intersection1.x - a.x) ** 2 + (intersection1.y - a.y) ** 2), + b: Math.sqrt((intersection1.x - b.x) ** 2 + (intersection1.y - b.y) ** 2) + } + const distance2 = { + a: Math.sqrt((intersection2.x - a.x) ** 2 + (intersection2.y - a.y) ** 2), + b: Math.sqrt((intersection2.x - b.x) ** 2 + (intersection2.y - b.y) ** 2) + } + const result = []; + if (Math.abs(sideC - (distance1.a + distance1.b)) < 0.01) { + result.push(intersection1); + } else { + if (distance1.a < distance1.b) { + if (sideB <= radius) result.push(a); + } else { + if (sideA <= radius) result.push(b) + } + } + if (Math.abs(sideC - (distance2.a + distance2.b)) < 0.01) { + result.push(intersection2); + } else { + if (distance2.a <= distance2.b) { + if (sideB <= radius) result.push(a); + } else { + if (sideA <= radius) result.push(b) + } + } + + return result; + } else { + // no intersection + return []; + } + } + + var vertices = []; + for (const obj of simulation.sight.intersectMap) { + for (var i = 0; i < obj.vertices.length; i++) { + const vertex = obj.vertices[i]; + const angleToVertex = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + // const distanceToVertex = Math.sqrt((vertex.x - pos.x) ** 2 + (vertex.y - pos.y) ** 2); + // const queryPoint = { x: Math.cos(angleToVertex) * (distanceToVertex - 1) + pos.x, y: Math.sin(angleToVertex) * (distanceToVertex - 1) + pos.y } + const queryPoint = { x: Math.cos(angleToVertex + Math.PI) + vertex.x, y: Math.sin(angleToVertex + Math.PI) + vertex.y } + + if (Matter.Query.ray(map, pos, queryPoint).length == 0) { + var distance = Math.sqrt((vertex.x - pos.x) ** 2 + (vertex.y - pos.y) ** 2); + var endPoint = { x: vertex.x, y: vertex.y } + + if (distance > radius) { + const angle = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + endPoint = { x: Math.cos(angle) * radius + pos.x, y: Math.sin(angle) * radius + pos.y } + distance = radius + } + + var best = simulation.sight.getIntersection(pos, endPoint, map); + if (best.dist >= distance) best = { x: endPoint.x, y: endPoint.y, dist: distance } + vertices.push(best) + + var angle = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + endPoint = { x: Math.cos(angle + 0.001) * radius + pos.x, y: Math.sin(angle + 0.001) * radius + pos.y } + best = simulation.sight.getIntersection(pos, endPoint, map); + + if (best.dist >= radius) best = { x: endPoint.x, y: endPoint.y, dist: radius } + vertices.push(best) + + angle = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + endPoint = { x: Math.cos(angle - 0.001) * radius + pos.x, y: Math.sin(angle - 0.001) * radius + pos.y } + + best = simulation.sight.getIntersection(pos, endPoint, map); + if (best.dist >= radius) best = { x: endPoint.x, y: endPoint.y, dist: radius } + vertices.push(best) + } + } + } + + const outerCollisions = allCircleLineCollisions(pos, radius, map); + const circleCollisions = []; + for (const line of outerCollisions) { + for (const vertex of line) { + const distance = Math.sqrt((vertex.x - pos.x) ** 2 + (vertex.y - pos.y) ** 2) + const angle = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + const queryPoint = { x: Math.cos(angle + Math.PI) + vertex.x, y: Math.sin(angle + Math.PI) + vertex.y } + if (Math.abs(distance - radius) < 1 && Matter.Query.ray(map, pos, queryPoint).length == 0) circleCollisions.push(vertex) + } + } + for (var i = 0; i < circleCollisions.length; i++) { + const vertex = circleCollisions[i]; + var nextIndex = i + 1; + if (nextIndex == circleCollisions.length) nextIndex = 0; + const nextVertex = circleCollisions[nextIndex]; + const angle1 = Math.atan2(vertex.y - pos.y, vertex.x - pos.x); + const angle2 = Math.atan2(nextVertex.y - pos.y, nextVertex.x - pos.x); + var newAngle; + if (Math.abs(angle1) > Math.PI / 2 && Math.abs(angle2) > Math.PI / 2 && angle1 / Math.abs(angle1) != angle2 / Math.abs(angle2)) { + // if the arc between the to points crosses over the left side (+/- pi radians) + const newAngle1 = (Math.PI - Math.abs(angle1)) * (angle1 / Math.abs(angle1)); + const newAngle2 = (Math.PI - Math.abs(angle2)) * (angle2 / Math.abs(angle2)); + newAngle = (newAngle1 + newAngle2) / 2; + var multiplier; + if (newAngle == 0) { + multiplier = 1; + } else { + multiplier = newAngle / Math.abs(newAngle); + } + newAngle = Math.PI * multiplier - newAngle * multiplier; + test = true; + } else { + newAngle = (angle1 + angle2) / 2; + } + + // shoot ray between them + var endPoint = { x: Math.cos(newAngle) * radius + pos.x, y: Math.sin(newAngle) * radius + pos.y } + var best = simulation.sight.getIntersection(pos, endPoint, map); + vertices.push(vertex); + if (best.dist <= radius) vertices.push({ x: best.x, y: best.y }) + } + vertices.sort((a, b) => Math.atan2(a.y - pos.y, a.x - pos.x) - Math.atan2(b.y - pos.y, b.x - pos.x)); + return vertices; + }, + }, + draw: { + // powerUp() { //is set by Bayesian tech + // // ctx.globalAlpha = 0.4 * Math.sin(m.cycle * 0.15) + 0.6; + // // for (let i = 0, len = powerUp.length; i < len; ++i) { + // // ctx.beginPath(); + // // ctx.arc(powerUp[i].position.x, powerUp[i].position.y, powerUp[i].size, 0, 2 * Math.PI); + // // ctx.fillStyle = powerUp[i].color; + // // ctx.fill(); + // // } + // // ctx.globalAlpha = 1; + // }, + // powerUpNormal() { //back up in case power up draw gets changed + // ctx.globalAlpha = 0.4 * Math.sin(m.cycle * 0.15) + 0.6; + // for (let i = 0, len = powerUp.length; i < len; ++i) { + // ctx.beginPath(); + // ctx.arc(powerUp[i].position.x, powerUp[i].position.y, powerUp[i].size, 0, 2 * Math.PI); + // ctx.fillStyle = powerUp[i].color; + // ctx.fill(); + // } + // ctx.globalAlpha = 1; + // }, + // powerUpBonus() { //draws crackle effect for bonus power ups + // ctx.globalAlpha = 0.4 * Math.sin(m.cycle * 0.15) + 0.6; + // for (let i = 0, len = powerUp.length; i < len; ++i) { + // ctx.beginPath(); + // ctx.arc(powerUp[i].position.x, powerUp[i].position.y, powerUp[i].size, 0, 2 * Math.PI); + // ctx.fillStyle = powerUp[i].color; + // ctx.fill(); + // } + // ctx.globalAlpha = 1; + // for (let i = 0, len = powerUp.length; i < len; ++i) { + // if (powerUp[i].isDuplicated && Math.random() < 0.1) { + // //draw electricity + // const mag = 5 + powerUp[i].size / 5 + // let unit = Vector.rotate({ + // x: mag, + // y: mag + // }, 2 * Math.PI * Math.random()) + // let path = { + // x: powerUp[i].position.x + unit.x, + // y: powerUp[i].position.y + unit.y + // } + // ctx.beginPath(); + // ctx.moveTo(path.x, path.y); + // for (let i = 0; i < 6; i++) { + // unit = Vector.rotate(unit, 3 * (Math.random() - 0.5)) + // path = Vector.add(path, unit) + // ctx.lineTo(path.x, path.y); + // } + // ctx.lineWidth = 0.5 + 2 * Math.random(); + // ctx.strokeStyle = "#000" + // ctx.stroke(); + // } + // } + // }, + + // map: function() { + // ctx.beginPath(); + // for (let i = 0, len = map.length; i < len; ++i) { + // let vertices = map[i].vertices; + // ctx.moveTo(vertices[0].x, vertices[0].y); + // for (let j = 1; j < vertices.length; j += 1) { + // ctx.lineTo(vertices[j].x, vertices[j].y); + // } + // ctx.lineTo(vertices[0].x, vertices[0].y); + // } + // ctx.fillStyle = "#444"; + // ctx.fill(); + // }, + mapPath: null, //holds the path for the map to speed up drawing + setPaths() { + //runs at each new level to store the path for the map since the map doesn't change + simulation.draw.mapPath = new Path2D(); + for (let i = 0, len = map.length; i < len; ++i) { + let vertices = map[i].vertices; + simulation.draw.mapPath.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j += 1) { + simulation.draw.mapPath.lineTo(vertices[j].x, vertices[j].y); + } + simulation.draw.mapPath.lineTo(vertices[0].x, vertices[0].y); + } + }, + lineOfSightPrecalculation() { + simulation.sight.intersectMap = []; + for (var i = 0; i < map.length; i++) { + const obj = map[i]; + const newVertices = []; + const restOfMap = [...map].slice(0, i).concat([...map].slice(i + 1)) + for (var j = 0; j < obj.vertices.length - 1; j++) { + var intersections = simulation.sight.getIntersections(obj.vertices[j], obj.vertices[j + 1], restOfMap); + newVertices.push(obj.vertices[j]); + for (const vertex of intersections) newVertices.push({ x: vertex.x, y: vertex.y }); + } + intersections = simulation.sight.getIntersections(obj.vertices[obj.vertices.length - 1], obj.vertices[0], restOfMap); + newVertices.push(obj.vertices[obj.vertices.length - 1]); + for (const vertex of intersections) newVertices.push({ x: vertex.x, y: vertex.y }); + //draw the vertices as black circles for debugging + // for (const vertex of newVertices) { + // ctx.beginPath(); + // ctx.moveTo(vertex.x, vertex.y); + // ctx.arc(vertex.x, vertex.y, 10, 0, 2 * Math.PI); + // ctx.fillStyle = '#000'; + // ctx.fill() + // } + simulation.sight.intersectMap.push({ vertices: newVertices }); + } + }, + drawMapPath() { }, + drawMapPathDefault() { + ctx.fillStyle = color.map; + ctx.fill(simulation.draw.mapPath); + }, + drawMapSight() { + if (!simulation.isTimeSkipping) { + const pos = m.pos + const radius = 4000 + const vertices = simulation.sight.circleLoS(pos, radius); + if (vertices.length) { + ctx.beginPath(); + ctx.moveTo(vertices[0].x, vertices[0].y); + for (var i = 1; i < vertices.length; i++) { + var currentDistance = Math.sqrt((vertices[i - 1].x - pos.x) ** 2 + (vertices[i - 1].y - pos.y) ** 2); + var newDistance = Math.sqrt((vertices[i].x - pos.x) ** 2 + (vertices[i].y - pos.y) ** 2); + if (Math.abs(currentDistance - radius) < 1 && Math.abs(newDistance - radius) < 1) { + const currentAngle = Math.atan2(vertices[i - 1].y - pos.y, vertices[i - 1].x - pos.x); + const newAngle = Math.atan2(vertices[i].y - pos.y, vertices[i].x - pos.x); + ctx.arc(pos.x, pos.y, radius, currentAngle, newAngle); + } else { + ctx.lineTo(vertices[i].x, vertices[i].y) + } + } + newDistance = Math.sqrt((vertices[0].x - pos.x) ** 2 + (vertices[0].y - pos.y) ** 2); + currentDistance = Math.sqrt((vertices[vertices.length - 1].x - pos.x) ** 2 + (vertices[vertices.length - 1].y - pos.y) ** 2); + if (Math.abs(currentDistance - radius) < 1 && Math.abs(newDistance - radius) < 1) { + const currentAngle = Math.atan2(vertices[vertices.length - 1].y - pos.y, vertices[vertices.length - 1].x - pos.x); + const newAngle = Math.atan2(vertices[0].y - pos.y, vertices[0].x - pos.x); + ctx.arc(pos.x, pos.y, radius, currentAngle, newAngle); + } else { + ctx.lineTo(vertices[0].x, vertices[0].y) + } + + // outline map edges, best with lighter colored document.body.style.backgroundColor + ctx.strokeStyle = "#000"; + ctx.lineWidth = 5; + ctx.stroke(simulation.draw.mapPath); + + ctx.globalCompositeOperation = "destination-in"; + ctx.fillStyle = "#000"; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + + // make map visible + // ctx.fill(simulation.draw.mapPath); + // ctx.fillStyle = "#000"; + + ctx.clip(); //this doesn't seem to be required, but it helps with performance, probably stops the canvas context from drawing the whole map + } + } + }, + body() { + ctx.beginPath(); + for (let i = 0, len = body.length; i < len; ++i) { + let vertices = body[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + } + ctx.lineWidth = 2; + ctx.fillStyle = color.block; + ctx.fill(); + ctx.strokeStyle = color.blockS; + ctx.stroke(); + }, + cons() { + ctx.beginPath(); + for (let i = 0, len = cons.length; i < len; ++i) { + ctx.moveTo(cons[i].pointA.x, cons[i].pointA.y); + // ctx.lineTo(cons[i].bodyB.position.x, cons[i].bodyB.position.y); + ctx.lineTo(cons[i].bodyB.position.x + cons[i].pointB.x, cons[i].bodyB.position.y + cons[i].pointB.y); + } + for (let i = 0, len = consBB.length; i < len; ++i) { + ctx.moveTo(consBB[i].bodyA.position.x, consBB[i].bodyA.position.y); + ctx.lineTo(consBB[i].bodyB.position.x, consBB[i].bodyB.position.y); + } + ctx.lineWidth = 2; + // ctx.strokeStyle = "#999"; + ctx.strokeStyle = "rgba(0,0,0,0.15)"; + ctx.stroke(); + }, + wireFrame() { + // ctx.textAlign = "center"; + // ctx.textBaseline = "middle"; + // ctx.fillStyle = "#999"; + const bodies = Composite.allBodies(engine.world); + ctx.beginPath(); + for (let i = 0; i < bodies.length; ++i) { + //ctx.fillText(bodies[i].id,bodies[i].position.x,bodies[i].position.y); //shows the id of every body + let vertices = bodies[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + } + ctx.lineWidth = 1; + ctx.strokeStyle = "#000"; + ctx.stroke(); + }, + testing() { + //jump + ctx.beginPath(); + let bodyDraw = jumpSensor.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(255, 0, 0, 0.5)"; + ctx.fill(); + // ctx.strokeStyle = "#000"; + // ctx.stroke(); + //main body + ctx.beginPath(); + bodyDraw = playerBody.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(0, 255, 255, 0.25)"; + ctx.fill(); + // ctx.stroke(); + //head + ctx.beginPath(); + bodyDraw = playerHead.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(255, 255, 0, 0.4)"; + ctx.fill(); + // ctx.stroke(); + //head sensor + ctx.beginPath(); + bodyDraw = headSensor.vertices; + ctx.moveTo(bodyDraw[0].x, bodyDraw[0].y); + for (let j = 1; j < bodyDraw.length; ++j) { + ctx.lineTo(bodyDraw[j].x, bodyDraw[j].y); + } + ctx.lineTo(bodyDraw[0].x, bodyDraw[0].y); + ctx.fillStyle = "rgba(0, 0, 255, 0.25)"; + ctx.fill(); + // ctx.stroke(); + } + }, + checkLineIntersection(v1, v1End, v2, v2End) { + // if the lines intersect, the result contains the x and y of the intersection (treating the lines as infinite) and booleans for whether line segment 1 or line segment 2 contain the point + let denominator, a, b, numerator1, numerator2; + let result = { + x: null, + y: null, + onLine1: false, + onLine2: false + }; + denominator = (v2End.y - v2.y) * (v1End.x - v1.x) - (v2End.x - v2.x) * (v1End.y - v1.y); + if (denominator == 0) { + return result; + } + a = v1.y - v2.y; + b = v1.x - v2.x; + numerator1 = (v2End.x - v2.x) * a - (v2End.y - v2.y) * b; + numerator2 = (v1End.x - v1.x) * a - (v1End.y - v1.y) * b; + a = numerator1 / denominator; + b = numerator2 / denominator; + + // if we cast these lines infinitely in both directions, they intersect here: + result.x = v1.x + a * (v1End.x - v1.x); + result.y = v1.y + a * (v1End.y - v1.y); + // if line1 is a segment and line2 is infinite, they intersect if: + if (a > 0 && a < 1) result.onLine1 = true; + // if line2 is a segment and line1 is infinite, they intersect if: + if (b > 0 && b < 1) result.onLine2 = true; + // if line1 and line2 are segments, they intersect if both of the above are true + return result; + }, + constructMouseDownPosition: { + x: 0, + y: 0 + }, + constructMapString: [], + constructCycle() { + if (simulation.isConstructionMode && simulation.constructMouseDownPosition) { + function round(num, round = 25) { + return Math.ceil(num / round) * round; + } + const x = round(simulation.constructMouseDownPosition.x) + const y = round(simulation.constructMouseDownPosition.y) + const dx = Math.max(25, round(simulation.mouseInGame.x) - x) + const dy = Math.max(25, round(simulation.mouseInGame.y) - y) + + ctx.strokeStyle = "#000" + ctx.lineWidth = 2; + ctx.strokeRect(x, y, dx, dy); + } + }, + enableConstructMode() { + level.isProcedural = false //this is set to be true in levels like labs that need x+ and y+ in front of positions + level.isVerticalFLipLevel = false + simulation.isConstructionMode = true; + simulation.isHorizontalFlipped = false; + simulation.isAutoZoom = false; + simulation.zoomScale = 2600; + simulation.setZoom(); + + document.body.addEventListener("mouseup", (e) => { + if (simulation.testing && simulation.constructMouseDownPosition) { + function round(num, round = 25) { + return Math.ceil(num / round) * round; + } + //clean up positions + const x = round(simulation.constructMouseDownPosition.x) + const y = round(simulation.constructMouseDownPosition.y) + const dx = Math.max(25, round(simulation.mouseInGame.x) - x) + const dy = Math.max(25, round(simulation.mouseInGame.y) - y) + if (e.button === 1) { + if (level.isProcedural) { + simulation.outputMapString(`spawn.randomMob(x+${x}, ${y}, 0);\n`); + } else { + simulation.outputMapString(`spawn.randomMob(${x}, ${y}, 0);\n`); + } + } else if (e.button === 4) { + simulation.outputMapString(`${Math.floor(simulation.constructMouseDownPosition.x)}, ${Math.floor(simulation.constructMouseDownPosition.y)}`); + } else if (simulation.mouseInGame.x > simulation.constructMouseDownPosition.x && simulation.mouseInGame.y > simulation.constructMouseDownPosition.y) { //make sure that the width and height are positive + if (e.button === 0) { //add map + // if (level.isProcedural) { + // simulation.outputMapString(`spawn.mapRect(x+${x}, ${y}, ${dx}, ${dy});\n`); + // } else { + // simulation.outputMapString(`spawn.mapRect(${x}, ${y}, ${dx}, ${dy});\n`); + // } + if (level.isProcedural) { + simulation.outputMapString(`spawn.mapRect(x+${x}, ${y}, ${dx}, ${dy});\n`); + } else if (level.isVerticalFLipLevel) { + console.log('hi') + simulation.outputMapString(`spawn.mapRect(${x}, ${y}, ${dx}, ${dy});\n`); + simulation.outputMapString(`//spawn.mapRect(${x}, ${-y - dy}, ${dx}, ${dy});\n`); + } else { + simulation.outputMapString(`spawn.mapRect(${x}, ${y}, ${dx}, ${dy});\n`); + } + //see map in world + spawn.mapRect(x, y, dx, dy); + len = map.length - 1 + map[len].collisionFilter.category = cat.map; + map[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(map[len], true); //make static + Composite.add(engine.world, map[len]); //add to world + simulation.draw.setPaths() //update map graphics + } else if (e.button === 2) { //add body + if (level.isProcedural) { + simulation.outputMapString(`spawn.bodyRect(x+${x}, ${y}, ${dx}, ${dy});\n`); + } else { + simulation.outputMapString(`spawn.bodyRect(${x}, ${y}, ${dx}, ${dy});\n`); + } + //see map in world + spawn.bodyRect(x, y, dx, dy); + } + } + } + simulation.constructMouseDownPosition.x = undefined + simulation.constructMouseDownPosition.y = undefined + }); + simulation.constructMouseDownPosition.x = undefined + simulation.constructMouseDownPosition.y = undefined + document.body.addEventListener("mousedown", (e) => { + if (simulation.testing) { + simulation.constructMouseDownPosition.x = simulation.mouseInGame.x + simulation.constructMouseDownPosition.y = simulation.mouseInGame.y + } + }); + + document.body.addEventListener("wheel", (e) => { + if (e.deltaY > 0) { + simulation.setZoom(simulation.zoomScale / 0.9) + } else { + simulation.setZoom(simulation.zoomScale * 0.9) + } + }); + + + + + //undo last element added after you press z + document.body.addEventListener("keydown", (event) => { // e.keyCode z=90 m=77 b=66 shift = 16 c = 67 + if (simulation.testing && event.code === "KeyZ" && simulation.constructMapString.length) { + if (simulation.constructMapString[simulation.constructMapString.length - 1][6] === 'm') { //remove map from current level + const index = map.length - 1 + Matter.Composite.remove(engine.world, map[index]); + map.splice(index, 1); + simulation.draw.setPaths() //update map graphics + } else if (simulation.constructMapString[simulation.constructMapString.length - 1][6] === 'b') { //remove body from current level + const index = body.length - 1 + Matter.Composite.remove(engine.world, body[index]); + body.splice(index, 1); + } + simulation.constructMapString.pop(); + simulation.outputMapString(); + } + }); + }, + outputMapString(string) { + if (string) simulation.constructMapString.push(string) //store command as a string in the next element of an array + let out = "" //combine set of map strings to one string + let outHTML = "" + for (let i = 0, len = simulation.constructMapString.length; i < len; i++) { + out += simulation.constructMapString[i]; + outHTML += "
" + simulation.constructMapString[i] + "
" + } + console.log(out) + navigator.clipboard.writeText(out).then(function () { + /* clipboard successfully set */ + }, function () { + /* clipboard write failed */ + console.log('copy failed') + }); + document.getElementById("construct").innerHTML = outHTML + }, + // copyToClipBoard(value) { + // // Create a fake textarea + // const textAreaEle = document.createElement('textarea'); + + // // Reset styles + // textAreaEle.style.border = '0'; + // textAreaEle.style.padding = '0'; + // textAreaEle.style.margin = '0'; + + // // Set the absolute position + // // User won't see the element + // textAreaEle.style.position = 'absolute'; + // textAreaEle.style.left = '-9999px'; + // textAreaEle.style.top = `0px`; + + // // Set the value + // textAreaEle.value = value + + // // Append the textarea to body + // document.body.appendChild(textAreaEle); + + // // Focus and select the text + // textAreaEle.focus(); + // textAreaEle.select(); + + // // Execute the "copy" command + // try { + // document.execCommand('copy'); + // } catch (err) { + // // Unable to copy + // console.log(err) + // } finally { + // // Remove the textarea + // document.body.removeChild(textAreaEle); + // } + // }, +}; \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/spawn.js b/WebGames-master/WebGames-master/n-gon-master/js/spawn.js new file mode 100644 index 00000000..9b9f2a8f --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/spawn.js @@ -0,0 +1,8578 @@ +//main object for spawning things in a level +const spawn = { + nonCollideBossList: ["cellBossCulture", "bomberBoss", "powerUpBoss", "growBossCulture"], + // other bosses: suckerBoss, laserBoss, tetherBoss, bounceBoss, sprayBoss, mineBoss, hopMotherBoss //these need a particular level to work so they are not included in the random pool + randomBossList: [ + "orbitalBoss", "historyBoss", "shooterBoss", "cellBossCulture", "bomberBoss", "spiderBoss", "launcherBoss", "laserTargetingBoss", + "powerUpBoss", "powerUpBossBaby", "streamBoss", "pulsarBoss", "spawnerBossCulture", "grenadierBoss", "growBossCulture", "blinkBoss", + "snakeSpitBoss", "laserBombingBoss", "blockBoss", "revolutionBoss", "slashBoss", "shieldingBoss", + "timeSkipBoss", "dragonFlyBoss", "beetleBoss", "sneakBoss", "mantisBoss", "laserLayerBoss", + "snakeBoss" + ], + bossTypeSpawnOrder: [], //preset list of boss names calculated at the start of a run by the randomSeed + bossTypeSpawnIndex: 0, //increases as the boss type cycles + randomLevelBoss(x, y, options = []) { + if (options.length === 0) { + const boss = spawn.bossTypeSpawnOrder[spawn.bossTypeSpawnIndex++ % spawn.bossTypeSpawnOrder.length] + spawn[boss](x, y) + } else { + spawn[options[Math.floor(Math.random() * options.length)]](x, y) + } + }, + pickList: ["starter", "starter"], + fullPickList: [ + "slasher", "slasher", "slasher2", "slasher3", + "hopper", "hopper", "hopMother", "hopMother", + "stabber", "stabber", "stabber", + "springer", "springer", "springer", + "stinger", "stinger", "stinger", + "flutter", "flutter", + "striker", "striker", + "shooter", "shooter", + "grenadier", "grenadier", + "pulsar", "pulsar", + "laser", "laser", + "laserLayer", "laserLayer", + "sneaker", "launcher", "launcherOne", "exploder", "sucker", "sniper", "spinner", "grower", "beamer", "spawner", "ghoster", "focuser" + ], + mobTypeSpawnOrder: [], //preset list of mob names calculated at the start of a run by the randomSeed + mobTypeSpawnIndex: 0, //increases as the mob type cycles + allowedGroupList: ["spinner", "striker", "springer", "laser", "focuser", "beamer", "exploder", "spawner", "shooter", "launcher", "launcherOne", "stabber", "sniper", "pulsar", "grenadier", "slasher", "flutter", "stinger", "laserLayer"], + setSpawnList() { //this is run at the start of each new level to determine the possible mobs for the level + spawn.pickList.splice(0, 1); + const push = spawn.mobTypeSpawnOrder[spawn.mobTypeSpawnIndex++ % spawn.mobTypeSpawnOrder.length] + spawn.pickList.push(push); + + // if (spawn.mobTypeSpawnIndex > spawn.mobTypeSpawnOrder.length) spawn.mobTypeSpawnIndex = 0 + //each level has 2 mobs: one new mob and one from the last level + // spawn.pickList.splice(0, 1); + // spawn.pickList.push(spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]); + }, + spawnChance(chance) { + const difficultyChance = (simulation.difficultyMode === 1) ? 1 : simulation.difficulty + return (Math.random() < chance + 0.07 * difficultyChance) && (mob.length < -1 + 16 * Math.log10(simulation.difficulty + 1)) + }, + randomMob(x, y, chance = 1) { + if (spawn.spawnChance(chance) || chance === Infinity) { + const pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x, y); + } + if (tech.isDuplicateMobs && Math.random() < tech.duplicationChance()) { + const pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x, y); + } + }, + randomSmallMob(x, y, + num = Math.max(Math.min(Math.round(Math.random() * simulation.difficulty * 0.2), 4), 0), + size = 16 + Math.ceil(Math.random() * 15), + chance = 1) { + if (spawn.spawnChance(chance)) { + for (let i = 0; i < num; ++i) { + const pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x + Math.round((Math.random() - 0.5) * 20) + i * size * 2.5, y + Math.round((Math.random() - 0.5) * 20), size); + } + } + if (tech.isDuplicateMobs && Math.random() < tech.duplicationChance()) { + for (let i = 0; i < num; ++i) { + const pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](x + Math.round((Math.random() - 0.5) * 20) + i * size * 2.5, y + Math.round((Math.random() - 0.5) * 20), size); + } + } + }, + randomGroup(x, y, chance = 1) { + if (spawn.spawnChance(chance) && simulation.difficulty > 2 || chance === Infinity) { + //choose from the possible picklist + let pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + //is the pick able to be a group? + let canBeGroup = false; + for (let i = 0, len = spawn.allowedGroupList.length; i < len; ++i) { + if (spawn.allowedGroupList[i] === pick) { + canBeGroup = true; + break; + } + } + if (canBeGroup) { + if (Math.random() < 0.55) { + spawn.nodeGroup(x, y, pick); + } else { + spawn.lineGroup(x, y, pick); + } + } else { + if (Math.random() < 0.1) { + spawn[pick](x, y, 90 + Math.random() * 40); //one extra large mob + spawn.spawnOrbitals(mob[mob.length - 1], mob[mob.length - 1].radius + 50 + 200 * Math.random(), 1) + // } else if (Math.random() < 0.35) { + // spawn.blockGroup(x, y) //hidden grouping blocks + } else { + pick = (Math.random() < 0.5) ? "randomList" : "random"; + if (Math.random() < 0.55) { + spawn.nodeGroup(x, y, pick); + } else { + spawn.lineGroup(x, y, pick); + } + } + } + } + }, + secondaryBossChance(x, y) { + if (simulation.difficultyMode > 2 && level.levelsCleared > 1) { + spawn.randomLevelBoss(x, y); + powerUps.spawn(x - 30, y, "ammo"); + powerUps.spawn(x + 30, y, "ammo"); + } else { + return false + } + }, + //mob templates ********************************************************************************************* + //*********************************************************************************************************** + darkMatter(x = m.pos.x, y = m.pos.y) { //immortal mob that follows player //if you have the tech it spawns at start of every level at the player + mobs.spawn(x, y, 3, 0.1, "transparent"); + let me = mob[mob.length - 1]; + me.stroke = "transparent" + me.isShielded = true; //makes it immune to damage + me.leaveBody = false; + me.isBadTarget = true; + me.isUnblockable = true; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.collisionFilter.category = 0; + me.collisionFilter.mask = 0; //cat.player //| cat.body + me.chaseSpeed = 3.3 + me.isDarkMatter = true; + me.frictionAir = 0.006 + me.onDeath = function () { + tech.isHarmDarkMatter = false; + } + me.do = function () { + if (!simulation.isTimeSkipping) { + const scale = ((tech.isMoveDarkMatter || tech.isNotDarkMatter) ? 1.6 : 1) * level.isReducedRegen + const sine = Math.sin(simulation.cycle * 0.015) + this.radius = 111 * tech.isDarkStar + 370 * (1 + 0.1 * sine) + //chase player + const sub = Vector.sub(player.position, this.position) + const mag = Vector.magnitude(sub) + // follow physics + if (tech.isMoveDarkMatter && m.crouch && input.down) { + Matter.Body.setVelocity(this, Vector.add(Vector.mult(this.velocity, 0.97), Vector.mult(player.velocity, 0.03))) + Matter.Body.setPosition(this, Vector.add(Vector.mult(this.position, 0.95), Vector.mult(player.position, 0.05))) + } + + const force = Vector.mult(Vector.normalise(sub), 0.000000003 * (this.distanceToPlayer() > 4000 ? 3 : 1)) + this.force.x += force.x + this.force.y += force.y + + if (tech.isNotDarkMatter) { + if (mag < this.radius) { //buff to player when inside radius + tech.isHarmDarkMatter = false; + } else { + tech.isHarmDarkMatter = true; + //draw halo + ctx.strokeStyle = "rgba(80,120,200,0.2)" //"rgba(255,255,0,0.2)" //ctx.strokeStyle = `rgba(0,0,255,${0.5+0.5*Math.random()})` + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 36, 0, 2 * Math.PI); + ctx.lineWidth = 10; + ctx.stroke(); + if (tech.isDarkEnergy) m.energy += 0.0017 * scale + } + } else { + if (mag < this.radius) { //buff to player when inside radius + tech.isHarmDarkMatter = true; + //draw halo + ctx.strokeStyle = "rgba(80,120,200,0.2)" //"rgba(255,255,0,0.2)" //ctx.strokeStyle = `rgba(0,0,255,${0.5+0.5*Math.random()})` + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 36, 0, 2 * Math.PI); + ctx.lineWidth = 10; + ctx.stroke(); + if (tech.isDarkEnergy) m.energy += 0.0017 * scale + } else { + tech.isHarmDarkMatter = false; + } + } + + //draw outline + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.radius + 15, 0, 2 * Math.PI); + ctx.strokeStyle = "#000" + ctx.lineWidth = 1; + ctx.stroke(); + if (tech.isDarkStar && !m.isCloak) { //&& !m.isTimeDilated + ctx.fillStyle = "rgba(10,0,40,0.4)" + ctx.fill() + //damage mobs + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && !mob[i].isShielded) { + if (Vector.magnitude(Vector.sub(this.position, mob[i].position)) - mob[i].radius < this.radius) { + const dmg = 0.03 * m.dmgScale * scale + mob[i].damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: mob[i].position.x, + y: mob[i].position.y, + radius: mob[i].radius + 8, + color: `rgba(10,0,40,0.1)`, + time: 4 + }); + } + } + } + } + //draw growing and fading out ring around the arc + ctx.beginPath(); + const rate = 150 + const r = simulation.cycle % rate + ctx.arc(this.position.x, this.position.y, 15 + this.radius + 0.3 * r, 0, 2 * Math.PI); + ctx.strokeStyle = `rgba(0,0,0,${0.5 * Math.max(0, 1 - 1.4 * r / rate)})` + ctx.stroke(); + } + } + }, + WIMP(x = level.exit.x + tech.wimpCount * 200 * (Math.random() - 0.5), y = level.exit.y + tech.wimpCount * 200 * (Math.random() - 0.5)) { //immortal mob that follows player //if you have the tech it spawns at start of every level at the exit + mobs.spawn(x, y, 3, 0.1, "transparent"); + let me = mob[mob.length - 1]; + me.stroke = "transparent" + me.isShielded = true; //makes it immune to damage + me.leaveBody = false; + me.isBadTarget = true; + me.isUnblockable = true; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.collisionFilter.category = 0; + me.collisionFilter.mask = 0; //cat.player //| cat.body + me.chaseSpeed = 1.2 + 2.3 * Math.random() + + me.awake = function () { + //chase player + const sub = Vector.sub(player.position, this.position) + const where = Vector.add(this.position, Vector.mult(Vector.normalise(sub), this.chaseSpeed)) + + Matter.Body.setPosition(this, { //hold position + x: where.x, + y: where.y + }); + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + + //aoe damage to player + if (m.immuneCycle < m.cycle && Vector.magnitude(Vector.sub(player.position, this.position)) < this.radius) { + const DRAIN = tech.isRadioactiveResistance ? 0.05 * 0.2 : 0.05 + if (m.energy > DRAIN) { + if (m.immuneCycle < m.cycle) m.energy -= DRAIN + } else { + m.energy = 0; + m.damage((tech.isRadioactiveResistance ? 0.005 * 0.2 : 0.005) * simulation.dmgScale) + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: this.radius, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + } + } + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.radius, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(25,139,170,${0.2 + 0.12 * Math.random()})`; + ctx.fill(); + this.radius = 100 * (1 + 0.25 * Math.sin(simulation.cycle * 0.03)) + } + me.do = function () { //wake up after the player moves + if (player.speed > 1 && !m.isCloak) { + if (this.distanceToPlayer() < 500) { + const unit = Vector.rotate({ x: 1, y: 0 }, Math.random() * 6.28) + Matter.Body.setPosition(this, Vector.add(player.position, Vector.mult(unit, 2000))) + } + setTimeout(() => { + this.do = this.awake; + }, 1000 * Math.random()); + } + this.checkStatus(); + }; + }, + finalBoss(x, y, radius = 300) { + mobs.spawn(x, y, 6, radius, "rgb(150,150,255)"); + let me = mob[mob.length - 1]; + setTimeout(() => { //fix mob in place, but allow rotation + me.constraint = Constraint.create({ + pointA: { x: me.position.x, y: me.position.y }, + bodyB: me, + stiffness: 1, + damping: 1 + }); + Composite.add(engine.world, me.constraint); + }, 1000); //add in a delay in case the level gets flipped left right + me.isBoss = true; + me.isFinalBoss = true; + me.frictionAir = 0.01; + me.memory = Infinity; + me.locatePlayer(); + me.hasRunDeathScript = false + me.cycle = 1; + + Matter.Body.setDensity(me, 0.2); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.14 + me.startingDamageReduction = me.damageReduction + me.nextHealthThreshold = 0.999 + me.invulnerableCount = 0 + me.isInvulnerable = false + me.totalModes = 0 + me.lastDamageCycle = 0 + me.onDamage = function () { + this.lastDamageCycle = this.cycle + if (this.health < this.nextHealthThreshold) { + if (this.health === 1) me.cycle = 1; //reset fight + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 //0.75,0.5,0.25 + this.invulnerableCount = 220 + 10 * simulation.difficultyMode //how long does invulnerable time last + this.isInvulnerable = true + this.damageReduction = 0 + } + }; + me.invulnerable = function () { + if (this.isInvulnerable) { + this.invulnerableCount-- + if (this.invulnerableCount < 0) { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + this.pushAway(); + this.mode[this.totalModes].enter() //enter new mode + this.totalModes++ + //spawn 6 mobs + me.mobType = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]; //fire a bullet from each vertex + for (let i = 0; i < 6; i++) me.spawnMobs(i) + + level.newLevelOrPhase() //run some new level tech effects + } + ctx.beginPath(); //draw invulnerable + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 15 + 6 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + ctx.fillStyle = `rgba(255,255,255,${Math.min(1, 120 / (this.invulnerableCount + 60))})`; + ctx.fill() + } + } + me.damageReductionDecay = function () { //slowly make the boss take more damage over time //damageReduction resets with each invulnerability phase + if (!(me.cycle % 60) && this.lastDamageCycle + 240 > this.cycle) this.damageReduction *= 1.04 //only decay once a second //only decay if the player has done damage in the last 4 seconds + } + me.mobType = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)] + me.spawnMobs = function (index = 0) { + const vertex = me.vertices[index] + const unit = Vector.normalise(Vector.sub(me.position, vertex)) + const where = Vector.add(vertex, Vector.mult(unit, -30)) + spawn[me.mobType](where.x + 50 * (Math.random() - 0.5), where.y + 50 * (Math.random() - 0.5)); + const velocity = Vector.mult(Vector.perp(unit), -10) //give the mob a rotational velocity as if they were attached to a vertex + Matter.Body.setVelocity(mob[mob.length - 1], { x: me.velocity.x + velocity.x, y: me.velocity.y + velocity.y }); + } + me.maxMobs = 400 + me.mode = [{ + name: "boulders", + spawnRate: Math.max(30, 170 - 5 * simulation.difficultyMode), + do() { + if (!(me.cycle % this.spawnRate) && mob.length < me.maxMobs) { + me.boulder(me.position.x, me.position.y + 250) + } + }, + enter() { }, + exit() { }, + }, + { + name: "mobs", + // whoSpawn: spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)], + spawnRate: Math.max(60, 240 - 20 * simulation.difficultyMode), + do() { + if (!(me.cycle % this.spawnRate) && mob.length < me.maxMobs) { + me.torque += 0.000015 * me.inertia; //spin + const index = Math.floor((me.cycle % (this.spawnRate * 6)) / this.spawnRate) //int from 0 to 5 + if (index === 0) me.mobType = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]; //fire a bullet from each vertex + me.spawnMobs(index) + // const vertex = me.vertices[index] + // const unit = Vector.normalise(Vector.sub(me.position, vertex)) + // const where = Vector.add(vertex, Vector.mult(unit, -30)) + // spawn[me.mobType](where.x + 50 * (Math.random() - 0.5), where.y + 50 * (Math.random() - 0.5)); + // const velocity = Vector.mult(Vector.perp(unit), -18) //give the mob a rotational velocity as if they were attached to a vertex + // Matter.Body.setVelocity(mob[mob.length - 1], { x: me.velocity.x + velocity.x, y: me.velocity.y + velocity.y }); + } + }, + enter() { }, + exit() { }, + }, + { + name: "hoppers", + spawnRate: Math.max(90, 480 - 16 * simulation.difficultyMode), + do() { + if (!(me.cycle % this.spawnRate) && mob.length < me.maxMobs) { + me.torque += 0.00002 * me.inertia; //spin + for (let i = 0; i < 6; i++) { + const vertex = me.vertices[i] + spawn.hopBullet(vertex.x + 50 * (Math.random() - 0.5), vertex.y + 50 * (Math.random() - 0.5), 13 + Math.ceil(Math.random() * 8)); //hopBullet(x, y, radius = 10 + Math.ceil(Math.random() * 8)) + Matter.Body.setDensity(mob[mob.length - 1], 0.002); //normal is 0.001 + const velocity = Vector.mult(Vector.perp(Vector.normalise(Vector.sub(me.position, vertex))), -18) //give the mob a rotational velocity as if they were attached to a vertex + Matter.Body.setVelocity(mob[mob.length - 1], { + x: me.velocity.x + velocity.x, + y: me.velocity.y + velocity.y + }); + } + let where = { x: 600 - Math.random() * 100, y: -225 } + if (simulation.isHorizontalFlipped) where.x = -600 + Math.random() * 100 + spawn.hopBullet(where.x, where.y, 13 + Math.ceil(Math.random() * 8)); //hopBullet(x, y, radius = 10 + Math.ceil(Math.random() * 8)) + Matter.Body.setDensity(mob[mob.length - 1], 0.002); //normal is 0.001 + } + }, + enter() { }, + exit() { }, + }, + { + name: "seekers", + spawnRate: Math.max(15, 100 - 3 * simulation.difficultyMode), + do() { + if (!(me.cycle % this.spawnRate) && mob.length < me.maxMobs) { //spawn seeker + const index = Math.floor((me.cycle % 360) / 60) + spawn.seeker(me.vertices[index].x, me.vertices[index].y, 18 * (0.5 + Math.random())); //seeker(x, y, radius = 8, sides = 6) + const who = mob[mob.length - 1] + Matter.Body.setDensity(who, 0.00003); //normal is 0.001 + who.timeLeft = 720 + 30 * simulation.difficulty //* (0.8 + 0.4 * Math.random()); + who.accelMag = 0.0004 * simulation.accelScale; //* (0.8 + 0.4 * Math.random()) + who.frictionAir = 0.01 //* (0.8 + 0.4 * Math.random()); + } + }, + enter() { }, + exit() { }, + }, + { + name: "mines", + bombCycle: 0, + bombInterval: Math.max(2, 10 - simulation.difficultyMode), + do() { + const yOff = 120 + this.bombCycle++ + if (!(this.bombCycle % this.bombInterval) && (this.bombCycle % 660) > 330) { //mines above player + if (simulation.isHorizontalFlipped) { + const x = m.pos.x + 200 * (Math.random() - 0.5) + if (x > -750) { //mines above player IN tunnel + spawn.mine(Math.min(Math.max(-730, x), 100), -450 - yOff * Math.random()) //player in main room + mob[mob.length - 1].fallHeight = -209 + } else { //mines above player NOT in tunnel + spawn.mine(Math.min(Math.max(-5375, x), -765), -1500 - yOff * Math.random()) //player in tunnel + mob[mob.length - 1].fallHeight = -9 + } + if (Math.random() < 0.5) { + spawn.mine(-5350 + 4550 * Math.random(), -1500 - yOff * Math.random()) //random mines + mob[mob.length - 1].fallHeight = -9 + } + } else { + const x = m.pos.x + 200 * (Math.random() - 0.5) + if (x < 750) { //mines above player IN tunnel + spawn.mine(Math.min(Math.max(-100, x), 735), -450 - yOff * Math.random()) //player in main room + mob[mob.length - 1].fallHeight = -209 + } else { //mines above player NOT in tunnel + spawn.mine(Math.min(Math.max(760, x), 5375), -1500 - yOff * Math.random()) //player in tunnel + mob[mob.length - 1].fallHeight = -9 + } + if (Math.random() < 0.5) { //random mines, but not in tunnel + spawn.mine(800 + 4550 * Math.random(), -1500 - yOff * Math.random()) //random mines + mob[mob.length - 1].fallHeight = -9 + } + } + } + for (let i = 0; i < mob.length; i++) { //mines fall + if (mob[i].isMine) { + if (mob[i].position.y < mob[i].fallHeight) { + mob[i].force.y += mob[i].mass * 0.03; + } else if (!mob[i].isOnGround) { + mob[i].isOnGround = true + Matter.Body.setPosition(mob[i], { + x: mob[i].position.x, + y: mob[i].fallHeight + }) + } + } + } + }, + enter() { + this.bombCycle = 0; + }, + exit() { + for (let i = 0; i < mob.length; i++) { + if (mob[i].isMine) mob[i].isExploding = true //explode the mines at the start of new round + } + }, + }, + { + name: "orbiters", + spawnRate: Math.ceil(Math.max(2, 5 - 0.2 * simulation.difficultyMode)), + orbitersCycle: 0, + do() { + this.orbitersCycle++ + if (!(this.orbitersCycle % this.spawnRate) && (this.orbitersCycle % 660) > 600 && mob.length < me.maxMobs) { + const speed = (0.01 + 0.0005 * simulation.difficultyMode) * ((Math.random() < 0.5) ? 0.85 : -1.15) + const phase = 0 //Math.floor(2 * Math.random()) * Math.PI + //find distance to play and set orbs at that range + const dist = me.distanceToPlayer() + //360 + 2150 * Math.random() + me.orbitalNoVelocity(me, dist + 900 * (Math.random() - 0.5), 0.1 * Math.random() + phase, speed) // orbital(who, radius, phase, speed) + } + }, + enter() { }, + exit() { }, + }, + { + name: "laser", + spinForce: 0.00000008, // * (Math.random() < 0.5 ? -1 : 1), + fadeCycle: 0, //fades in over 4 seconds + do() { + this.fadeCycle++ + if (this.fadeCycle > 0) { + me.torque += this.spinForce * me.inertia; //spin //0.00000015 + if (this.fadeCycle > 360) this.fadeCycle = -200 + simulation.difficultyMode * simulation.difficultyMode //turn laser off and reset + ctx.strokeStyle = "#50f"; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.lineWidth = 1.5; + ctx.beginPath(); + if (this.fadeCycle < 120) { //damage scales up over 2 seconds to give player time to move as it fades in + const scale = this.fadeCycle / 120 + const dmg = this.fadeCycle < 60 ? 0 : 0.1 * simulation.dmgScale * scale + me.lasers(me.vertices[0], me.angle + Math.PI / 6, dmg); + me.lasers(me.vertices[1], me.angle + 3 * Math.PI / 6, dmg); + me.lasers(me.vertices[2], me.angle + 5 * Math.PI / 6, dmg); + me.lasers(me.vertices[3], me.angle + 7 * Math.PI / 6, dmg); + me.lasers(me.vertices[4], me.angle + 9 * Math.PI / 6, dmg); + me.lasers(me.vertices[5], me.angle + 11 * Math.PI / 6, dmg); + ctx.strokeStyle = `rgba(85, 0, 255,${scale})`; + ctx.stroke(); + ctx.strokeStyle = `rgba(80, 0, 255,${0.07 * scale})` + } else if (this.fadeCycle > 0) { + me.lasers(me.vertices[0], me.angle + Math.PI / 6); + me.lasers(me.vertices[1], me.angle + 3 * Math.PI / 6); + me.lasers(me.vertices[2], me.angle + 5 * Math.PI / 6); + me.lasers(me.vertices[3], me.angle + 7 * Math.PI / 6); + me.lasers(me.vertices[4], me.angle + 9 * Math.PI / 6); + me.lasers(me.vertices[5], me.angle + 11 * Math.PI / 6); + ctx.strokeStyle = "#50f"; + ctx.stroke(); + ctx.strokeStyle = "rgba(80,0,255,0.07)"; + } + ctx.setLineDash([]); + ctx.lineWidth = 20; + ctx.stroke(); + } + }, + enter() { this.fadeCycle = 0 }, + exit() { }, + }, + { + name: "black hole", + eventHorizon: 0, + eventHorizonRadius: 1700, + eventHorizonCycle: 0, + do() { + this.eventHorizonCycle++ + this.eventHorizon = Math.max(0, this.eventHorizonRadius * Math.sin(this.eventHorizonCycle * 0.007)) //eventHorizon waves in and out + //draw darkness + ctx.beginPath(); + ctx.arc(me.position.x, me.position.y, this.eventHorizon * 0.2, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,20,40,0.3)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(me.position.x, me.position.y, this.eventHorizon * 0.4, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,20,40,0.25)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(me.position.x, me.position.y, this.eventHorizon * 0.6, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,20,40,0.2)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(me.position.x, me.position.y, this.eventHorizon * 0.8, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,20,40,0.15)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(me.position.x, me.position.y, this.eventHorizon, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.1)"; + ctx.fill(); + //when player is inside event horizon + if (Vector.magnitude(Vector.sub(me.position, player.position)) < this.eventHorizon) { + if (m.immuneCycle < m.cycle) { + if (m.energy > 0) m.energy -= 0.018 + if (m.energy < 0.05 && m.immuneCycle < m.cycle) m.damage(0.0003 * simulation.dmgScale); + } + const angle = Math.atan2(player.position.y - me.position.y, player.position.x - me.position.x); + player.force.x -= 0.0017 * Math.cos(angle) * player.mass * (m.onGround ? 1.7 : 1); + player.force.y -= 0.0017 * Math.sin(angle) * player.mass; + //draw line to player + ctx.beginPath(); + ctx.moveTo(me.position.x, me.position.y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineWidth = Math.min(60, me.radius * 2); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + ctx.stroke(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ctx.fill(); + } + me.curl(this.eventHorizon); + }, + enter() { this.eventHorizonCycle = 0 }, + exit() { }, + }, + { + name: "oscillation", + waveCycle: 0, + whereX: simulation.isHorizontalFlipped ? -3000 : 3000, + do() { + this.waveCycle += !me.isStunned + !me.isSlowed + // if (!me.isShielded && (!(this.waveCycle % 1800) || !(this.waveCycle % 1801))) spawn.shield(me, me.position.x, me.position.y, 1); + me.constraint.pointA = { + x: this.whereX + 600 * Math.sin(this.waveCycle * 0.005), + y: me.constraint.pointA.y + } + }, + enter() { + spawn.shield(me, me.position.x, me.position.y, 1); + }, + exit() { this.waveCycle = 0 }, + }, + { + name: "slow zone", + waveCycle: 0, + whereX: simulation.isHorizontalFlipped ? -3000 : 3000, + width: 1200, + // isActive: false, + cycle: 0, + cycleDuration: 150, + zone: 0, + isMovingRight: true, + playerSlowTime: 0, + do() { + // console.log(zone) + this.cycle++ + if (this.cycle % this.cycleDuration === 0) { //next zone + this.zone += this.isMovingRight ? 1 : -1 + if (this.zone > 0) this.isMovingRight = false + if (this.zone < -1) this.isMovingRight = true + this.whereX = (simulation.isHorizontalFlipped ? -3000 : 3000) + this.width * this.zone + } + //draw slow zone + if (this.cycle % this.cycleDuration > 0.45 * this.cycleDuration) { + ctx.fillStyle = `rgba(0, 100, 255, ${0.19 + 0.015 * Math.sin(simulation.cycle * 0.36)})`; + ctx.fillRect(this.whereX, -1500, this.width, 1500); + //check for player in range and apply slow debuff + if (player.position.x > this.whereX && player.position.x < this.whereX + this.width) { + this.playerSlowTime = 180 + //damage player + const dmg = 0.0001 * simulation.dmgScale + m.damage(dmg); + } + } else { //show where slow zone is about to show up + ctx.fillStyle = `rgba(0, 100, 255, ${0.2 + 0.25 * Math.random()})`; + ctx.fillRect(this.whereX, -1500, this.width, 12); + ctx.fillRect(this.whereX, -12, this.width, 12); + } + if (this.playerSlowTime > 0) { + this.playerSlowTime-- //warm up player when outside of slow zone + //slow player + // Matter.Body.setVelocity(player, Vector.mult(player.velocity, (1 - 0.01 * this.playerSlowTime))); + // Matter.Body.setVelocity(player, { x: (1 - 0.01 * this.playerSlowTime) * player.velocity.x, y: (1 - 0.0025 * this.playerSlowTime) * player.velocity.y }); //makes the player get stuck slow when walking horizontally + Matter.Body.setVelocity(player, { x: Math.max(0.05, 1 - 0.01 * Math.max(10, this.playerSlowTime)) * player.velocity.x, y: Math.max(0.2, 1 - 0.0025 * this.playerSlowTime) * player.velocity.y }); + //draw effect on player + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 45, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(0,100,255,${(0.003 * Math.max(10, this.playerSlowTime))})`; + ctx.fill(); + } + }, + enter() { + }, + exit() { }, + }, + { + name: "antigravity", + cycle: 0, + startCycle: 420, + totalCycles: 600, + rectX: simulation.isHorizontalFlipped ? -5400 : -150, //for positioning graphics + do() { + this.cycle++ + if (this.cycle > this.totalCycles) this.cycle = 0 + if (this.cycle === this.startCycle) { + //initial push up + for (let i = 0, len = body.length; i < len; ++i) { + body[i].force.y -= 0.05 * body[i].mass + } + for (let i = 0, len = powerUp.length; i < len; ++i) { + powerUp[i].force.y -= 0.07 * powerUp[i].mass + } + for (let i = 0, len = bullet.length; i < len; ++i) { + bullet[i].force.y -= 0.05 * bullet[i].mass + } + for (let i = 0, len = mob.length; i < len; ++i) { + mob[i].force.y -= 0.15 * mob[i].mass + } + player.force.y -= 0.04 * player.mass + } else if (this.cycle > this.startCycle) { //antigravity + for (let i = 0, len = body.length; i < len; ++i) { //push blocks away horizontally + body[i].force.y -= simulation.g * body[i].mass + Matter.Body.setVelocity(body[i], Vector.mult(body[i].velocity, 0.98)); //friction + } + for (let i = 0, len = powerUp.length; i < len; ++i) { + powerUp[i].force.y -= simulation.g * powerUp[i].mass + } + // for (let i = 0, len = bullet.length; i < len; ++i) { + // bullet[i].force.y -= simulation.g * bullet[i].mass + // Matter.Body.setVelocity(bullet[i], Vector.mult(bullet[i].velocity, 0.98)); //friction + // } + // for (let i = 0, len = mob.length; i < len; ++i) { + // mob[i].force.y -= 0.7 * simulation.g * mob[i].mass + // } + player.force.y -= simulation.g * player.mass //g = 0.0024 + Matter.Body.setVelocity(player, Vector.mult(player.velocity, 0.985)); //friction + //graphics + ctx.fillStyle = `rgba(0, 0, 0, ${0.03 + 0.03 * Math.random()})`; + ctx.fillRect(this.rectX, -1500, 5650, 1500); //cover everything + } else if (this.cycle > this.startCycle - 60) { + //graphical warning of antigravity + ctx.fillStyle = `rgba(0, 0, 0, ${0.2 + 0.25 * Math.random()})`; + ctx.fillRect(this.rectX, -25, 5650, 25); //cover floor + } + }, + enter() { spawn.shield(me, me.position.x, me.position.y, 1); }, + exit() { this.cycle = 0 }, + }, + // { + // name: "__", + // do() { }, + // enter() { }, + // exit() { }, + // }, + ] + shuffle(me.mode); //THIS SHOULD NOT BE COMMENTED OUT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + me.do = function () { + this.fill = `hsl(${360 * Math.sin(this.cycle * 0.011)},${80 + 20 * Math.sin(this.cycle * 0.004)}%,${60 + 20 * Math.sin(this.cycle * 0.009)}%)` + if (this.health < 1) { + this.cycle++; + this.checkStatus(); + this.invulnerable(); + this.spawnBoss(); + this.damageReductionDecay(); + for (let i = 0; i < this.totalModes; i++) this.mode[i].do() + } + // this.mode[10].do() //comment out this + // console.log(this.mode[9].name) + // this.cycle++; + // this.mode[4].do() + // this.mode[7].do() + }; + me.spawnRate = 5800 - 30 * simulation.difficultyMode * simulation.difficultyMode + me.spawnBoss = function () { //if the fight lasts too long start spawning bosses + if (!(me.cycle % this.spawnRate) && this.health < 1) { + this.spawnRate = Math.max(300, this.spawnRate - 10 * simulation.difficultyMode * simulation.difficultyMode) //reduce the timer each time a boss spawns + spawn.randomLevelBoss(3000 * (simulation.isHorizontalFlipped ? -1 : 1) + 2000 * (Math.random() - 0.5), -1100 + 200 * (Math.random() - 0.5)) + } + } + me.pushAway = function (magX = 0.13, magY = 0.05) { + for (let i = 0, len = body.length; i < len; ++i) { //push blocks away horizontally + body[i].force.x += magX * body[i].mass * (body[i].position.x > this.position.x ? 1 : -1) + body[i].force.y -= magY * body[i].mass + } + for (let i = 0, len = bullet.length; i < len; ++i) { //push blocks away horizontally + bullet[i].force.x += magX * bullet[i].mass * (bullet[i].position.x > this.position.x ? 1 : -1) + bullet[i].force.y -= magY * bullet[i].mass + } + for (let i = 0, len = powerUp.length; i < len; ++i) { //push blocks away horizontally + powerUp[i].force.x += magX * powerUp[i].mass * (powerUp[i].position.x > this.position.x ? 1 : -1) + powerUp[i].force.y -= magY * powerUp[i].mass + } + player.force.x += magX * player.mass * (player.position.x > this.position.x ? 1 : -1) + player.force.y -= magY * player.mass + } + me.boulder = function (x, y) { + mobs.spawn(x, y, 6, Math.floor(50 + 50 * Math.random()), this.fill); + let boss = this + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + this.timeLeft = 0 + }; + me.explodeRange = 500 + me.onDeath = function () { //explode + simulation.drawList.push({ //draw explosion + x: this.position.x, + y: this.position.y, + radius: this.explodeRange, + color: this.fill, + time: 8 + }); + let sub, knock + sub = Vector.sub(player.position, this.position); + if (Vector.magnitude(sub) < this.explodeRange) { //player knock back + m.damage(0.05); + knock = Vector.mult(Vector.normalise(sub), player.mass * 0.1); + player.force.x += knock.x; + player.force.y += knock.y; + } + for (let i = 0, len = powerUp.length; i < len; ++i) { //power up knock backs + sub = Vector.sub(powerUp[i].position, this.position); + if (Vector.magnitude(sub) < this.explodeRange) { + knock = Vector.mult(Vector.normalise(sub), powerUp[i].mass * 0.1); + powerUp[i].force.x += knock.x; + powerUp[i].force.y += knock.y; + } + } + for (let i = 0, len = body.length; i < len; ++i) { //block knock backs + sub = Vector.sub(body[i].position, this.position); + if (Vector.magnitude(sub) < this.explodeRange) { + knock = Vector.mult(Vector.normalise(sub), body[i].mass * 0.1); + body[i].force.x += knock.x; + body[i].force.y += knock.y; + } + } + } + Matter.Body.setDensity(me, 0.003); //normal is 0.001 + me.timeLeft = 300; + me.g = 0.0005; //required if using this.gravity + me.frictionAir = 0.005; + me.friction = 1; + me.frictionStatic = 1 + me.restitution = 0; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet; + me.spin = me.inertia * 0.000005 * (1 + Math.random()) * (m.pos.x > me.position.x ? 1 : -1) + Matter.Body.setAngularVelocity(me, 0.1 * (1 + 0.3 * Math.random()) * (m.pos.x > me.position.x ? 1 : -1)); + Matter.Body.setVelocity(me, { x: 0, y: 10 }); + me.do = function () { + this.fill = boss.fill + this.torque += this.spin; + this.gravity(); + this.timeLimit(); + if (this.timeLeft < 60) { + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.explodeRange, 0, 2 * Math.PI); + ctx.fillStyle = `rgba(255,255,255,0.15)`; + ctx.fill(); + } + }; + } + me.orbitalNoVelocity = function (who, radius, phase, speed) { //orbitals that don't include their host velocity //specifically for finalBoss + let boss = this + mobs.spawn(who.position.x, who.position.y, 6, 20, "rgb(255,0,150)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.001); //normal is 0.001 + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isUnstable = true; //dies when blocked + me.showHealthBar = false; + me.isOrbital = true; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet; //cat.player | cat.map | cat.body + me.do = function () { + this.fill = boss.fill + const time = simulation.cycle * speed + phase + const orbit = { x: Math.cos(time), y: Math.sin(time) } + Matter.Body.setPosition(this, Vector.add(who.position, Vector.mult(orbit, radius))) + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + const dmg = 0.13 * simulation.dmgScale + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + this.death(); + } + }; + } + me.lasers = function (where, angle, dmg = 0.1 * simulation.dmgScale) { + const seeRange = 7000; + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { + x: where.x + seeRange * Math.cos(angle), + y: where.y + seeRange * Math.sin(angle) + }; + best = vertexCollision(where, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + if (m.immuneCycle < m.cycle + 60 + m.collisionImmuneCycles) m.immuneCycle = m.cycle + 60 + m.collisionImmuneCycles; //player is immune to damage extra time + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + //draw beam + if (best.dist2 === Infinity) best = look; + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + } + me.onDeath = function () { + if (!this.hasRunDeathScript) { + this.hasRunDeathScript = true + //record win on this difficulty level to show up in the difficulty settings as a + if (!simulation.isCheating) { + localSettings.difficultyCompleted[simulation.difficultyMode] = true + localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + } + + //make a block body to replace this one + //this body is too big to leave behind in the normal way mobs.replace() + const len = body.length; + const v = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) //might help with vertex collision issue, not sure + body[len] = Matter.Bodies.fromVertices(this.position.x, this.position.y, v); + Matter.Body.setVelocity(body[len], { x: 0, y: -3 }); + Matter.Body.setAngularVelocity(body[len], this.angularVelocity); + body[len].collisionFilter.category = cat.body; + body[len].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet; + body[len].classType = "body"; + Composite.add(engine.world, body[len]); //add to world + const expand = function (that, massLimit) { + const scale = 1.05; + Matter.Body.scale(that, scale, scale); + if (that.mass < massLimit) setTimeout(expand, 20, that, massLimit); + }; + expand(body[len], 200) + + function unlockExit() { + if (simulation.isHorizontalFlipped) { + level.exit.x = -5500 - 100; + } else { + level.exit.x = 5500; + } + level.exit.y = -330; + Matter.Composite.remove(engine.world, map[map.length - 1]); + map.splice(map.length - 1, 1); + simulation.draw.setPaths(); //redraw map draw path + // level.levels.push("null") + } + + //add lore level as next level if player took lore tech earlier in the game + if (lore.techCount > (lore.techGoal - 1) && !simulation.isCheating) { + simulation.inGameConsole(`undefined = ${lore.techCount}/${lore.techGoal}`, 360); + setTimeout(function () { + simulation.inGameConsole(`level.levels.push("null")`, 720); + unlockExit() + level.levels.push("null") + }, 4000); + //remove block map element so exit is clear + } else { //reset game + let count = 0 + + function loop() { + if (!simulation.paused && !simulation.onTitlePage) { + count++ + if (count < 660) { + if (count === 1 && simulation.difficultyMode < 6) simulation.inGameConsole(`//enter testing mode to set level.levels.length to Infinite`); + if (!(count % 60)) simulation.inGameConsole(`simulation.analysis = ${((count / 60 - Math.random()) * 0.1).toFixed(3)}`); + } else if (count === 660) { + simulation.inGameConsole(`simulation.analysis = 1 //analysis complete`); + } else if (count === 780) { + simulation.inGameConsole(`undefined = ${lore.techCount}/${lore.techGoal}`) + } else if (count === 1020) { + simulation.inGameConsole(`Engine.clear(engine) //simulation successful`); + } else if (count === 1260) { + // tech.isImmortal = false; + // m.death() + // m.alive = false; + // simulation.paused = true; + // m.health = 0; + // m.displayHealth(); + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + document.getElementById("defense-bar").style.display = "none" + document.getElementById("damage-bar").style.display = "none" + document.getElementById("text-log").style.display = "none" + document.getElementById("fade-out").style.opacity = 1; //slowly fades out + // build.shareURL(false) + setTimeout(function () { + if (!simulation.onTitlePage) { + m.alive = false + simulation.paused = true; + // simulation.clearMap(); + // Matter.Composite.clear(composite, keepStatic, [deep = false]) + // Composite.clear(engine.composite); + engine.world.bodies.forEach((body) => { Matter.Composite.remove(engine.world, body) }) + Engine.clear(engine); + simulation.splashReturn(); + } + }, 6000); + return + } + } + if (simulation.testing || simulation.difficultyMode > 6) { + unlockExit() + setTimeout(function () { + simulation.inGameConsole(`level.levels.length = Infinite`); + }, 1500); + } else { + if (!simulation.onTitlePage) requestAnimationFrame(loop); + } + } + requestAnimationFrame(loop); + } + //remove power Ups, to avoid spamming console + function removeAll(array) { + for (let i = 0; i < array.length; ++i) Matter.Composite.remove(engine.world, array[i]); + } + removeAll(powerUp); + powerUp = []; + + //pull in particles + for (let i = 0, len = body.length; i < len; ++i) { + const velocity = Vector.mult(Vector.normalise(Vector.sub(this.position, body[i].position)), 65) + const pushUp = Vector.add(velocity, { x: 0, y: -0.5 }) + Matter.Body.setVelocity(body[i], Vector.add(body[i].velocity, pushUp)); + } + //damage all mobs + for (let j = 0; j < 8; j++) { //in case some mobs leave things after they die + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i] !== this) { + if (mob[i].isInvulnerable) { //disable invulnerability + mob[i].isInvulnerable = false + mob[i].damageReduction = 1 + } + mob[i].damage(Infinity, true); + } + } + } + + //draw stuff + for (let i = 0, len = 22; i < len; i++) { + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: (i + 1) * 150, + color: `rgba(255,255,255,0.17)`, + time: 5 * (len - i + 1) + }); + } + } + }; + }, + zombie(x, y, radius, sides, color) { //mob that attacks other mobs + mobs.spawn(x, y, sides, radius, color); + let me = mob[mob.length - 1]; + me.damageReduction = 0 //take NO damage, but also slowly lose health + Matter.Body.setDensity(me, 0.0001) // normal density is 0.001 // this reduces life by half and decreases knockback + me.isZombie = true + me.isBadTarget = true; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.stroke = "#83a" + me.accelMag = 0.003 + me.frictionAir = 0.005 + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.mob + me.seeAtDistance2 = 1000000 //1000 vision range + // me.onDeath = function() { + // const amount = Math.min(10, Math.ceil(this.mass * 0.5)) + // if (tech.isSporeFlea) { + // const len = amount / 2 + // for (let i = 0; i < len; i++) { + // const speed = 10 + 5 * Math.random() + // const angle = 2 * Math.PI * Math.random() + // b.flea(this.position, { x: speed * Math.cos(angle), y: speed * Math.sin(angle) }) + // } + // } else if (tech.isSporeWorm) { + // const len = amount / 2 + // for (let i = 0; i < len; i++) b.worm(this.position) + // } else { + // for (let i = 0; i < amount; i++) b.spore(this.position) + // } + // } + me.do = function () { + this.checkStatus(); + this.zombieHealthBar(); + this.lookForMobTargets(); + this.attack(); + }; + me.mobSearchIndex = 0; + me.target = null + me.lookForMobTargets = function () { + if (this.target === null && mob.length > 1 && !(simulation.cycle % this.seePlayerFreq)) { //find mob targets + let closeDist = Infinity; + for (let i = 0, len = mob.length; i < len; ++i) { + if ( + !mob[i].isZombie && + !mob[i].isUnblockable && + !mob[i].isMobBullet && + Matter.Query.ray(map, this.position, mob[i].position).length === 0 && + Matter.Query.ray(body, this.position, mob[i].position).length === 0 + // !mob[i].isBadTarget && + // !mob[i].isInvulnerable && + // (Vector.magnitudeSquared(Vector.sub(this.position, mob[this.mobSearchIndex].position)) < this.seeAtDistance2) + ) { + const DIST = Vector.magnitude(Vector.sub(this.position, mob[i].position)); + if (DIST < closeDist) { + closeDist = DIST; + this.target = mob[i] + } + } + } + } else if ( + !(simulation.cycle % this.memory) && + this.target && + (!this.target.alive || Matter.Query.ray(map, this.position, this.target.position).length !== 0) + ) { + this.target = null //chance to forget target + } + } + me.zombieHealthBar = function () { + this.health -= 0.0003 //decay + if ((this.health < 0.01 || isNaN(this.health)) && this.alive) this.death(); + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(136, 51, 170,0.7)"; + ctx.fillRect(x, y, w * this.health, h); + } + me.hitCD = 0 + me.attack = function () { //hit non zombie mobs + if (this.hitCD < simulation.cycle && !this.isStunned && !this.isSlowed) { + if (this.target) { + this.force = Vector.mult(Vector.normalise(Vector.sub(this.target.position, this.position)), this.accelMag * this.mass) + } else { //wonder around + this.torque += 0.0000003 * this.inertia; + const mag = 0.0003 * this.mass + this.force.x += mag * Math.cos(this.angle) + this.force.y += mag * Math.sin(this.angle) + } + if (this.speed > 15) { // speed cap instead of friction to give more agility + Matter.Body.setVelocity(this, { x: this.velocity.x * 0.96, y: this.velocity.y * 0.96 }); + } else if (this.speed < 10) { + Matter.Body.setVelocity(this, { x: this.velocity.x * 0.98, y: this.velocity.y * 0.98 }); + } else if (this.speed < 8) { + Matter.Body.setVelocity(this, { x: this.velocity.x * 0.99, y: this.velocity.y * 0.99 }); + } + const hit = (who) => { + if (!who.isZombie && who.damageReduction) { + this.hitCD = simulation.cycle + 15 + //knock back away from recently hit mob + const force = Vector.mult(Vector.normalise(Vector.sub(who.position, this.position)), 0.03 * this.mass) + this.force.x -= force.x; + this.force.y -= force.y; + this.target = null //look for a new target + + // who.damage(dmg); + //by pass normal damage method + const dmg = 1.5 * who.damageReduction / Math.sqrt(who.mass) + who.health -= dmg + who.onDamage(dmg); //custom damage effects + who.locatePlayer(); + if ((who.health < 0.01 || isNaN(who.health)) && who.alive) who.death(); + + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: Math.log(dmg + 1.1) * 40 * who.damageReduction + 3, + color: simulation.playerDmgColor, + time: simulation.drawTime + }); + } + } + const collide = Matter.Query.collides(this, mob) //damage mob targets if nearby + if (collide.length > 1) { //don't count self collide + for (let i = 0, len = collide.length; i < len; i++) { + hit(collide[i].bodyA) + hit(collide[i].bodyB) + } + } + } + } + }, + starter(x, y, radius = Math.floor(15 + 20 * Math.random())) { //easy mob for on level 1 + mobs.spawn(x, y, 8, radius, "#9ccdc6"); + let me = mob[mob.length - 1]; + // console.log(`mass=${me.mass}, radius = ${radius}`) + me.accelMag = 0.0002 + me.repulsionRange = 400000 + radius * radius; //squared + // me.memory = 120; + me.seeAtDistance2 = 2000000 //1400 vision range + Matter.Body.setDensity(me, 0.0005) // normal density is 0.001 // this reduces life by half and decreases knockback + me.do = function () { + this.seePlayerByLookingAt(); + this.attraction(); + this.repulsion(); + this.checkStatus(); + }; + }, + blockGroup(x, y, num = 3 + Math.random() * 8) { + for (let i = 0; i < num; i++) { + const radius = 25 + Math.floor(Math.random() * 20) + spawn.blockGroupMob(x + Math.random() * radius, y + Math.random() * radius, radius); + } + }, + blockGroupMob(x, y, radius = 25 + Math.floor(Math.random() * 20)) { + mobs.spawn(x, y, 4, radius, "#999"); + let me = mob[mob.length - 1]; + me.g = 0.00015; //required if using this.gravity + me.accelMag = 0.0008 * simulation.accelScale; + me.groupingRangeMax = 250000 + Math.random() * 100000; + me.groupingRangeMin = (radius * 8) * (radius * 8); + me.groupingStrength = 0.0005 + me.memory = 200; + me.isGrouper = true; + me.seeAtDistance2 = 600 * 600 + me.seePlayerFreq = Math.floor(50 + 50 * Math.random()) + me.do = function () { + this.gravity(); + this.checkStatus(); + this.seePlayerCheck(); + if (this.seePlayer.recall) { + this.attraction(); + //tether to other blocks + ctx.beginPath(); + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isGrouper && mob[i] != this && mob[i].isDropPowerUp) { //don't tether to self, bullets, shields, ... + const distance2 = Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)) + if (distance2 < this.groupingRangeMax) { + if (!mob[i].seePlayer.recall) mob[i].seePlayerCheck(); //wake up sleepy mobs + if (distance2 > this.groupingRangeMin) { + const angle = Math.atan2(mob[i].position.y - this.position.y, mob[i].position.x - this.position.x); + const forceMag = this.groupingStrength * mob[i].mass; + mob[i].force.x -= forceMag * Math.cos(angle); + mob[i].force.y -= forceMag * Math.sin(angle); + } + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(mob[i].position.x, mob[i].position.y); + } + } + } + ctx.strokeStyle = "#0ff"; + ctx.lineWidth = 1; + ctx.stroke(); + } + } + }, + blockBoss(x, y, radius = 60) { + const activeBeams = []; // used to draw beams when converting + const beamTotalDuration = 60 + mobs.spawn(x, y, 4, radius, "#999"); //#54291d + const me = mob[mob.length - 1]; + me.isBoss = true; + Matter.Body.setDensity(me, 0.002); //normal density even though its a boss + me.damageReduction = 0.04 + me.frictionAir = 0.01; + me.accelMag = 0.0002; + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y); + for (const who of mob) { + if (who.isNecroMob) { //blockMobs leave their body, and die + who.leaveBody = true + who.damage(Infinity) + } + } + } + me.target = player; // the target to lock on. Usually a block, but will be the player under certain conditions + me.do = function () { + this.checkStatus(); + this.seePlayerCheck(); + if (this.target) { //(this.target === player && this.seePlayer.yes) || this.target !== player + const force = Vector.mult(Vector.normalise(Vector.sub(this.target.position, this.position)), this.accelMag * this.mass) + this.force.x += force.x; + this.force.y += force.y; + } + + if (!(simulation.cycle % 30)) { + //find blocks to turn into mobs + for (let i = 0; i < body.length; i++) { + if (Vector.magnitude(Vector.sub(this.position, body[i].position)) < 700 && !body[i].isNotHoldable) { // check distance for each block + Matter.Composite.remove(engine.world, body[i]); + this.target = null //player; + spawn.blockMob(body[i].position.x, body[i].position.y, body[i], 0); + body.splice(i, 1); + activeBeams.push([beamTotalDuration, mob[mob.length - 1]]); + } + } + + // generally, the boss will tend to stay in the player's area but focus on blocks. + if (this.distanceToPlayer() > 1500 && this.target === null) { + this.target = player; // too far, attract to the player + } else { + if (body.length) { // look for a new target by finding the closest block + let min = Infinity; + let closestBlock = null; + for (const block of body) { + const dist = Vector.magnitudeSquared(Vector.sub(this.position, block.position)) + if (dist < min && Matter.Query.ray(map, this.position, block.position).length === 0) { + min = dist; + closestBlock = block; + } + } + this.target = closestBlock; + } + } + + //randomly spawn new mobs from nothing + if (!(simulation.cycle % 90)) { + let count = 0 + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isNecroMob) count++ + } + if (count < 20 * Math.random() * Math.random()) { //limit number of spawns if there are already too many blockMobs + const unit = Vector.normalise(Vector.sub(player.position, this.position)) + for (let i = 0, len = 3 * Math.random(); i < len; i++) { + this.damageReduction += 0.001; //0.05 is starting value + const scale = 0.99; //if 120 use 1.02 + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + + const where = Vector.add(Vector.mult(unit, radius + 200 * Math.random()), this.position) + spawn.blockMob(where.x + 100 * (Math.random() - 0.5), where.y + 100 * (Math.random() - 0.5), null); + this.torque += 0.000035 * this.inertia; //spin after spawning + activeBeams.push([beamTotalDuration, mob[mob.length - 1]]); + } + } + } + + } + for (let i = 0; i < activeBeams.length; i++) { // draw beams on new mobs + const [duration, newBlockMob] = activeBeams[i]; + if (duration === 0) { + activeBeams.splice(i, 1); + continue; + } + if (newBlockMob.alive) { + const vertexIndex = Math.floor((newBlockMob.vertices.length - 1) * duration / beamTotalDuration) + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(newBlockMob.vertices[vertexIndex].x, newBlockMob.vertices[vertexIndex].y); + + //outline mob + ctx.moveTo(newBlockMob.vertices[0].x, newBlockMob.vertices[0].y); + for (let j = 1; j < newBlockMob.vertices.length; j++) { + ctx.lineTo(newBlockMob.vertices[j].x, newBlockMob.vertices[j].y); + } + ctx.lineTo(newBlockMob.vertices[0].x, newBlockMob.vertices[0].y); + + ctx.strokeStyle = "#0ff"; + ctx.lineWidth = 3; + ctx.stroke(); + } + activeBeams[i][0]--; // shorten duration + } + } + }, + blockMob(x, y, host, growCycles = 60) { + if (host === null) { + mobs.spawn(x, y, 4, 1.25 + 3.5 * Math.random(), "#999"); + } else { + const sideLength = Vector.magnitude(Vector.sub(host.vertices[0], host.vertices[1])) + Vector.magnitude(Vector.sub(host.vertices[1], host.vertices[2])) / 2 //average of first 2 sides + mobs.spawn(x, y, 4, Math.min(70, sideLength), "#999"); + if (host.bounds.max.x - host.bounds.min.x < 150 && host.bounds.max.y - host.bounds.min.y < 150) { + Matter.Body.setVertices(mob[mob.length - 1], host.vertices) //if not too big match vertices of host exactly + // mob[mob.length - 1].radius = + } + } + const me = mob[mob.length - 1]; + me.damageReduction = 0.5; //only until done growing + me.isNecroMob = true + me.g = 0.00012; //required if using this.gravity + me.accelMag = 0.0003 * Math.sqrt(simulation.accelScale); + me.memory = 120; + me.leaveBody = false; + me.isDropPowerUp = false; + // me.showHealthBar = false; + me.cycle = 0 + me.do = function () { //grow phase only occurs for growCycles + this.checkStatus(); + this.seePlayerCheck(); + this.cycle++ + if (this.cycle > growCycles) { + this.damageReduction = 1.8 //take extra damage + this.do = this.normalDo + } else { + const scale = 1.04; //if 120 use 1.02 + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + } + } + me.normalDo = function () { + this.gravity(); + this.checkStatus(); + this.seePlayerCheck(); + this.attraction(); + } + }, + cellBossCulture(x, y, radius = 20, num = 5) { + const cellID = Math.random() + for (let i = 0; i < num; i++) { + spawn.cellBoss(x, y, radius, cellID) + } + }, + cellBoss(x, y, radius = 20, cellID) { + mobs.spawn(x + Math.random(), y + Math.random(), 20, radius * (1 + 1.2 * Math.random()), "rgba(0,80,125,0.3)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent" + me.isBoss = true; + me.isCell = true; + me.cellID = cellID + me.accelMag = 0.000165 * simulation.accelScale; + me.memory = Infinity; + me.leaveBody = false; + me.isVerticesChange = true + me.frictionAir = 0.012 + me.seePlayerFreq = Math.floor(11 + 7 * Math.random()) + me.seeAtDistance2 = 1400000; + me.cellMassMax = 70 + me.collisionFilter.mask = cat.player | cat.bullet | cat.body// | cat.map + Matter.Body.setDensity(me, 0.00012 + 0.000008 * simulation.difficulty) // normal density is 0.001 + me.damageReduction = 0.17 + + const k = 642 //k=r^2/m + me.split = function () { + const scale = 0.45 + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + spawn.cellBoss(this.position.x, this.position.y, this.radius, this.cellID); + mob[mob.length - 1].health = this.health + } + me.onHit = function () { //run this function on hitting player + this.health = 1; + this.split(); + }; + me.onDamage = function (dmg) { + if (Math.random() < 0.34 * dmg * Math.sqrt(this.mass) && this.health > dmg) this.split(); + } + me.do = function () { + this.seePlayerByDistOrLOS(); + this.checkStatus(); + this.attraction(); + + if (this.seePlayer.recall && this.mass < this.cellMassMax) { //grow cell radius + const scale = 1 + 0.0002 * this.cellMassMax / this.mass; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + } + if (!(simulation.cycle % this.seePlayerFreq)) { //move away from other mobs + const repelRange = 150 + const attractRange = 700 + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isCell && mob[i].id !== this.id) { + const sub = Vector.sub(this.position, mob[i].position) + const dist = Vector.magnitude(sub) + if (dist < repelRange) { + this.force = Vector.mult(Vector.normalise(sub), this.mass * 0.002) + } else if (dist > attractRange) { + this.force = Vector.mult(Vector.normalise(sub), -this.mass * 0.003) + } + } + } + } + }; + me.onDeath = function () { + this.isCell = false; + let count = 0 //count other cells by id + // console.log(this.cellID) + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isCell && mob[i].cellID === this.cellID) count++ + } + if (count < 1) { //only drop a power up if this is the last cell + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + } else { + this.isDropPowerUp = false; + } + } + }, + spawnerBossCulture(x, y, radius = 50, num = 8 + Math.min(20, simulation.difficulty * 0.4)) { + tech.deathSpawnsFromBoss += 0.4 + const spawnID = Math.random() + for (let i = 0; i < num; i++) spawn.spawnerBoss(x, y, radius, spawnID) + }, + spawnerBoss(x, y, radius, spawnID) { + mobs.spawn(x + Math.random(), y + Math.random(), 4, radius, "rgba(255,60,0,0.3)") //); + let me = mob[mob.length - 1]; + me.isBoss = true; + + me.isSpawnBoss = true; + me.spawnID = spawnID + me.accelMag = 0.00022 * simulation.accelScale; + me.memory = Infinity; + me.showHealthBar = false; + me.isVerticesChange = true + me.frictionAir = 0.011 + me.seePlayerFreq = Math.floor(14 + 7 * Math.random()) + me.seeAtDistance2 = 200000 //1400000; + me.stroke = "transparent" + me.collisionFilter.mask = cat.player | cat.bullet | cat.body | cat.map //"rgba(255,60,0,0.3)" + // Matter.Body.setDensity(me, 0.0014) // normal density is 0.001 + Matter.Body.setAngularVelocity(me, 0.12 * (Math.random() - 0.5)) + // spawn.shield(me, x, y, 1); + + me.onHit = function () { //run this function on hitting player + this.explode(); + }; + me.damageReduction = 0.14 + me.doAwake = function () { + this.alwaysSeePlayer(); + this.checkStatus(); + this.attraction(); + + if (!(simulation.cycle % this.seePlayerFreq)) { //move away from other mobs + const repelRange = 40 + const attractRange = 240 + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isSpawnBoss && mob[i].id !== this.id) { + const sub = Vector.sub(this.position, mob[i].position) + const dist = Vector.magnitude(sub) + if (dist < repelRange) { + this.force = Vector.mult(Vector.normalise(sub), this.mass * 0.002) + } else if (dist > attractRange) { + this.force = Vector.mult(Vector.normalise(sub), -this.mass * 0.002) + } + } + } + } + } + me.do = function () { + this.checkStatus(); + if (this.seePlayer.recall) { + this.do = this.doAwake + //awaken other spawnBosses + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isSpawnBoss && mob[i].spawnID === this.spawnID) mob[i].seePlayer.recall = 1 + } + } + }; + me.onDeath = function () { + this.isSpawnBoss = false; + let count = 0 //count other cells by id + // console.log(this.spawnID) + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isSpawnBoss && mob[i].spawnID === this.spawnID) count++ + } + if (count < 1) { //only drop a power up if this is the last cell + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + tech.deathSpawnsFromBoss -= 0.4 + } else { + this.leaveBody = false; + this.isDropPowerUp = false; + } + + const spawns = tech.deathSpawns + tech.deathSpawnsFromBoss + const len = Math.min(12, spawns * Math.ceil(Math.random() * simulation.difficulty * spawns)) + for (let i = 0; i < len; i++) { + spawn.spawns(this.position.x + (Math.random() - 0.5) * radius * 2.5, this.position.y + (Math.random() - 0.5) * radius * 2.5); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + (Math.random() - 0.5) * 10, + y: this.velocity.x + (Math.random() - 0.5) * 10 + }); + } + + } + }, + growBossCulture(x, y, radius = 17, nodes = 12 + Math.min(10, simulation.difficulty * 0.25)) { + const buffID = Math.random() + const sideLength = 200 + 50 * Math.sqrt(nodes) // distance between each node mob + for (let i = 0; i < nodes; ++i) { + const angle = 2 * Math.PI * Math.random() + const mag = Math.max(radius, sideLength * (1 - Math.pow(Math.random(), 1.5))) //working on a distribution that is circular, random, but not too focused in the center + spawn.growBoss(x + mag * Math.cos(angle), y + mag * Math.sin(angle), radius, buffID); + } + spawn.constrain2AdjacentMobs(nodes, 0.0001, false); //loop mobs together + }, + growBoss(x, y, radius, buffID) { + mobs.spawn(x + Math.random(), y + Math.random(), 6, radius, "hsl(144, 15%, 50%)") //); + let me = mob[mob.length - 1]; + me.isBoss = true; + me.isBuffBoss = true; + me.buffID = buffID + me.memory = Infinity; + me.isVerticesChange = true + me.frictionAir = 0.012 + me.seePlayerFreq = Math.floor(11 + 7 * Math.random()) + me.seeAtDistance2 = 200000 //1400000; + me.stroke = "transparent" + me.collisionFilter.mask = cat.player | cat.bullet //| cat.body //| cat.map //"rgba(255,60,0,0.3)" + + me.buffCount = 0 + me.accelMag = 0.00005 //* simulation.accelScale; + me.setBuffed = function () { + this.buffCount++ + this.accelMag += 0.000024 //* Math.sqrt(simulation.accelScale) + this.fill = `hsl(144, ${5 + 10 * this.buffCount}%, 50%)` + const scale = 1.135; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + + // this.isInvulnerable = true + // if (this.damageReduction) this.startingDamageReduction = this.damageReduction + // this.damageReduction = 0 + // this.invulnerabilityCountDown = simulation.difficulty + } + me.onDeath = function () { + this.isBuffBoss = false; + let count = 0 //count other cells by id + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isBuffBoss && mob[i].buffID === this.buffID) { + count++ + mob[i].setBuffed() + } + } + if (count < 1) { //only drop a power up if this is the last cell + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + } else { + this.leaveBody = false; + this.isDropPowerUp = false; + powerUps.spawnRandomPowerUp(this.position.x, this.position.y) // manual power up spawn to avoid spawning too many tech with "symbiosis" + } + } + me.damageReduction = 0.2 + //required setup for invulnerable + // me.isInvulnerable = false + me.invulnerabilityCountDown = 0 + me.do = function () { + // if (this.isInvulnerable) { + // if (this.invulnerabilityCountDown > 0) { + // this.invulnerabilityCountDown-- + // ctx.beginPath(); + // let vertices = this.vertices; + // ctx.moveTo(vertices[0].x, vertices[0].y); + // for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + // ctx.lineTo(vertices[0].x, vertices[0].y); + // ctx.lineWidth = 20; + // ctx.strokeStyle = "rgba(255,255,255,0.7)"; + // ctx.stroke(); + // } else { + // this.isInvulnerable = false + // this.damageReduction = this.startingDamageReduction + // } + // } + this.alwaysSeePlayer(); + this.checkStatus(); + this.attraction(); + // if (!(simulation.cycle % this.seePlayerFreq)) { //move away from other mobs + // const repelRange = 100 + 4 * this.radius + // const attractRange = 240 + // for (let i = 0, len = mob.length; i < len; i++) { + // if (mob[i].isBuffBoss && mob[i].id !== this.id) { + // const sub = Vector.sub(this.position, mob[i].position) + // const dist = Vector.magnitude(sub) + // if (dist < repelRange) { + // this.force = Vector.mult(Vector.normalise(sub), this.mass * 0.002) + // } else if (dist > attractRange) { + // this.force = Vector.mult(Vector.normalise(sub), -this.mass * 0.002) + // } + // } + // } + // } + } + }, + powerUpBossBaby(x, y, vertices = 9, radius = 60) { + mobs.spawn(x, y, vertices, radius, "rgba(225,240,245,0.4)"); //"rgba(120,140,150,0.4)" + let me = mob[mob.length - 1]; + me.isBoss = true; + me.frictionAir = 0.006 + me.seeAtDistance2 = 1000000; + me.accelMag = 0.0004 + 0.0003 * simulation.accelScale; + // Matter.Body.setDensity(me, 0.001); //normal is 0.001 + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map + me.memory = Infinity; + me.seePlayerFreq = 17 + me.lockedOn = null; + if (vertices === 9) { + //on primary spawn + powerUps.spawnBossPowerUp(me.position.x, me.position.y) + powerUps.spawn(me.position.x, me.position.y, "heal"); + powerUps.spawn(me.position.x, me.position.y, "ammo"); + powerUps.spawn(me.position.x, me.position.y, "ammo"); + } else if (!m.isCloak) { + me.foundPlayer(); + } + me.damageReduction = 0.21 + me.isInvulnerable = true + me.startingDamageReduction = me.damageReduction + me.damageReduction = 0 + me.invulnerabilityCountDown = 30 + simulation.difficulty + me.onHit = function () { //run this function on hitting player + if (powerUps.ejectTech()) { + powerUps.ejectGraphic("150, 138, 255"); + // powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "ammo"); + // powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "research"); + this.accelMag *= 1.4 + Matter.Body.setDensity(this, this.density * 1.4); //normal is 0.001 + } + }; + me.onDeath = function () { + this.leaveBody = false; + if (vertices > 3) { + this.isDropPowerUp = false; + spawn.powerUpBossBaby(this.position.x, this.position.y, vertices - 1) + Matter.Body.setVelocity(mob[mob.length - 1], { x: this.velocity.x, y: this.velocity.y }) + } + for (let i = 0; i < powerUp.length; i++) powerUp[i].collisionFilter.mask = cat.map | cat.powerUp + }; + me.do = function () { + if (this.isInvulnerable) { + if (this.invulnerabilityCountDown > 0) { + this.invulnerabilityCountDown-- + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } else { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + } + } + // this.stroke = `hsl(0,0%,${80 + 25 * Math.sin(simulation.cycle * 0.01)}%)` + // this.fill = `hsla(0,0%,${80 + 25 * Math.sin(simulation.cycle * 0.01)}%,0.3)` + + //steal all power ups + if (this.alive) { + for (let i = 0; i < Math.min(powerUp.length, this.vertices.length); i++) { + powerUp[i].collisionFilter.mask = 0 + Matter.Body.setPosition(powerUp[i], this.vertices[i]) + Matter.Body.setVelocity(powerUp[i], { x: 0, y: 0 }) + } + } + this.seePlayerByHistory(50); + this.attraction(); + this.checkStatus(); + }; + }, + powerUpBoss(x, y, vertices = 9, radius = 130) { + mobs.spawn(x, y, vertices, radius, "transparent"); + let me = mob[mob.length - 1]; + me.isBoss = true; + me.frictionAir = 0.01 + me.seeAtDistance2 = 1000000; + me.accelMag = 0.0002 + 0.0004 * simulation.accelScale; + Matter.Body.setDensity(me, 0.0003); //normal is 0.001 + me.collisionFilter.mask = cat.bullet | cat.player | cat.body + me.memory = Infinity; + me.seePlayerFreq = 30 + me.lockedOn = null; + if (vertices === 9) { + //on primary spawn + powerUps.spawnBossPowerUp(me.position.x, me.position.y) + powerUps.spawn(me.position.x, me.position.y, "heal"); + powerUps.spawn(me.position.x, me.position.y, "ammo"); + powerUps.spawn(me.position.x, me.position.y, "ammo"); + } else if (!m.isCloak) { + me.foundPlayer(); + } + + me.damageReduction = 0.23 + me.isInvulnerable = true + me.startingDamageReduction = me.damageReduction + me.damageReduction = 0 + me.invulnerabilityCountDown = 30 + simulation.difficulty + + me.onHit = function () { //run this function on hitting player + if (powerUps.ejectTech()) { + powerUps.ejectGraphic("150, 138, 255"); + // powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "ammo"); + // powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "research"); + this.accelMag *= 1.4 + Matter.Body.setDensity(this, this.density * 1.4); //normal is 0.001 + } + }; + me.onDeath = function () { + this.leaveBody = false; + if (vertices > 3) { + this.isDropPowerUp = false; + spawn.powerUpBoss(this.position.x, this.position.y, vertices - 1) + Matter.Body.setVelocity(mob[mob.length - 1], { x: this.velocity.x, y: this.velocity.y }) + } + for (let i = 0; i < powerUp.length; i++) powerUp[i].collisionFilter.mask = cat.map | cat.powerUp + for (let i = 0; i < 40; i++) this.colors(); + }; + me.colors = function () { + const unit = Vector.rotate({ x: 1, y: 0 }, Math.random() * 6.28) + const where = Vector.add(this.position, Vector.mult(unit, 700 - 500 * Math.random() * Math.random())) + const colors = ["#0ae", "#f55", "#f7b", "#0eb", "#467", "hsl(246,100%,77%)", "#0cf", "#26a"] + simulation.drawList.push({ //add dmg to draw queue + x: where.x, + y: where.y, + radius: 5 + 10 * Math.random(), + color: colors[Math.floor(Math.random() * colors.length)], //#0cf + time: 17//4 + Math.floor(15 * Math.random()) + }); + } + me.do = function () { + this.stroke = `hsl(0,0%,${80 + 25 * Math.sin(simulation.cycle * 0.01)}%)` + if (this.isInvulnerable) { + if (this.invulnerabilityCountDown > 0) { + this.invulnerabilityCountDown-- + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } else { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + } + } + if (this.alive) { + for (let i = 0; i < Math.min(powerUp.length, this.vertices.length); i++) { + powerUp[i].collisionFilter.mask = 0 + Matter.Body.setPosition(powerUp[i], this.vertices[i]) + Matter.Body.setVelocity(powerUp[i], { x: 0, y: 0 }) + } + } + + this.seePlayerCheckByDistance(); + this.attraction(); + this.checkStatus(); + + //aura around boss so it can bee seen more easily even when inside walls + if (!(simulation.cycle % 5)) this.colors(); + }; + }, + + // chaser(x, y, radius = 35 + Math.ceil(Math.random() * 40)) { + // mobs.spawn(x, y, 8, radius, "rgb(255,150,100)"); //"#2c9790" + // let me = mob[mob.length - 1]; + // // Matter.Body.setDensity(me, 0.0007); //extra dense //normal is 0.001 //makes effective life much lower + // me.friction = 0.1; + // me.frictionAir = 0; + // me.accelMag = 0.001 * Math.sqrt(simulation.accelScale); + // me.g = me.accelMag * 0.6; //required if using this.gravity + // me.memory = 180; + // spawn.shield(me, x, y); + // me.do = function() { + // this.gravity(); + // this.seePlayerByHistory(15); + // this.checkStatus(); + // this.attraction(); + // }; + // }, + grower(x, y, radius = 15) { + mobs.spawn(x, y, 7, radius, "hsl(144, 15%, 50%)"); + let me = mob[mob.length - 1]; + me.isVerticesChange = true + me.big = false; //required for grow + me.accelMag = 0.00045 * simulation.accelScale; + me.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.player //can't touch other mobs + // me.onDeath = function () { //helps collisions functions work better after vertex have been changed + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) + // } + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + this.grow(); + }; + }, + springer(x, y, radius = 20 + Math.ceil(Math.random() * 35)) { + mobs.spawn(x, y, 10, radius, "#b386e8"); + let me = mob[mob.length - 1]; + me.friction = 0; + me.frictionAir = 0.006; + me.lookTorque = 0.0000008; //controls spin while looking for player + me.g = 0.0002; //required if using this.gravity + me.seePlayerFreq = Math.floor((40 + 25 * Math.random())); + const springStiffness = 0.00014; + const springDampening = 0.0005; + + me.springTarget = { x: me.position.x, y: me.position.y }; + const len = cons.length; + cons[len] = Constraint.create({ + pointA: me.springTarget, + bodyB: me, + stiffness: springStiffness, + damping: springDampening + }); + Composite.add(engine.world, cons[cons.length - 1]); + + cons[len].length = 100 + 1.5 * radius; + me.cons = cons[len]; + + me.springTarget2 = { x: me.position.x, y: me.position.y }; + const len2 = cons.length; + cons[len2] = Constraint.create({ + pointA: me.springTarget2, + bodyB: me, + stiffness: springStiffness, + damping: springDampening + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len2].length = 100 + 1.5 * radius; + me.cons2 = cons[len2]; + me.do = function () { + this.gravity(); + this.searchSpring(); + this.checkStatus(); + this.springAttack(); + }; + me.onDeath = function () { + this.removeCons(); + }; + spawn.shield(me, x, y); + }, + hopper(x, y, radius = 35 + Math.ceil(Math.random() * 30)) { + mobs.spawn(x, y, 5, radius, "rgb(0,200,180)"); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 0.0015); //normal is 0.001 + me.accelMag = 0.05; + me.g = 0.0032; //required if using this.gravity + me.frictionAir = 0.01; + me.friction = 1 + me.frictionStatic = 1 + me.restitution = 0; + me.delay = 120 * simulation.CDScale; + me.randomHopFrequency = 200 + Math.floor(Math.random() * 150); + me.randomHopCD = simulation.cycle + me.randomHopFrequency; + Matter.Body.rotate(me, Math.random() * Math.PI); + spawn.shield(me, x, y); + me.do = function () { + this.gravity(); + this.seePlayerCheck(); + this.checkStatus(); + if (this.seePlayer.recall) { + if (this.cd < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + this.cd = simulation.cycle + this.delay; + const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x += forceMag * Math.cos(angle); + this.force.y += forceMag * Math.sin(angle) - (Math.random() * 0.06 + 0.1) * this.mass; //antigravity + } + } else { + //randomly hob if not aware of player + if (this.randomHopCD < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + this.randomHopCD = simulation.cycle + this.randomHopFrequency; + //slowly change randomHopFrequency after each hop + this.randomHopFrequency = Math.max(100, this.randomHopFrequency + (0.5 - Math.random()) * 200); + const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass * (0.1 + Math.random() * 0.3); + const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI; + this.force.x += forceMag * Math.cos(angle); + this.force.y += forceMag * Math.sin(angle) - 0.07 * this.mass; //antigravity + } + } + }; + }, + hopMother(x, y, radius = 20 + Math.ceil(Math.random() * 20)) { + mobs.spawn(x, y, 5, radius, "rgb(50,170,200)"); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 0.0008); //normal is 0.001 + me.accelMag = 0.05; + me.g = 0.0032; //required if using this.gravity + me.frictionAir = 0.01; + me.friction = 1 + me.frictionStatic = 1 + me.restitution = 0; + me.delay = 120 + 110 * simulation.CDScale; + me.randomHopFrequency = 300 + Math.floor(Math.random() * 150); + me.randomHopCD = simulation.cycle + me.randomHopFrequency; + Matter.Body.rotate(me, Math.random()); + spawn.shield(me, x, y); + me.dropEgg = function () { + if (mob.length < 360) { + let where = { x: this.position.x, y: this.position.y + 0.3 * radius } + for (let i = 0; i < 30; i++) { //find the ground + if (Matter.Query.point(map, where).length > 0 || Matter.Query.point(body, where).length > 0) break + where.y += 1 + } + spawn.hopEgg(where.x, where.y - 10) + } + } + me.do = function () { + this.gravity(); + this.seePlayerCheck(); + this.checkStatus(); + if (this.seePlayer.recall) { + if (this.cd < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + this.cd = simulation.cycle + this.delay; + const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x += forceMag * Math.cos(angle); + this.force.y += forceMag * Math.sin(angle) - (Math.random() * 0.06 + 0.1) * this.mass; //antigravity + this.dropEgg(); + } + } else { + //randomly hob if not aware of player + if (this.randomHopCD < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + this.randomHopCD = simulation.cycle + this.randomHopFrequency; + //slowly change randomHopFrequency after each hop + this.randomHopFrequency = Math.max(100, this.randomHopFrequency + (0.5 - Math.random()) * 200); + const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass * (0.1 + Math.random() * 0.3); + const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI; + this.force.x += forceMag * Math.cos(angle); + this.force.y += forceMag * Math.sin(angle) - 0.07 * this.mass; //antigravity + if (Math.random() < 0.2) this.dropEgg(); + } + } + }; + }, + hopEgg(x, y) { + mobs.spawn(x, y, 10, 9 + Math.floor(3 * Math.random()), "rgba(50, 150, 150,0.3)"); //"rgb(100,170,150)" //"rgb(61, 125, 121)" + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.0001); //normal is 0.001 + // Matter.Body.setStatic(me, true); //make static (disables taking damage) + me.frictionAir = 1 + me.damageReduction = 2 + me.collisionFilter.mask = cat.bullet //| cat.body + // me.collisionFilter.category = cat.mobBullet; + // me.collisionFilter.mask = cat.bullet | cat.body // | cat.player + me.isMine = true + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.isUnstable = true; //dies when blocked + me.showHealthBar = false; + me.explodeRange = 210 + 140 * Math.random() + me.isExploding = false + me.countDown = Math.ceil(4 * Math.random()) + me.hatchTimer = 600 + Math.floor(120 * Math.random()) + me.isInvulnerable = true //not actually invulnerable, just prevents block + ice-9 interaction + me.do = function () { + this.checkStatus(); + this.hatchTimer-- + if (this.hatchTimer < 1) { + spawn.hopBullet(this.position.x, this.position.y) + this.death(); + } + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) this.isExploding = true + if (this.isExploding) { + if (this.countDown-- < 0) { //explode + this.death(); + //hit player + if (Vector.magnitude(Vector.sub(this.position, player.position)) < this.explodeRange && m.immuneCycle < m.cycle) { + m.damage(0.01 * simulation.dmgScale * (tech.isRadioactiveResistance ? 0.2 : 1)); + m.energy -= 0.1 * (tech.isRadioactiveResistance ? 0.2 : 1) + if (m.energy < 0) m.energy = 0 + } + const range = this.explodeRange + 50 //mines get a slightly larger range to explode + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && Vector.magnitude(Vector.sub(this.position, mob[i].position)) < range && mob[i].isMine) { + mob[i].isExploding = true //explode other mines + } + } + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: this.explodeRange, + color: "rgba(50,180,180,0.45)", + time: 16 + }); + } + } + }; + }, + hopBullet(x, y, radius = 10 + Math.ceil(Math.random() * 8)) { + mobs.spawn(x, y, 5, radius, "rgb(0,200,180)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.leaveBody = false; + me.isDropPowerUp = false; + // me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.timeLeft = 1020 + Math.floor(480 * Math.random()); + + me.isRandomMove = Math.random() < 0.3 //most chase player, some don't + me.accelMag = 0.01; //jump height + me.g = 0.0015; //required if using this.gravity + me.frictionAir = 0.01; + me.friction = 1 + me.frictionStatic = 1 + me.restitution = 0; + me.delay = 120 + 60 * simulation.CDScale; + // Matter.Body.rotate(me, Math.random() * Math.PI); + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet; + me.onHit = function () { + this.explode(0.5 * this.mass); + }; + me.do = function () { + this.gravity(); + this.checkStatus(); + if (this.cd < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + this.cd = simulation.cycle + this.delay; + if (this.isRandomMove || Math.random() < 0.2) { + this.force.x += (0.01 + 0.03 * Math.random()) * this.mass * (Math.random() < 0.5 ? 1 : -1); //random move + } else { + this.force.x += (0.01 + 0.03 * Math.random()) * this.mass * (player.position.x > this.position.x ? 1 : -1); //chase player + } + this.force.y -= (0.04 + 0.04 * Math.random()) * this.mass + } + this.timeLimit(); + }; + }, + hopMotherBoss(x, y, radius = 120) { + mobs.spawn(x, y, 5, radius, "rgb(0,200,180)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + me.damageReduction = 0.12 + me.accelMag = 0.05; //jump height + me.g = 0.003; //required if using this.gravity + me.frictionAir = 0.01; + me.friction = 1 + me.frictionStatic = 1 + me.restitution = 0; + me.delay = 130 + 40 * simulation.CDScale; + Matter.Body.rotate(me, Math.random() * Math.PI); + spawn.shield(me, x, y, 1); + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // for (let i = 0, len = 3 + 0.1 * simulation.difficulty; i < len; ++i) spawn.hopBullet(this.position.x + 100 * (Math.random() - 0.5), this.position.y + 100 * (Math.random() - 0.5)) + }; + me.do = function () { + this.gravity(); + this.seePlayerCheck(); + this.checkStatus(); + if (this.cd < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + this.cd = simulation.cycle + this.delay; + //spawn hopBullets after each jump + for (let i = 0, len = 1 + 0.05 * simulation.difficulty; i < len; ++i) spawn.hopBullet(this.position.x + 100 * (Math.random() - 0.5), this.position.y + 100 * (Math.random() - 0.5)) + + this.force.x += (0.02 + 0.06 * Math.random()) * this.mass * (player.position.x > this.position.x ? 1 : -1); + this.force.y -= (0.08 + 0.08 * Math.random()) * this.mass + } + }; + }, + // hopBoss(x, y, radius = 90) { + // mobs.spawn(x, y, 5, radius, "rgb(0,200,180)"); + // let me = mob[mob.length - 1]; + // me.isBoss = true; + // me.g = 0.005; //required if using this.gravity + // me.frictionAir = 0.01; + // me.friction = 1 + // me.frictionStatic = 1 + // me.restitution = 0; + // me.accelMag = 0.07; + // me.delay = 120 * simulation.CDScale; + // me.randomHopFrequency = 200 + // me.randomHopCD = simulation.cycle + me.randomHopFrequency; + // // me.memory = 420; + // me.isInAir = false + // Matter.Body.setDensity(me, 0.03); //extra dense //normal is 0.001 //makes effective life much larger + // spawn.shield(me, x, y, 1); + // spawn.spawnOrbitals(me, radius + 60, 1) + // me.onDeath = function() { + // powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // }; + // me.lastSpeed = me.speed + // me.damageReduction = 0.25 + // me.do = function() { + // // this.armor(); + // this.gravity(); + // this.seePlayerCheck(); + // this.checkStatus(); + // if (this.seePlayer.recall) { + // const deltaSpeed = this.lastSpeed - this.speed + // this.lastSpeed = this.speed + // if (deltaSpeed > 13 && this.speed < 5) { //if the player slows down greatly in one cycle + // //damage and push player away, push away blocks + // const range = 800 //Math.min(800, 50 * deltaSpeed) + // for (let i = body.length - 1; i > -1; i--) { + // if (!body[i].isNotHoldable) { + // sub = Vector.sub(body[i].position, this.position); + // dist = Vector.magnitude(sub); + // if (dist < range) { + // knock = Vector.mult(Vector.normalise(sub), Math.min(20, 50 * body[i].mass / dist)); + // body[i].force.x += knock.x; + // body[i].force.y += knock.y; + // } + // } + // } + // simulation.drawList.push({ //draw radius + // x: this.position.x, + // y: this.position.y, + // radius: range, + // color: "rgba(0,200,180,0.6)", + // time: 4 + // }); + // } + // if (this.isInAir) { + // if (this.velocity.y > -0.01 && Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length) { //not moving up, and has hit the map or a body + // this.isInAir = false //landing + // this.cd = simulation.cycle + this.delay + // } + // } else { //on ground + // if (this.cd < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { //jump + // this.isInAir = true + // const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass; + // const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + // this.force.x += forceMag * Math.cos(angle); + // this.force.y += forceMag * Math.sin(angle) - (Math.random() * 0.05 + 0.04) * this.mass; //antigravity + // } + // } + // // if (this.cd < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + // // this.cd = simulation.cycle + this.delay; + // // const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass; + // // const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + // // this.force.x += forceMag * Math.cos(angle); + // // this.force.y += forceMag * Math.sin(angle) - (Math.random() * 0.05 + 0.04) * this.mass; //antigravity + // // } + // } else { + // //randomly hob if not aware of player + // if (this.randomHopCD < simulation.cycle && (Matter.Query.collides(this, map).length || Matter.Query.collides(this, body).length)) { + // this.randomHopCD = simulation.cycle + this.randomHopFrequency; + // //slowly change randomHopFrequency after each hop + // this.randomHopFrequency = Math.max(100, this.randomHopFrequency + 200 * (0.5 - Math.random())); + // const forceMag = (this.accelMag + this.accelMag * Math.random()) * this.mass * (0.5 + Math.random() * 0.2); + // const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI; + // this.force.x += forceMag * Math.cos(angle); + // this.force.y += forceMag * Math.sin(angle) - (0.1 + 0.08 * Math.random()) * this.mass; //antigravity + // } + // } + // }; + // }, + spinner(x, y, radius = 30 + Math.ceil(Math.random() * 35)) { + mobs.spawn(x, y, 5, radius, "#000000"); + let me = mob[mob.length - 1]; + me.fill = "#28b"; + me.rememberFill = me.fill; + me.cd = 0; + me.burstDir = { x: 0, y: 0 }; + me.frictionAir = 0.022; + me.lookTorque = 0.0000014; + me.restitution = 0; + spawn.shield(me, x, y); + me.look = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + if (this.seePlayer.recall && this.cd < simulation.cycle) { + this.burstDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + this.cd = simulation.cycle + 40; + this.do = this.spin + } + } + me.do = me.look + me.spin = function () { + this.checkStatus(); + this.torque += 0.000035 * this.inertia; + //draw attack vector + const mag = this.radius * 2.5 + 50; + ctx.strokeStyle = "rgba(0,0,0,0.2)"; + ctx.lineWidth = 3; + ctx.setLineDash([10, 20]); //30 + const dir = Vector.add(this.position, Vector.mult(this.burstDir, mag)); + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(dir.x, dir.y); + ctx.stroke(); + ctx.setLineDash([]); + if (this.cd < simulation.cycle) { + this.fill = this.rememberFill; + this.cd = simulation.cycle + 180 * simulation.CDScale + this.do = this.look + this.force = Vector.mult(this.burstDir, this.mass * 0.25); + } + } + }, + sucker(x, y, radius = 30 + Math.ceil(Math.random() * 25)) { + radius = 9 + radius / 8; //extra small + mobs.spawn(x, y, 6, radius, "transparent"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; //used for drawSneaker + me.eventHorizon = radius * 30; //required for blackhole + me.seeAtDistance2 = (me.eventHorizon + 400) * (me.eventHorizon + 400); //vision limit is event horizon + me.accelMag = 0.00012 * simulation.accelScale; + me.frictionAir = 0.025; + me.collisionFilter.mask = cat.player | cat.bullet | cat.body + me.memory = Infinity; + Matter.Body.setDensity(me, 0.015); //extra dense //normal is 0.001 //makes effective life much larger + me.do = function () { + //keep it slow, to stop issues from explosion knock backs + if (this.speed > 5) { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.99, + y: this.velocity.y * 0.99 + }); + } + this.seePlayerCheckByDistance() + this.checkStatus(); + //accelerate towards the player + if (this.seePlayer.recall) { + const forceMag = this.accelMag * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x += forceMag * Math.cos(angle); + this.force.y += forceMag * Math.sin(angle); + } + //eventHorizon waves in and out + const eventHorizon = this.eventHorizon * (0.93 + 0.17 * Math.sin(simulation.cycle * 0.011)) + //draw darkness + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon * 0.25, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.9)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon * 0.55, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.5)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.1)"; + ctx.fill(); + + //when player is inside event horizon + if (Vector.magnitude(Vector.sub(this.position, player.position)) < eventHorizon) { + if (m.immuneCycle < m.cycle) { + if (m.energy > 0) m.energy -= 0.005 + if (m.energy < 0.1) m.damage(0.0001 * simulation.dmgScale); + } + const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x); + player.force.x -= 0.00125 * player.mass * Math.cos(angle) * (m.onGround ? 1.8 : 1); + player.force.y -= 0.0001 * player.mass * Math.sin(angle); + //draw line to player + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineWidth = Math.min(60, this.radius * 2); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + ctx.stroke(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ctx.fill(); + } + } + if (level.isMobShields) spawn.shield(me, x, y); + }, + // timeBoss(x, y, radius = 25) { + // mobs.spawn(x, y, 12, radius, "#000"); + // let me = mob[mob.length - 1]; + // me.isBoss = true; + // me.stroke = "transparent"; //used for drawSneaker + // me.eventHorizon = 1100; //required for black hole + // me.eventHorizonGoal = 1100; //required for black hole + // me.seeAtDistance2 = (me.eventHorizon + 1200) * (me.eventHorizon + 1200); //vision limit is event horizon + // me.accelMag = 0.00006 * simulation.accelScale; + // // me.collisionFilter.mask = cat.player | cat.bullet //| cat.body + // // me.frictionAir = 0.005; + // me.memory = Infinity; + // Matter.Body.setDensity(me, 0.03); //extra dense //normal is 0.001 //makes effective life much larger + // me.onDeath = function() { + // powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // }; + // me.damageReduction = 0.23 + // me.do = function() { + // //keep it slow, to stop issues from explosion knock backs + // if (!(simulation.cycle % this.seePlayerFreq)) { + // if (this.distanceToPlayer2() < this.seeAtDistance2) { //&& !m.isCloak ignore cloak for black holes + // this.locatePlayer(); + // if (!this.seePlayer.yes) this.seePlayer.yes = true; + // } else if (this.seePlayer.recall) { + // this.lostPlayer(); + // } + // } + // this.checkStatus(); + // if (this.seePlayer.recall) { + // //accelerate towards the player + // const forceMag = this.accelMag * this.mass; + // const dx = this.seePlayer.position.x - this.position.x + // const dy = this.seePlayer.position.y - this.position.y + // const mag = Math.sqrt(dx * dx + dy * dy) + // this.force.x += forceMag * dx / mag; + // this.force.y += forceMag * dy / mag; + + // //eventHorizon waves in and out + // const eventHorizon = this.eventHorizon * (1 + 0.2 * Math.sin(simulation.cycle * 0.008)) + // // zoom camera in and out with the event horizon + + // //draw darkness + // if (!simulation.isTimeSkipping) { + // ctx.beginPath(); + // ctx.arc(this.position.x, this.position.y, eventHorizon, 0, 2 * Math.PI); + // ctx.fillStyle = "rgba(0,0,0,0.05)"; + // ctx.fill(); + // //when player is inside event horizon + // if (Vector.magnitude(Vector.sub(this.position, player.position)) < eventHorizon) { + // // if (!(simulation.cycle % 10)) simulation.timePlayerSkip(5) + // // if (!(simulation.cycle % 2)) simulation.timePlayerSkip(1) + // simulation.timePlayerSkip(2) + + // // if (m.immuneCycle < m.cycle) { + // // if (m.energy > 0) m.energy -= 0.004 + // // if (m.energy < 0.1) m.damage(0.00017 * simulation.dmgScale); + // // } + // } + // } + // } + // } + // }, + suckerBoss(x, y, radius = 25) { + mobs.spawn(x, y, 12, radius, "#000"); + let me = mob[mob.length - 1]; + me.isBoss = true; + + me.stroke = "transparent"; //used for drawSneaker + me.eventHorizon = 1100; //required for black hole + me.seeAtDistance2 = (me.eventHorizon + 3000) * (me.eventHorizon + 3000); //vision limit is event horizon + me.accelMag = 0.00004 * simulation.accelScale; + me.collisionFilter.mask = cat.player | cat.bullet //| cat.body + // me.frictionAir = 0.005; + me.memory = 1600; + Matter.Body.setDensity(me, 0.06); //extra dense //normal is 0.001 //makes effective life much larger + me.onDeath = function () { + //applying forces to player doesn't seem to work inside this method, not sure why + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + if (simulation.difficulty > 5) { + //teleport everything to center + function toMe(who, where, range) { + for (let i = 0, len = who.length; i < len; i++) { + if (!who[i].isNotHoldable) { + const SUB = Vector.sub(who[i].position, where) + const DISTANCE = Vector.magnitude(SUB) + if (DISTANCE < range) { + Matter.Body.setPosition(who[i], where) + } + } + } + } + toMe(body, this.position, this.eventHorizon) + toMe(mob, this.position, this.eventHorizon) + // toMe(bullet, this.position, this.eventHorizon)) + } + }; + me.damageReduction = 0.27 + me.do = function () { + //keep it slow, to stop issues from explosion knock backs + if (this.speed > 1) { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.95, + y: this.velocity.y * 0.95 + }); + } + if (!(simulation.cycle % this.seePlayerFreq)) { + if (this.distanceToPlayer2() < this.seeAtDistance2) { //&& !m.isCloak ignore cloak for black holes + this.locatePlayer(); + if (!this.seePlayer.yes) this.seePlayer.yes = true; + } else if (this.seePlayer.recall) { + this.lostPlayer(); + } + } + this.checkStatus(); + if (this.seePlayer.recall) { + //throw large seekers + if (!(simulation.cycle % 90)) { + spawn.seeker(this.position.x, this.position.y, 15 * (0.7 + 0.5 * Math.random()), 7); //give the bullet a rotational velocity as if they were attached to a vertex + const who = mob[mob.length - 1] + Matter.Body.setDensity(who, 0.00001); //normal is 0.001 + who.timeLeft = 600 + who.accelMag = 0.0002 * simulation.accelScale; //* (0.8 + 0.4 * Math.random()) + who.frictionAir = 0.01 //* (0. + const velocity = Vector.mult(Vector.normalise(Vector.sub(m.pos, this.position)), -20); //set direction to turn to fire //Vector.mult(Vector.perp(Vector.normalise(Vector.sub(this.position, this.vertices[index]))), -35) + Matter.Body.setVelocity(who, { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }); + } + //accelerate towards the player + const forceMag = this.accelMag * this.mass; + const dx = this.seePlayer.position.x - this.position.x + const dy = this.seePlayer.position.y - this.position.y + const mag = Math.sqrt(dx * dx + dy * dy) + this.force.x += forceMag * dx / mag; + this.force.y += forceMag * dy / mag; + //eventHorizon waves in and out + const eventHorizon = this.eventHorizon * (1 + 0.2 * Math.sin(simulation.cycle * 0.008)) // zoom camera in and out with the event horizon + //draw darkness + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon * 0.2, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,20,40,0.6)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon * 0.4, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,20,40,0.4)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon * 0.6, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,20,40,0.3)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon * 0.8, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,20,40,0.2)"; + ctx.fill(); + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, eventHorizon, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.05)"; + ctx.fill(); + //when player is inside event horizon + if (Vector.magnitude(Vector.sub(this.position, player.position)) < eventHorizon) { + if (m.immuneCycle < m.cycle) { + if (m.energy > 0) m.energy -= 0.008 + if (m.energy < 0.1) m.damage(0.00015 * simulation.dmgScale); + } + const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x); + player.force.x -= 0.0013 * Math.cos(angle) * player.mass * (m.onGround ? 1.7 : 1); + player.force.y -= 0.0013 * Math.sin(angle) * player.mass; + //draw line to player + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineWidth = Math.min(60, this.radius * 2); + ctx.strokeStyle = "rgba(0,0,0,0.5)"; + ctx.stroke(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ctx.fill(); + } + this.curl(eventHorizon); + //attract other power ups + for (let i = 0; i < powerUp.length; i++) { //attract heal power ups + const sub = Vector.sub(this.position, powerUp[i].position) + const mag = 0.0015 * Math.min(1, (Vector.magnitude(sub) - 200) / this.eventHorizon) + const attract = Vector.mult(Vector.normalise(sub), mag * powerUp[i].mass) + powerUp[i].force.x += attract.x; + powerUp[i].force.y += attract.y - powerUp[i].mass * simulation.g; //negate gravity + // Matter.Body.setVelocity(powerUp[i], Vector.mult(powerUp[i].velocity, 0.7)); + } + } + } + }, + spiderBoss(x, y, radius = 60 + Math.ceil(Math.random() * 10)) { + let targets = [] //track who is in the node boss, for shields + mobs.spawn(x, y, 6, radius, "#b386e8"); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 0.003); //extra dense //normal is 0.001 //makes effective life much larger and damage on collision + me.isBoss = true; + me.damageReduction = 0.13 //normal is 1, most bosses have 0.25 + + targets.push(me.id) //add to shield protection + me.friction = 0; + me.frictionAir = 0.0067; + me.lookTorque = 0.0000008; //controls spin while looking for player + me.g = 0.0002; //required if using this.gravity + me.seePlayerFreq = Math.floor((30 + 20 * Math.random())); + const springStiffness = 0.00014; + const springDampening = 0.0005; + + me.springTarget = { x: me.position.x, y: me.position.y }; + const len = cons.length; + cons[len] = Constraint.create({ + pointA: me.springTarget, + bodyB: me, + stiffness: springStiffness, + damping: springDampening + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len].length = 100 + 1.5 * radius; + me.cons = cons[len]; + + me.springTarget2 = { + x: me.position.x, + y: me.position.y + }; + const len2 = cons.length; + cons[len2] = Constraint.create({ + pointA: me.springTarget2, + bodyB: me, + stiffness: springStiffness, + damping: springDampening, + length: 0 + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len2].length = 100 + 1.5 * radius; + me.cons2 = cons[len2]; + me.do = function () { + // this.armor(); + this.gravity(); + this.searchSpring(); + this.checkStatus(); + this.springAttack(); + }; + + me.onDeath = function () { + this.removeCons(); + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + + radius = 22 // radius of each node mob + const sideLength = 100 // distance between each node mob + const nodes = 6 + const angle = 2 * Math.PI / nodes + + spawn.allowShields = false; //don't want shields on individual mobs + + for (let i = 0; i < nodes; ++i) { + spawn.stabber(x + sideLength * Math.sin(i * angle), y + sideLength * Math.cos(i * angle), radius, 12); + Matter.Body.setDensity(mob[mob.length - 1], 0.003); //extra dense //normal is 0.001 //makes effective life much larger + mob[mob.length - 1].damageReduction = 0.12 + targets.push(mob[mob.length - 1].id) //track who is in the node boss, for shields + } + + const attachmentStiffness = 0.02 + spawn.constrain2AdjacentMobs(nodes, attachmentStiffness, true); //loop mobs together + + for (let i = 0; i < nodes; ++i) { //attach to center mob + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: mob[mob.length - i - 1], + stiffness: attachmentStiffness, + damping: 0.03 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + //spawn shield around all nodes + spawn.groupShield(targets, x, y, sideLength + 1 * radius + nodes * 5 - 25); + spawn.allowShields = true; + }, + mantisBoss(x, y, radius = 35, isSpawnBossPowerUp = true) { + mobs.spawn(x, y, 5, radius, "#6ba"); + let me = mob[mob.length - 1]; + me.babyList = [] //list of mobs that are apart of this boss + Matter.Body.setDensity(me, 0.0015); //extra dense //normal is 0.001 //makes effective life much larger and damage on collision + me.damageReduction = 0.14 //normal is 1, most bosses have 0.25 + me.isBoss = true; + + me.friction = 0; + me.frictionAir = 0.006; + me.g = 0.0002; //required if using this.gravity + me.seePlayerFreq = 31; + const springStiffness = 0.00003; //simulation.difficulty + const springDampening = 0.0002; + me.springTarget = { x: me.position.x, y: me.position.y }; + const len = cons.length; + cons[len] = Constraint.create({ + pointA: me.springTarget, + bodyB: me, + stiffness: springStiffness, + damping: springDampening + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len].length = 100 + 1.5 * radius; + me.cons = cons[len]; + me.springTarget2 = { x: me.position.x, y: me.position.y }; + const len2 = cons.length; + cons[len2] = Constraint.create({ + pointA: me.springTarget2, + bodyB: me, + stiffness: springStiffness, + damping: springDampening, + length: 0 + }); + Composite.add(engine.world, cons[cons.length - 1]); + cons[len2].length = 100 + 1.5 * radius; + me.cons2 = cons[len2]; + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.invulnerabilityCountDown = 0 + me.do = function () { + this.checkStatus(); + this.gravity(); + //draw the two dots on the end of the springs + ctx.beginPath(); + ctx.arc(this.cons.pointA.x, this.cons.pointA.y, 6, 0, 2 * Math.PI); + ctx.arc(this.cons2.pointA.x, this.cons2.pointA.y, 6, 0, 2 * Math.PI); + ctx.fillStyle = "#222"; + ctx.fill(); + // this.seePlayerCheck() + this.seePlayerByHistory() + this.invulnerabilityCountDown-- + if (this.isInvulnerable) { + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + for (let i = 0; i < this.babyList.length; i++) { + if (this.babyList[i].alive) { + let vertices = this.babyList[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + } + } + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + if (this.invulnerabilityCountDown < 0) { + this.invulnerabilityCountDown = 110 + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + for (let i = 0; i < this.babyList.length; i++) { + if (this.babyList[i].alive) { + this.babyList[i].isInvulnerable = false + this.babyList[i].damageReduction = this.startingDamageReduction + } + } + } + } else if (this.invulnerabilityCountDown < 0) { + this.invulnerabilityCountDown = 120 + 9 * simulation.difficulty + this.isInvulnerable = true + if (this.damageReduction) this.startingDamageReduction = this.damageReduction + this.damageReduction = 0 + for (let i = 0; i < this.babyList.length; i++) { + if (this.babyList[i].alive) { + this.babyList[i].isInvulnerable = true + this.babyList[i].damageReduction = 0 + } + } + } + // set new values of the ends of the spring constraints + const stepRange = 700 + if (this.seePlayer.recall && Matter.Query.ray(map, this.position, this.seePlayer.position).length === 0) { + if (!(simulation.cycle % (this.seePlayerFreq * 2))) { + const unit = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)) + const goal = Vector.add(this.position, Vector.mult(unit, stepRange)) + this.springTarget.x = goal.x; + this.springTarget.y = goal.y; + this.cons.length = -200; + this.cons2.length = 100 + 1.5 * this.radius; + } else if (!(simulation.cycle % this.seePlayerFreq)) { + const unit = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)) + const goal = Vector.add(this.position, Vector.mult(unit, stepRange)) + this.springTarget2.x = goal.x; + this.springTarget2.y = goal.y; + this.cons.length = 100 + 1.5 * this.radius; + this.cons2.length = -200; + } + } else { + this.torque = this.lookTorque * this.inertia; + //spring to random place on map + if (!(simulation.cycle % (this.seePlayerFreq))) { + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const seeRange = 3000; + const look = { x: this.position.x + seeRange * Math.cos(this.angle), y: this.position.y + seeRange * Math.sin(this.angle) }; + best = vertexCollision(this.position, look, [map]); + if (best.dist2 != Infinity) { + this.springTarget.x = best.x; + this.springTarget.y = best.y; + this.cons.length = 100 + 1.5 * this.radius; + this.cons2.length = 100 + 1.5 * this.radius; + } + } + } + }; + me.onDeath = function () { + this.removeCons(); + if (isSpawnBossPowerUp) powerUps.spawnBossPowerUp(this.position.x, this.position.y) + for (let i = 0; i < this.babyList.length; i++) { + if (this.babyList[i].alive) { + this.babyList[i].collisionFilter.mask = cat.map | cat.bullet | cat.player + this.babyList[i].isInvulnerable = false + this.babyList[i].damageReduction = this.startingDamageReduction + this.babyList[i].collisionFilter.mask = cat.bullet | cat.player | cat.map | cat.body + } + } + }; + const sideLength = 80 // distance between each node mob + const nodes = 3 + const angle = 2 * Math.PI / nodes + spawn.allowShields = false; //don't want shields on individual mobs, it messes with the constraints + for (let i = 0; i < nodes; ++i) { + spawn.striker(x + sideLength * Math.sin(i * angle), y + sideLength * Math.cos(i * angle), 20, 12); + const babyMob = mob[mob.length - 1] + me.babyList.push(babyMob) + babyMob.fill = "rgb(68, 102, 119)" + babyMob.isBoss = true; + // Matter.Body.setDensity(babyMob, 0.001); //extra dense //normal is 0.001 //makes effective life much larger and increases damage + babyMob.damageReduction = this.startingDamageReduction * 0.8 + babyMob.collisionFilter.mask = cat.bullet | cat.player //can't touch other mobs //cat.map | cat.body | + babyMob.delay = 60 + 55 * simulation.CDScale + Math.floor(Math.random() * 20); + babyMob.strikeRange = 400 + babyMob.onHit = function () { + this.cd = simulation.cycle + this.delay; + //dislodge ammo + if (b.inventory.length) { + let isRemovedAmmo = false + const numRemoved = 3 + for (let j = 0; j < numRemoved; j++) { + for (let i = 0; i < b.inventory.length; i++) { + const gun = b.guns[b.inventory[i]] + if (gun.ammo > 0 && gun.ammo !== Infinity) { + gun.ammo -= Math.ceil((Math.random() + Math.random()) * gun.ammoPack) + if (gun.ammo < 0) gun.ammo = 0 + isRemovedAmmo = true + } + } + } + if (isRemovedAmmo) { + simulation.updateGunHUD(); + for (let j = 0; j < numRemoved; j++) powerUps.directSpawn(this.position.x + 10 * Math.random(), this.position.y + 10 * Math.random(), "ammo"); + powerUps.ejectGraphic(); + } + } + }; + } + const stiffness = 0.01 + const damping = 0.1 + for (let i = 1; i < nodes; ++i) { //attach to center mob + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - i], + bodyB: mob[mob.length - i - 1], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - 1], + bodyB: mob[mob.length - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + + + for (let i = 0; i < nodes; ++i) { //attach to center mob + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: mob[mob.length - i - 1], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + spawn.allowShields = true; + }, + // timeSkipBoss(x, y, radius = 55) { + // mobs.spawn(x, y, 6, radius, '#000'); + // let me = mob[mob.length - 1]; + // me.isBoss = true; + // // me.stroke = "transparent"; //used for drawSneaker + // me.timeSkipLastCycle = 0 + // me.eventHorizon = 1800; //required for black hole + // me.seeAtDistance2 = (me.eventHorizon + 2000) * (me.eventHorizon + 2000); //vision limit is event horizon + 2000 + // me.accelMag = 0.0004 * simulation.accelScale; + // // me.frictionAir = 0.005; + // // me.memory = 1600; + // // Matter.Body.setDensity(me, 0.02); //extra dense //normal is 0.001 //makes effective life much larger + // Matter.Body.setDensity(me, 0.0005 + 0.00018 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + // spawn.shield(me, x, y, 1); + // me.onDeath = function() { + // //applying forces to player doesn't seem to work inside this method, not sure why + // powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // }; + // me.do = function() { + // //keep it slow, to stop issues from explosion knock backs + // if (this.speed > 8) { + // Matter.Body.setVelocity(this, { + // x: this.velocity.x * 0.99, + // y: this.velocity.y * 0.99 + // }); + // } + // this.seePlayerCheck(); + // this.checkStatus(); + // this.attraction() + // if (!simulation.isTimeSkipping) { + // const compress = 1 + // if (this.timeSkipLastCycle < simulation.cycle - compress && + // Vector.magnitude(Vector.sub(this.position, player.position)) < this.eventHorizon) { + // this.timeSkipLastCycle = simulation.cycle + // simulation.timeSkip(compress) + + // this.fill = `rgba(0,0,0,${0.4+0.6*Math.random()})` + // this.stroke = "#014" + // this.isShielded = false; + // this.isDropPowerUp = true; + // this.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob; //can't touch bullets + + // ctx.beginPath(); + // ctx.arc(this.position.x, this.position.y, this.eventHorizon, 0, 2 * Math.PI); + // ctx.fillStyle = "#fff"; + // ctx.globalCompositeOperation = "destination-in"; //in or atop + // ctx.fill(); + // ctx.globalCompositeOperation = "source-over"; + // ctx.beginPath(); + // ctx.arc(this.position.x, this.position.y, this.eventHorizon, 0, 2 * Math.PI); + // ctx.clip(); + + // // ctx.beginPath(); + // // ctx.arc(this.position.x, this.position.y, 9999, 0, 2 * Math.PI); + // // ctx.fillStyle = "#000"; + // // ctx.fill(); + // // ctx.strokeStyle = "#000"; + // // ctx.stroke(); + + // // ctx.beginPath(); + // // ctx.arc(this.position.x, this.position.y, this.eventHorizon, 0, 2 * Math.PI); + // // ctx.fillStyle = `rgba(0,0,0,${0.05*Math.random()})`; + // // ctx.fill(); + // // ctx.strokeStyle = "#000"; + // // ctx.stroke(); + // } else { + // this.isShielded = true; + // this.isDropPowerUp = false; + // this.seePlayer.recall = false + // this.fill = "transparent" + // this.stroke = "transparent" + // this.collisionFilter.mask = cat.player | cat.map | cat.body | cat.mob; //can't touch bullets + // ctx.beginPath(); + // ctx.arc(this.position.x, this.position.y, this.eventHorizon, 0, 2 * Math.PI); + // ctx.fillStyle = `rgba(0,0,0,${0.05*Math.random()})`; + // ctx.fill(); + // } + // } + // } + // }, + beamer(x, y, radius = 15 + Math.ceil(Math.random() * 15)) { + mobs.spawn(x, y, 4, radius, "rgb(255,0,190)"); + let me = mob[mob.length - 1]; + me.repulsionRange = 73000; //squared + me.laserRange = 370; + me.accelMag = 0.0005 * simulation.accelScale; + me.frictionStatic = 0; + me.friction = 0; + spawn.shield(me, x, y); + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + this.repulsion(); + this.harmZone(); + }; + }, + historyBoss(x, y, radius = 30) { + if (tech.dynamoBotCount > 0) { + spawn.randomLevelBoss(x, y, spawn.nonCollideBossList) + return + } + mobs.spawn(x, y, 0, radius, "transparent"); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 0.21); //extra dense //normal is 0.001 + me.laserRange = 350; + me.seeAtDistance2 = 2000000; + me.isBoss = true; + me.damageReduction = 0.38 // me.damageReductionGoal + + me.showHealthBar = false; //drawn in this.awake + me.delayLimit = 60 + Math.floor(30 * Math.random()); + me.followDelay = 600 - Math.floor(90 * Math.random()) + me.stroke = "transparent"; //used for drawGhost + me.collisionFilter.mask = cat.bullet | cat.body + me.memory = Infinity + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + requestAnimationFrame(() => { + requestAnimationFrame(() => { + ctx.setTransform(1, 0, 0, 1, 0, 0); //reset warp effect + if (simulation.isInvertedVertical) { //redo vertical camera effects + ctx.translate(0, canvas.height); // Move the origin down to the bottom + ctx.scale(1, -1); // Flip vertically + //flip mouse Y + simulation.isInvertedVertical = true + mouseMove = function (e) { + simulation.mouse.x = e.clientX; + simulation.mouse.y = window.innerHeight - e.clientY; + } + } + ctx.setLineDash([]) //reset stroke dash effect + }) + }) + }; + me.warpIntensity = 0 + me.awake = function () { + this.checkStatus(); + //health bar needs to be here because the position is being set + const h = this.radius * 0.3; + const w = this.radius * 2; + const x = this.position.x - w / 2; + const y = this.position.y - w * 0.7; + ctx.fillStyle = "rgba(100, 100, 100, 0.3)"; + ctx.fillRect(x, y, w, h); + ctx.fillStyle = "rgba(150,0,255,0.7)"; + ctx.fillRect(x, y, w * this.health, h); + + //draw eye + const unit = Vector.normalise(Vector.sub(m.pos, this.position)) + const eye = Vector.add(Vector.mult(unit, 15), this.position) + ctx.beginPath(); + ctx.arc(eye.x, eye.y, 4, 0, 2 * Math.PI); + ctx.moveTo(this.position.x + 20 * unit.x, this.position.y + 20 * unit.y); + ctx.lineTo(this.position.x + 30 * unit.x, this.position.y + 30 * unit.y); + ctx.strokeStyle = this.stroke; + ctx.lineWidth = 2; + ctx.stroke(); + + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); //the dashed effect is not set back to normal, because it looks neat for how the player is drawn + // ctx.lineDashOffset = 6*(simulation.cycle % 215); + if (this.distanceToPlayer() < this.laserRange) { + if (m.immuneCycle < m.cycle) { + if (m.energy > 0.002) { + m.energy -= 0.004 + } else { + m.damage(0.0004 * simulation.dmgScale) + } + } + this.warpIntensity += 0.0004 + requestAnimationFrame(() => { + if (!simulation.paused && m.alive) { + ctx.transform(1, this.warpIntensity * (Math.random() - 0.5), this.warpIntensity * (Math.random() - 0.5), 1, 0, 0); //ctx.transform(Horizontal scaling. A value of 1 results in no scaling, Vertical skewing, Horizontal skewing, Vertical scaling. A value of 1 results in no scaling, Horizontal translation (moving), Vertical translation (moving)) //https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform + // ctx.transform(1 - scale * (Math.random() - 0.5), skew * (Math.random() - 0.5), skew * (Math.random() - 0.5), 1 - scale * (Math.random() - 0.5), translation * (Math.random() - 0.5), translation * (Math.random() - 0.5)); //ctx.transform(Horizontal scaling. A value of 1 results in no scaling, Vertical skewing, Horizontal skewing, Vertical scaling. A value of 1 results in no scaling, Horizontal translation (moving), Vertical translation (moving)) //https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform + } + }) + ctx.beginPath(); + ctx.moveTo(eye.x, eye.y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineTo(m.pos.x + (Math.random() - 0.5) * 3000, m.pos.y + (Math.random() - 0.5) * 3000); + ctx.lineWidth = 2; + ctx.strokeStyle = "rgb(150,0,255)"; + ctx.stroke(); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(150,0,255,0.1)"; + ctx.fill(); + } else { + this.warpIntensity = 0; + } + + //several ellipses spinning about the same axis + const rotation = simulation.cycle * 0.015 + const phase = simulation.cycle * 0.021 + ctx.lineWidth = 1; + ctx.fillStyle = "rgba(150,0,255,0.05)" + ctx.strokeStyle = "#70f" + for (let i = 0, len = 6; i < len; i++) { + ctx.beginPath(); + ctx.ellipse(this.position.x, this.position.y, this.laserRange * Math.abs(Math.sin(phase + i / len * Math.PI)), this.laserRange, rotation, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + } + + if (!this.isStunned && !this.isSlowed) { + if (this.followDelay > this.delayLimit) this.followDelay -= 0.15; + let history = m.history[(m.cycle - Math.floor(this.followDelay)) % 600] + Matter.Body.setPosition(this, { x: history.position.x, y: history.position.y - history.yOff + 24.2859 }) //bullets move with player + } + } + me.do = function () { + if (this.seePlayer.recall || (!(simulation.cycle % this.seePlayerFreq) && this.distanceToPlayer2() < this.seeAtDistance2 && !m.isCloak)) { + setTimeout(() => { + this.do = this.awake + this.stroke = "rgba(205,0,255,0.5)" + this.fill = "rgba(205,0,255,0.1)" + this.seePlayer.yes = true + }, 2000); + } + this.checkStatus(); + }; + }, + focuser(x, y, radius = 30 + Math.ceil(Math.random() * 10)) { + radius = Math.ceil(radius * 0.7); + mobs.spawn(x, y, 4, radius, "rgb(0,0,255)"); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 0.003); //extra dense //normal is 0.001 + me.restitution = 0; + me.laserPos = me.position; //required for laserTracking + me.repulsionRange = 1200000; //squared + me.accelMag = 0.00009 * simulation.accelScale; + me.frictionStatic = 0; + me.friction = 0; + me.onDamage = function () { + this.laserPos = this.position; + }; + spawn.shield(me, x, y); + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + const dist2 = this.distanceToPlayer2(); + //laser Tracking + if (this.seePlayer.yes && dist2 < 4000000) { + const rangeWidth = 2000; //this is sqrt of 4000000 from above if() + //targeting laser will slowly move from the mob to the player's position + this.laserPos = Vector.add(this.laserPos, Vector.mult(Vector.sub(player.position, this.laserPos), 0.03)); + let targetDist = Vector.magnitude(Vector.sub(this.laserPos, m.pos)); + const r = 12; + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + if (targetDist < r + 16) { + targetDist = r + 10; + if (m.immuneCycle < m.cycle) { + m.damage(0.0003 * simulation.dmgScale); + if (m.energy > 0.1) m.energy -= 0.003 + } + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(m.pos.x, m.pos.y); + ctx.lineTo(m.pos.x + (Math.random() - 0.5) * 3000, m.pos.y + (Math.random() - 0.5) * 3000); + ctx.lineWidth = 2; + ctx.strokeStyle = "rgb(0,0,255)"; + ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + ctx.beginPath(); + ctx.arc(m.pos.x, m.pos.y, 40, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(0,0,255,0.1)"; + ctx.fill(); + } else { + const laserWidth = 0.0005; + let laserOffR = Vector.rotateAbout(this.laserPos, (targetDist - r) * laserWidth, this.position); + let sub = Vector.normalise(Vector.sub(laserOffR, this.position)); + laserOffR = Vector.add(laserOffR, Vector.mult(sub, rangeWidth)); + ctx.lineTo(laserOffR.x, laserOffR.y); + + let laserOffL = Vector.rotateAbout(this.laserPos, (targetDist - r) * -laserWidth, this.position); + sub = Vector.normalise(Vector.sub(laserOffL, this.position)); + laserOffL = Vector.add(laserOffL, Vector.mult(sub, rangeWidth)); + ctx.lineTo(laserOffL.x, laserOffL.y); + ctx.fillStyle = `rgba(0,0,255,${Math.max(0, 0.6 * r / targetDist)})` + ctx.fill(); + } + } else { + this.laserPos = this.position; + } + } + }, + // focuser(x, y, radius = 30 + Math.ceil(Math.random() * 10)) { + // radius = Math.ceil(radius * 0.7); + // mobs.spawn(x, y, 4, radius, "rgb(0,0,255)"); + // let me = mob[mob.length - 1]; + // Matter.Body.setDensity(me, 0.003); //extra dense //normal is 0.001 + // me.restitution = 0; + // me.laserPos = me.position; //required for laserTracking + // me.repulsionRange = 1200000; //squared + // me.accelMag = 0.00009 * simulation.accelScale; + // me.frictionStatic = 0; + // me.friction = 0; + // me.onDamage = function () { + // this.laserPos = this.position; + // }; + // spawn.shield(me, x, y); + // me.do = function () { + // this.seePlayerByLookingAt(); + // this.checkStatus(); + // this.attraction(); + // const dist2 = this.distanceToPlayer2(); + // //laser Tracking + // if (this.seePlayer.yes && dist2 < 4000000) { + // const rangeWidth = 2000; //this is sqrt of 4000000 from above if() + // //targeting laser will slowly move from the mob to the player's position + // this.laserPos = Vector.add(this.laserPos, Vector.mult(Vector.sub(player.position, this.laserPos), 0.1)); + // let targetDist = Vector.magnitude(Vector.sub(this.laserPos, m.pos)); + // const r = 12; + // ctx.beginPath(); + // ctx.moveTo(this.position.x, this.position.y); + // if (targetDist < r + 16) { + // targetDist = r + 10; + // //charge at player + // const forceMag = this.accelMag * 40 * this.mass; + // const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + // this.force.x += forceMag * Math.cos(angle); + // this.force.y += forceMag * Math.sin(angle); + // } + // // else { + // //high friction if can't lock onto player + // // Matter.Body.setVelocity(this, { + // // x: this.velocity.x * 0.98, + // // y: this.velocity.y * 0.98 + // // }); + // // } + // if (dist2 > 80000) { + // const laserWidth = 0.002; + // let laserOffR = Vector.rotateAbout(this.laserPos, (targetDist - r) * laserWidth, this.position); + // let sub = Vector.normalise(Vector.sub(laserOffR, this.position)); + // laserOffR = Vector.add(laserOffR, Vector.mult(sub, rangeWidth)); + // ctx.lineTo(laserOffR.x, laserOffR.y); + + // let laserOffL = Vector.rotateAbout(this.laserPos, (targetDist - r) * -laserWidth, this.position); + // sub = Vector.normalise(Vector.sub(laserOffL, this.position)); + // laserOffL = Vector.add(laserOffL, Vector.mult(sub, rangeWidth)); + // ctx.lineTo(laserOffL.x, laserOffL.y); + // ctx.fillStyle = `rgba(0,0,255,${Math.max(0, 0.3 * r / targetDist)})` + // ctx.fill(); + // } + // } else { + // this.laserPos = this.position; + // } + // } + // }, + flutter(x, y, radius = 20 + 6 * Math.random()) { + mobs.spawn(x, y, 7, radius, '#16576b'); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 0.002); //extra dense //normal is 0.001 //makes effective life much larger + // me.damageReduction = 0.04 + + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.accelMag = 0.0006 + 0.0007 * Math.sqrt(simulation.accelScale); + me.frictionAir = 0.04; + // me.seePlayerFreq = 40 + Math.floor(13 * Math.random()) + me.memory = 240; + me.restitution = 1; + me.frictionStatic = 0; + me.friction = 0; + me.lookTorque = 0.000001 * (Math.random() > 0.5 ? -1 : 1); + me.fireDir = { x: 0, y: 0 } + spawn.shield(me, x, y); + + // me.onDeath = function() {}; + me.flapRate = 0.3 + Math.floor(3 * Math.random()) / 10 + 100 * me.accelMag + me.flapRadius = 75 + radius * 3 + me.do = function () { + this.seePlayerByHistory() + this.checkStatus(); + if (this.seePlayer.recall) { + this.force.x += Math.cos(this.angle) * this.accelMag * this.mass + this.force.y += Math.sin(this.angle) * this.accelMag * this.mass + + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + + //dot product can't tell if mob is facing directly away or directly towards, so check if pointed directly away from player every few cycles + const mod = (a, n) => { + return a - Math.floor(a / n) * n + } + const sub = Vector.sub(m.pos, this.position) //check by comparing different between angles. Give this a nudge if angles are 180 degree different + const diff = mod(Math.atan2(sub.y, sub.x) - this.angle + Math.PI, 2 * Math.PI) - Math.PI + if (Math.abs(diff) > 2.8) this.torque += 0.0002 * this.inertia * Math.random(); + } + + //rotate towards fireDir + const angle = this.angle + Math.PI / 2; + c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + const threshold = 0.4; + const turn = 0.000025 * this.inertia + if (c > threshold) { + this.torque += turn; + } else if (c < -threshold) { + this.torque -= turn; + } + + const flapArc = 0.7 //don't go past 1.57 for normal flaps + ctx.fillStyle = `hsla(${160 + 40 * Math.random()}, 100%, ${25 + 25 * Math.random() * Math.random()}%, 0.2)`; //"rgba(0,235,255,0.3)"; // ctx.fillStyle = `hsla(44, 79%, 31%,0.4)`; //"rgba(0,235,255,0.3)"; + this.wing(this.angle + Math.PI / 2 + flapArc * Math.sin(simulation.cycle * this.flapRate), this.flapRadius) + this.wing(this.angle - Math.PI / 2 - flapArc * Math.sin(simulation.cycle * this.flapRate), this.flapRadius) + } + // else { //flocking behavior (not working yet) + // this.force.x += Math.cos(this.angle) * this.accelMag * this.mass + // this.force.y += Math.sin(this.angle) * this.accelMag * this.mass + // //set direction to turn to fire + // if (!(simulation.cycle % this.seePlayerFreq)) { + // //find nearest mob and maintain a distance + // let nearestMob = null + // let nearestMobDistance = Infinity + // for (let i = 0; i < mob.length; i++) { + // const newMobDistance = Vector.magnitude(Vector.sub(this.position, mob[i].position)) + // if (mob[i].isDropPowerUp && mob[i].alive && newMobDistance < nearestMobDistance) { //&& !mob[i].isBoss + // nearestMobDistance = newMobDistance + // nearestMob = mob[i] + // } + // } + // if (nearestMob) { + // // console.log(nearestMob) + // this.fireDir = Vector.normalise(Vector.sub(nearestMob.position, this.position)); + // //dot product can't tell if mob is facing directly away or directly towards, so check if pointed directly away from player every few cycles + // const mod = (a, n) => { + // return a - Math.floor(a / n) * n + // } + // const sub = Vector.sub(nearestMob.position, this.position) //check by comparing different between angles. Give this a nudge if angles are 180 degree different + // const diff = mod(Math.atan2(sub.y, sub.x) - this.angle + Math.PI, 2 * Math.PI) - Math.PI + // if (Math.abs(diff) > 2.8) this.torque += 0.0002 * this.inertia * Math.random(); + // } + // } + // //rotate towards fireDir + // const angle = this.angle + Math.PI / 2; + // c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + // const threshold = 0.4; + // const turn = 0.000025 * this.inertia + // if (c > threshold) { + // this.torque += turn; + // } else if (c < -threshold) { + // this.torque -= turn; + // } + // const flapArc = 0.7 //don't go past 1.57 for normal flaps + // ctx.fillStyle = `hsla(${160 + 40 * Math.random()}, 100%, ${25 + 25 * Math.random() * Math.random()}%, 0.2)`; //"rgba(0,235,255,0.3)"; // ctx.fillStyle = `hsla(44, 79%, 31%,0.4)`; //"rgba(0,235,255,0.3)"; + // this.wing(this.angle + Math.PI / 2 + flapArc * Math.sin(simulation.cycle * this.flapRate), this.flapRadius) + // this.wing(this.angle - Math.PI / 2 - flapArc * Math.sin(simulation.cycle * this.flapRate), this.flapRadius) + // } + }; + }, + stinger(x, y, radius = 18 + 4 * Math.random()) { + const color = '#5bc' + mobs.spawn(x, y, 7, radius, color); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 0.0025); //extra dense //normal is 0.001 //makes effective life much larger + // me.damageReduction = 0.04 + + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.accelMag = 0.0015 + 0.0007 * Math.sqrt(simulation.accelScale); + me.frictionAir = 0.04; + // me.seePlayerFreq = 40 + Math.floor(13 * Math.random()) + me.memory = 240; + me.restitution = 0.8; + me.frictionStatic = 0; + me.friction = 0; + me.lookTorque = 0.000001 * (Math.random() > 0.5 ? -1 : 1); + me.fireDir = { x: 0, y: 0 } + spawn.shield(me, x, y); + + // me.onDeath = function() {}; + me.flapRate = 0.06 + 0.03 * Math.random() + me.flapRadius = 40 + radius * 3 + me.do = function () { + this.seePlayerByHistory() + this.checkStatus(); + if (this.seePlayer.recall) { + this.force.x += Math.cos(this.angle) * this.accelMag * this.mass + this.force.y += Math.sin(this.angle) * this.accelMag * this.mass + + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + //dot product can't tell if mob is facing directly away or directly towards, so check if pointed directly away from player every few cycles + const mod = (a, n) => a - Math.floor(a / n) * n + const sub = Vector.sub(m.pos, this.position) //check by comparing different between angles. Give this a nudge if angles are 180 degree different + const diff = mod(Math.atan2(sub.y, sub.x) - this.angle + Math.PI, 2 * Math.PI) - Math.PI + if (Math.abs(diff) > 2.8) this.torque += 0.0002 * this.inertia * Math.random(); + } + + //rotate towards fireDir + const angle = this.angle + Math.PI / 2; + c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + const threshold = 0.4; + const turn = 0.00002 * this.inertia + if (c > threshold) { + this.torque += turn; + } else if (c < -threshold) { + this.torque -= turn; + } + + // this.accelMag = 0.0006 + 0.0007 * Math.sqrt(simulation.accelScale); + this.frictionAir = 0.11 + 0.09 * Math.sin(simulation.cycle * this.flapRate - Math.PI / 2) + + const flapArc = 0.8 //don't go past 1.57 for normal flaps + ctx.fillStyle = `hsla(${160 + 40 * Math.random()}, 100%, ${25 + 25 * Math.random() * Math.random()}%, 0.2)`; //"rgba(0,235,255,0.3)"; // ctx.fillStyle = `hsla(44, 79%, 31%,0.4)`; //"rgba(0,235,255,0.3)"; + this.wing(this.angle + 2.1 + flapArc * Math.sin(simulation.cycle * this.flapRate), this.flapRadius) + this.wing(this.angle - 2.1 - flapArc * Math.sin(simulation.cycle * this.flapRate), this.flapRadius) + + const seeRange = 550 + 35 * simulation.difficultyMode; + if (this.distanceToPlayer() < 1000) { + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const seeRangeRandom = seeRange - 200 - 150 * Math.random() + const look = { x: this.position.x + seeRangeRandom * Math.cos(this.angle), y: this.position.y + seeRangeRandom * Math.sin(this.angle) }; + best = vertexCollision(this.position, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + + // hitting player + if ((best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + const dmg = 0.002 * simulation.dmgScale; + m.damage(dmg); + //draw damage + ctx.fillStyle = color; + ctx.beginPath(); + ctx.arc(best.x, best.y, 5 + dmg * 1500, 0, 2 * Math.PI); + ctx.fill(); + } + //draw beam + const vertex = 3 + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); + ctx.moveTo(this.vertices[vertex].x, this.vertices[vertex].y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = color; + ctx.lineWidth = 2; + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + + // ctx.beginPath(); + // ctx.arc(this.vertices[vertex].x, this.vertices[vertex].y, 5, 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + // ctx.fillStyle = color; + // ctx.fill(); + } + // else { + // ctx.beginPath(); + // ctx.arc(this.vertices[1].x, this.vertices[1].y, 1 + 0.3 * (simulation.cycle % this.laserInterval), 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + // ctx.fillStyle = color; + // ctx.fill(); + // } + } + // else { //flocking behavior (not working yet) + // this.force.x += Math.cos(this.angle) * this.accelMag * this.mass + // this.force.y += Math.sin(this.angle) * this.accelMag * this.mass + // //set direction to turn to fire + // if (!(simulation.cycle % this.seePlayerFreq)) { + // //find nearest mob and maintain a distance + // let nearestMob = null + // let nearestMobDistance = Infinity + // for (let i = 0; i < mob.length; i++) { + // const newMobDistance = Vector.magnitude(Vector.sub(this.position, mob[i].position)) + // if (mob[i].isDropPowerUp && mob[i].alive && newMobDistance < nearestMobDistance) { //&& !mob[i].isBoss + // nearestMobDistance = newMobDistance + // nearestMob = mob[i] + // } + // } + // if (nearestMob) { + // // console.log(nearestMob) + // this.fireDir = Vector.normalise(Vector.sub(nearestMob.position, this.position)); + // //dot product can't tell if mob is facing directly away or directly towards, so check if pointed directly away from player every few cycles + // const mod = (a, n) => { + // return a - Math.floor(a / n) * n + // } + // const sub = Vector.sub(nearestMob.position, this.position) //check by comparing different between angles. Give this a nudge if angles are 180 degree different + // const diff = mod(Math.atan2(sub.y, sub.x) - this.angle + Math.PI, 2 * Math.PI) - Math.PI + // if (Math.abs(diff) > 2.8) this.torque += 0.0002 * this.inertia * Math.random(); + // } + // } + // //rotate towards fireDir + // const angle = this.angle + Math.PI / 2; + // c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + // const threshold = 0.4; + // const turn = 0.000025 * this.inertia + // if (c > threshold) { + // this.torque += turn; + // } else if (c < -threshold) { + // this.torque -= turn; + // } + // const flapArc = 0.7 //don't go past 1.57 for normal flaps + // ctx.fillStyle = `hsla(${160 + 40 * Math.random()}, 100%, ${25 + 25 * Math.random() * Math.random()}%, 0.2)`; //"rgba(0,235,255,0.3)"; // ctx.fillStyle = `hsla(44, 79%, 31%,0.4)`; //"rgba(0,235,255,0.3)"; + // this.wing(this.angle + Math.PI / 2 + flapArc * Math.sin(simulation.cycle * this.flapRate), this.flapRadius) + // this.wing(this.angle - Math.PI / 2 - flapArc * Math.sin(simulation.cycle * this.flapRate), this.flapRadius) + // } + }; + }, + beetleBoss(x, y, radius = 50) { + mobs.spawn(x, y, 7, radius, '#16576b'); + let me = mob[mob.length - 1]; + me.isBoss = true; + Matter.Body.setDensity(me, 0.005); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.08 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.nextHealthThreshold = 0.75 + me.invulnerableCount = 0 + + me.flapRate = 0.2 + me.wingSize = 0 + me.wingGoal = 250 + simulation.difficulty + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.accelMag = 0.00045 + 0.0005 * Math.sqrt(simulation.accelScale); + me.frictionAir = 0.05; + me.seePlayerFreq = 13 + me.memory = 420; + me.restitution = 1; + me.frictionStatic = 0; + me.friction = 0; + me.lookTorque = 0.000001 * (Math.random() > 0.5 ? -1 : 1); + me.fireDir = { x: 0, y: 0 } + spawn.shield(me, x, y); + + // len = 0.3 * simulation.difficulty //spawn some baby flutters + // if (len > 3) { + // for (let i = 0; i < len; ++i) { + // const phase = i / len * 2 * Math.PI + // const where = Vector.add(me.position, Vector.mult({ x: Math.cos(phase), y: Math.sin(phase) }, radius * 1.5)) + // spawn.flutter(where.x, where.y) + // } + // } + + // if (Math.random() < 0.3) { + // const len = 0.1 * simulation.difficulty //spawn some baby flutters + // let i = 0 + // let spawnFlutters = () => { + // if (i < len) { + // if (!(simulation.cycle % 30) && !simulation.paused && !simulation.isChoosing) { + // const phase = i / len * 2 * Math.PI + // const where = Vector.add(me.position, Vector.mult({ x: Math.cos(phase), y: Math.sin(phase) }, radius * 1.5)) + // spawn.flutter(where.x, where.y) + // i++ + // } + // requestAnimationFrame(spawnFlutters); + // } + // } + // requestAnimationFrame(spawnFlutters); + // me.isAlreadyHadBabies = true + // } + + me.pushAway = function (magX = 0.13, magY = 0.05) { + for (let i = 0, len = body.length; i < len; ++i) { //push blocks away horizontally + if (Vector.magnitudeSquared(Vector.sub(body[i].position, this.position)) < 4000000) { //2000 + body[i].force.x += magX * body[i].mass * (body[i].position.x > this.position.x ? 1 : -1) + body[i].force.y -= magY * body[i].mass + } + } + for (let i = 0, len = bullet.length; i < len; ++i) { //push blocks away horizontally + if (Vector.magnitudeSquared(Vector.sub(bullet[i].position, this.position)) < 4000000) { //2000 + bullet[i].force.x += magX * bullet[i].mass * (bullet[i].position.x > this.position.x ? 1 : -1) + bullet[i].force.y -= magY * bullet[i].mass + } + } + for (let i = 0, len = powerUp.length; i < len; ++i) { //push blocks away horizontally + if (Vector.magnitudeSquared(Vector.sub(powerUp[i].position, this.position)) < 4000000) { //2000 + powerUp[i].force.x += magX * powerUp[i].mass * (powerUp[i].position.x > this.position.x ? 1 : -1) + powerUp[i].force.y -= magY * powerUp[i].mass + } + } + if (Vector.magnitudeSquared(Vector.sub(player.position, this.position)) < 4000000) { //2000 + player.force.x += magX * player.mass * (player.position.x > this.position.x ? 1 : -1) + player.force.y -= magY * player.mass + } + } + + me.babies = function (len) { + const delay = Math.max(3, Math.floor(15 - len / 2)) + let i = 0 + let spawnFlutters = () => { + if (i < len) { + if (!(simulation.cycle % delay) && !simulation.paused && !simulation.isChoosing && m.alive) { + // const phase = i / len * 2 * Math.PI + // const where = Vector.add(this.position, Vector.mult({ x: Math.cos(phase), y: Math.sin(phase) }, radius * 1.5)) + const unit = Vector.normalise(Vector.sub(player.position, this.position)) + const velocity = Vector.mult(unit, 10 + 10 * Math.random()) + const where = Vector.add(this.position, Vector.mult(unit, radius * 1.2)) + spawn.allowShields = false + spawn.flutter(where.x, where.y, Math.floor(7 + 8 * Math.random())) + const who = mob[mob.length - 1] + Matter.Body.setDensity(who, 0.01); //extra dense //normal is 0.001 //makes effective life much larger + Matter.Body.setVelocity(who, velocity); + Matter.Body.setAngle(who, Math.atan2(velocity.y, velocity.x)) + + this.alertNearByMobs(); + spawn.allowShields = true + i++ + } + requestAnimationFrame(spawnFlutters); + } + } + requestAnimationFrame(spawnFlutters); + } + // me.babies(0.05 * simulation.difficulty + 1) + + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + me.babies(0.05 * simulation.difficulty + 1) + }; + me.onDamage = function () { + if (this.health < this.nextHealthThreshold && this.alive) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 + this.invulnerableCount = 90 + Math.floor(30 * Math.random()) + this.isInvulnerable = true + this.damageReduction = 0 + this.frictionAir = 0 + this.wingGoal = 0 + this.wingSize = 0 + this.flapRate += 0.13 + this.accelMag *= 1.4 + } + }; + me.do = function () { + this.seePlayerByHistory(50) + this.checkStatus(); + if (this.isInvulnerable) { + this.invulnerableCount-- + if (this.invulnerableCount < 0) { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + this.frictionAir = 0.05 + this.wingGoal = 250 + this.pushAway(Math.sqrt(this.flapRate) * 0.13, Math.sqrt(this.flapRate) * 0.06) //this.flapRate = 0.2, +0.13x3 -> 0.6 + me.babies(0.05 * simulation.difficulty + 1) + } + //draw invulnerable + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } else if (this.seePlayer.recall) { + // const force = Vector.mult(Vector.normalise(Vector.sub(this.seePlayer.position, this.position)), this.accelMag * this.mass) + // const force = Vector.mult({ x: Math.cos(this.angle), y: Math.sin(this.angle) }, this.accelMag * this.mass) + // this.force.x += force.x; + // this.force.y += force.y; + this.force.x += Math.cos(this.angle) * this.accelMag * this.mass + this.force.y += Math.sin(this.angle) * this.accelMag * this.mass + + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + + //dot product can't tell if mob is facing directly away or directly towards, so check if pointed directly away from player every few cycles + //check by comparing different between angles. Give this a nudge if angles are 180 degree different + const mod = (a, n) => { + return a - Math.floor(a / n) * n + } + const sub = Vector.sub(m.pos, this.position) + const diff = mod(Math.atan2(sub.y, sub.x) - this.angle + Math.PI, 2 * Math.PI) - Math.PI + if (Math.abs(diff) > 2.8) this.torque += 0.0002 * this.inertia * Math.random(); + } + + //rotate towards fireDir + const angle = this.angle + Math.PI / 2; + c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + const threshold = 0.4; + const turn = 0.00003 * this.inertia + if (c > threshold) { + this.torque += turn; + } else if (c < -threshold) { + this.torque -= turn; + } + const flapArc = 0.7 //don't go past 1.57 for normal flaps + this.wingSize = 0.97 * this.wingSize + 0.03 * this.wingGoal + ctx.fillStyle = this.fill = `hsla(${160 + 40 * Math.random()}, 100%, ${25 + 25 * Math.random() * Math.random()}%, 0.9)`; //"rgba(0,235,255,0.3)"; // ctx.fillStyle = `hsla(44, 79%, 31%,0.4)`; //"rgba(0,235,255,0.3)"; + this.wing(this.angle + Math.PI / 2 + flapArc * Math.sin(simulation.cycle * this.flapRate), this.wingSize, 0.5, 0.0012) + this.wing(this.angle - Math.PI / 2 - flapArc * Math.sin(simulation.cycle * this.flapRate), this.wingSize, 0.5, 0.0012) + } else { + this.wingSize = 0.96 * this.wingSize + 0 //shrink while stunned + } + }; + }, + laserTargetingBoss(x, y, radius = 80) { + const color = "#07f" + mobs.spawn(x, y, 3, radius, color); + let me = mob[mob.length - 1]; + me.isBoss = true; + Matter.Body.setDensity(me, 0.004); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.12 + + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.accelMag = 0.00018 * Math.sqrt(simulation.accelScale); + me.seePlayerFreq = 30 + me.memory = 420; + me.restitution = 1; + me.frictionAir = 0.01; + me.frictionStatic = 0; + me.friction = 0; + me.lookTorque = 0.000001 * (Math.random() > 0.5 ? -1 : 1); + me.fireDir = { x: 0, y: 0 } + spawn.shield(me, x, y, 1); + // spawn.spawnOrbitals(me, radius + 50 + 100 * Math.random()) + for (let i = 0, len = 2 + 0.3 * Math.sqrt(simulation.difficulty); i < len; i++) spawn.spawnOrbitals(me, radius + 40 + 10 * i, 1); + // me.onHit = function() { }; + // spawn.shield(me, x, y, 1); //not working, not sure why + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.laserInterval = 100 + me.do = function () { + // this.armor(); + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + + if (this.seePlayer.recall) { + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + + //rotate towards fireAngle + const angle = this.angle + Math.PI / 2; + c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + const threshold = 0.4; + if (c > threshold) { + this.torque += 0.000004 * this.inertia; + } else if (c < -threshold) { + this.torque -= 0.000004 * this.inertia; + } + if (simulation.cycle % this.laserInterval > this.laserInterval / 2) { + const seeRange = 8000; + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { x: this.position.x + seeRange * Math.cos(this.angle), y: this.position.y + seeRange * Math.sin(this.angle) }; + best = vertexCollision(this.position, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + + // hitting player + if ((best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + const dmg = 0.006 * simulation.dmgScale; + m.damage(dmg); + //draw damage + ctx.fillStyle = color; + ctx.beginPath(); + ctx.arc(best.x, best.y, dmg * 1500, 0, 2 * Math.PI); + ctx.fill(); + } + //draw beam + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); + ctx.moveTo(this.vertices[1].x, this.vertices[1].y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = color; + ctx.lineWidth = 3; + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + + ctx.beginPath(); + ctx.arc(this.vertices[1].x, this.vertices[1].y, 1 + 0.3 * (this.laserInterval - simulation.cycle % this.laserInterval), 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = color; + ctx.fill(); + } else { + ctx.beginPath(); + ctx.arc(this.vertices[1].x, this.vertices[1].y, 1 + 0.3 * (simulation.cycle % this.laserInterval), 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = color; + ctx.fill(); + } + } + }; + }, + laserBombingBoss(x, y, radius = 80) { + mobs.spawn(x, y, 3, radius, "rgb(0,235,255)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + me.damageReduction = 0.27 + + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.accelMag = 0.00055 * Math.sqrt(simulation.accelScale); + me.seePlayerFreq = 30; + me.memory = 420; + me.restitution = 1; + me.frictionAir = 0.05; + me.frictionStatic = 0; + me.friction = 0; + me.lookTorque = 0.0000055 * (Math.random() > 0.5 ? -1 : 1) * (1 + 0.1 * Math.sqrt(simulation.difficulty)) + me.fireDir = { x: 0, y: 0 } + Matter.Body.setDensity(me, 0.01); //extra dense //normal is 0.001 //makes effective life much larger + spawn.shield(me, x, y, 1); + spawn.spawnOrbitals(me, radius + 200 + 300 * Math.random()) + me.onHit = function () { }; + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.targetingCount = 0; + me.targetingTime = 60 - Math.min(58, 3 * simulation.difficulty) + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + + if (this.seePlayer.recall) { + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + + //rotate towards fireAngle + const angle = this.angle + Math.PI / 2; + c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + const threshold = 0.02; + if (c > threshold) { + this.torque += 0.000004 * this.inertia; + } else if (c < -threshold) { + this.torque -= 0.000004 * this.inertia; + } + + const seeRange = 8000; + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { x: this.position.x + seeRange * Math.cos(this.angle), y: this.position.y + seeRange * Math.sin(this.angle) }; + best = vertexCollision(this.position, look, m.isCloak ? [map] : [map, [playerBody, playerHead]]); + + // hitting player + if (best.who === playerBody || best.who === playerHead) { + this.targetingCount++ + if (this.targetingCount > this.targetingTime) { + this.targetingCount -= 10; + const sub = Vector.sub(player.position, this.position) + const dist = Vector.magnitude(sub) + const speed = Math.min(55, 5 + 20 * simulation.accelScale) + const velocity = Vector.mult(Vector.normalise(sub), speed) + spawn.grenade(this.vertices[1].x, this.vertices[1].y, dist / speed, Math.min(550, 250 + simulation.difficulty * 3), 6); // grenade(x, y, lifeSpan = 90 + Math.ceil(60 / simulation.accelScale), pulseRadius = Math.min(550, 250 + simulation.difficulty * 3), size = 4) { + Matter.Body.setVelocity(mob[mob.length - 1], velocity); + } + } else if (this.targetingCount > 0) { + this.targetingCount-- + } + //draw beam + if (best.dist2 === Infinity) best = look; + // ctx.beginPath(); + // ctx.moveTo(this.vertices[1].x, this.vertices[1].y); + // ctx.lineTo(best.x, best.y); + // ctx.strokeStyle = "rgba(0,235,255,0.5)"; + // ctx.lineWidth = 3// + 0.1 * this.targetingCount; + // ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + // ctx.stroke(); + // ctx.setLineDash([]); + ctx.beginPath(); + ctx.moveTo(this.vertices[1].x, this.vertices[1].y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(0,235,255,1)"; + ctx.lineWidth = 3 + ctx.stroke(); + if (this.targetingCount / this.targetingTime > 0.33) { + ctx.strokeStyle = "rgba(0,235,255,0.45)"; + ctx.lineWidth = 10 + ctx.stroke(); + if (this.targetingCount / this.targetingTime > 0.66) { + ctx.strokeStyle = "rgba(0,235,255,0.25)"; + ctx.lineWidth = 30 + ctx.stroke(); + } + } + + // ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + // ctx.setLineDash([]); + } + }; + }, + blinkBoss(x, y) { + mobs.spawn(x, y, 5, 50, "rgb(0,235,255)"); //"rgb(221,102,119)" + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, Math.PI * 0.1); + Matter.Body.setDensity(me, 0.002); //extra dense //normal is 0.001 //makes effective life much larger + me.isBoss = true; + me.damageReduction = 0.038 + + me.frictionStatic = 0; + me.friction = 0; + me.memory = 240 + me.seePlayerFreq = 55 + me.blinkRange = 250 + if (0.5 < Math.random()) { + me.grenadeDelay = 260 + me.blinkRange *= 1.5 + } else { + me.grenadeDelay = 100 + } + me.pulseRadius = 1.5 * Math.min(550, 200 + simulation.difficulty * 2) + me.delay = 55 + 35 * simulation.CDScale; + me.nextBlinkCycle = me.delay; + spawn.shield(me, x, y, 1); + me.onDamage = function () { + // this.cd = simulation.cycle + this.delay; + }; + me.onDeath = function () { + const offAngle = Math.PI * Math.random() + for (let i = 0, len = 3; i < len; i++) { + spawn.grenade(this.position.x, this.position.y, this.grenadeDelay); + const who = mob[mob.length - 1] + const speed = 5 * simulation.accelScale; + const angle = 2 * Math.PI * i / len + offAngle + Matter.Body.setVelocity(who, { + x: speed * Math.cos(angle), + y: speed * Math.sin(angle) + }); + } + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + } + me.do = function () { + this.seePlayerByHistory(40) + if (this.nextBlinkCycle < simulation.cycle && this.seePlayer.yes) { //teleport towards the player + this.nextBlinkCycle = simulation.cycle + this.delay; + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + if (distMag < this.blinkRange) { //if player is inside teleport range + Matter.Body.setPosition(this, this.seePlayer.position); + } else { + Matter.Body.translate(this, Vector.mult(Vector.normalise(dist), this.blinkRange)); + } + spawn.grenade(this.position.x, this.position.y, this.grenadeDelay, this.pulseRadius); //spawn at new location + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = this.radius * 2.1; + ctx.strokeStyle = this.fill; //"rgba(0,0,0,0.5)"; //'#000' + ctx.stroke(); + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + this.torque += (0.00004 + 0.00003 * Math.random()) * this.inertia * (Math.round(Math.random()) * 2 - 1) //randomly spin around after firing + } + this.checkStatus(); + }; + }, + snakeBoss(x, y) { + mobs.spawn(x, y, 0, 25, `rgba(255,0,200)`); //"rgb(221,102,119)" + let me = mob[mob.length - 1]; + me.stroke = "transparent"; //used for drawGhost + me.isUnblockable = true; + Matter.Body.setDensity(me, 0.033); //extra dense //normal is 0.001 //makes effective life much larger + me.isBoss = true; + me.damageReduction = 0.5 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.nextHealthThreshold = 0.75 + me.invulnerableCount = 0 + me.history = [] + for (let i = 0; i < 20; i++) { + me.history.push({ x: me.position.x + i, y: me.position.y }) + } + me.frictionStatic = 0; + me.friction = 0; + me.memory = 240 + me.seePlayerFreq = 55 + me.delay = 5 + 2 * simulation.CDScale;//8 + 3 * simulation.CDScale; + me.nextBlinkCycle = me.delay; + me.JumpDistance = 0//set in redMode() + // spawn.shield(me, x, y, 1); + me.collisionFilter.mask = cat.bullet | cat.map //| cat.body //cat.player | + me.powerUpNames = [] + me.redMode = function () { + this.color = `rgba(255,0,200,` + this.fill = this.color + '1)' + this.JumpDistance = 20 + let cycle = () => { + if (this.radius < 25) { + if (m.alive && this.JumpDistance === 20) requestAnimationFrame(cycle); + if (!simulation.paused && !simulation.isChoosing) { + const scale = 1.01; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + } + } + } + requestAnimationFrame(cycle); + } + me.redMode(); + me.blueMode = function () { + this.color = `rgba(0,0,255,`//`rgba(255,0,200,` + this.fill = this.color + '1)' + this.JumpDistance = 37 //adjust this number in the IF below + let cycle = () => { + if (this.radius > 14) { + if (m.alive && this.JumpDistance === 37) requestAnimationFrame(cycle); + if (!simulation.paused && !simulation.isChoosing) { + const scale = 0.96; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + } + } + } + requestAnimationFrame(cycle); + } + me.onDamage = function () { + if (this.health < this.nextHealthThreshold) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 //0.75,0.5,0.25 + this.invulnerableCount = 240 + this.isInvulnerable = true + this.damageReduction = 0 + if (this.history.length < 200) for (let i = 0; i < 11; i++) this.history.unshift(this.history[0]) + this.blueMode() + } + }; + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + + //respawn all eaten power ups + let i = 0 + let cycle = () => { + if (i < this.powerUpNames.length) { + if (m.alive) requestAnimationFrame(cycle); + if (!simulation.paused && !simulation.isChoosing && powerUp.length < 300) { + const index = Math.floor(Math.random() * this.history.length) //random segment of tail + const where = { x: this.history[index].x + 25 * (Math.random() - 0.5), y: this.history[index].y + 25 * (Math.random() - 0.5) } + powerUps.spawn(where.x, where.y, this.powerUpNames[i]); + i++ + } + } + } + requestAnimationFrame(cycle); + } + me.do = function () { + const color = this.color + (0.35 + 0.25 * Math.random()) + ')' + //check for player collisions in between each segment + if (m.immuneCycle < m.cycle) { + for (let i = 0; i < this.history.length - 1; i++) { + if (Matter.Query.ray([player], this.history[i], this.history[i + 1], 10).length > 0) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60 + const dmg = 0.15 * simulation.dmgScale + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: m.pos.x, + y: m.pos.y, + radius: dmg * 1500,//30, + color: color, + time: 20 + }); + + //reset tail length for a sec to prevent repeat damage + for (let i = 0, len = this.history.length; i < len; i++) { + this.history[i] = { x: this.position.x, y: this.position.y } + } + break + } + } + } + + if (this.nextBlinkCycle < simulation.cycle) { //teleport towards the player + this.nextBlinkCycle = simulation.cycle + this.delay; + if (this.isSlowed) this.nextBlinkCycle += this.delay + if (this.isStunned) this.nextBlinkCycle += this.delay * 3 + + //custom see player by history code + let move = (target = this.seePlayer.position) => { + const dist = Vector.sub(target, this.position); + + Matter.Body.translate(this, Vector.mult(Vector.normalise(dist), this.JumpDistance)); + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + // Matter.Body.setAngle(this, 0); + Matter.Body.setAngularVelocity(this, 0) + //track previous locations for the tail + this.history.push({ x: this.position.x, y: this.position.y }) //add newest to end + this.history.shift() //remove first (oldest) + } + //look for close power ups in line of sight + let close = { + dist: Infinity, + targetPos: null, + index: null, + } + for (let i = 0; i < powerUp.length; i++) { + if (Matter.Query.ray(map, this.position, powerUp[i].position).length === 0) { + const dist = Vector.magnitude(Vector.sub(this.position, powerUp[i].position)) + if (dist < close.dist) { + close = { + dist: dist, + target: powerUp[i], + index: i, + } + } + } + } + if (close.dist < 3000) { //chase power ups if they are near + move(close.target.position) + + //check if close to power up and eat it + if (close.dist < this.JumpDistance + 2 * this.radius) { + this.powerUpNames.push(close.target.name) //save name to return power ups after this mob dies + Matter.Composite.remove(engine.world, close.target); + powerUp.splice(close.index, 1); + this.health = 1 //heal to full + //add more segments to tail + if (this.history.length < 200) for (let i = 0; i < 4; i++) this.history.unshift(this.history[0]) + //draw pickup for a single cycle + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + ctx.lineTo(close.target.position.x, close.target.position.y); + ctx.strokeStyle = "#000" + ctx.lineWidth = 4 + ctx.stroke(); + } + + //go eat blocks to heal? + // } else if (this.health < 0.6) { + + } else if (Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && !m.isCloak) { //chase player + this.seePlayer.yes = true; + this.locatePlayer(); + if (!this.seePlayer.yes) this.seePlayer.yes = true; + move() + } else if (this.seePlayer.recall) { //chase player's history + this.lostPlayer(); + if (!m.isCloak) { + for (let i = 0; i < 50; i++) { //if lost player lock onto a player location in history + let history = m.history[(m.cycle - 10 * i) % 600] + if (Matter.Query.ray(map, this.position, history.position).length === 0) { + this.seePlayer.recall = this.memory + Math.round(this.memory * Math.random()); //cycles before mob falls a sleep + this.seePlayer.position.x = history.position.x; + this.seePlayer.position.y = history.position.y; + this.seePlayer.yes = true; + move() + break + } + } + } + } + + } + this.checkStatus(); + if (this.isInvulnerable) { + this.invulnerableCount-- + if (this.invulnerableCount < 0) { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + this.redMode() + } + //draw invulnerable + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + //draw history + ctx.beginPath(); + for (let i = 0, len = this.history.length; i < len; i++) { + ctx.lineTo(this.history[i].x, this.history[i].y) + } + ctx.lineWidth = this.radius * 2; + ctx.strokeStyle = color //"rgba(0,235,255,0.5)"; + ctx.stroke(); + }; + }, + pulsarBoss(x, y, radius = 90, isNonCollide = false) { + mobs.spawn(x, y, 3, radius, "#a0f"); + let me = mob[mob.length - 1]; + if (isNonCollide) me.collisionFilter.mask = cat.bullet | cat.player + setTimeout(() => { //fix mob in place, but allow rotation + me.constraint = Constraint.create({ + pointA: { + x: me.position.x, + y: me.position.y + }, + bodyB: me, + stiffness: 0.0001, + damping: 0.3 + }); + Composite.add(engine.world, me.constraint); + }, 2000); //add in a delay in case the level gets flipped left right + + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.radius *= 1.5 + me.vertices[1].x = me.position.x + Math.cos(me.angle) * me.radius; //make one end of the triangle longer + me.vertices[1].y = me.position.y + Math.sin(me.angle) * me.radius; + // me.homePosition = { x: x, y: y }; + me.fireCycle = 0 + me.fireTarget = { x: 0, y: 0 } + me.pulseRadius = Math.min(500, 230 + simulation.difficulty * 3) + me.fireDelay = Math.max(60, 150 - simulation.difficulty * 2) + me.isFiring = false + Matter.Body.setDensity(me, 0.01); //extra dense //normal is 0.001 //makes effective life much larger + me.isBoss = true; + + spawn.shield(me, x, y, 1); + spawn.spawnOrbitals(me, radius + 200 + 300 * Math.random(), 1) + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.onHit = function () { }; + me.do = function () { + if (player.speed > 5) this.do = this.fire //don't attack until player moves + } + me.damageReduction = 0.29 + me.fire = function () { + // this.armor(); + this.checkStatus(); + if (!m.isCloak && !this.isStunned) { + if (this.isFiring) { + if (this.fireCycle > this.fireDelay) { //fire + this.isFiring = false + this.fireCycle = 0 + this.torque += (0.00008 + 0.00007 * Math.random()) * this.inertia * (Math.round(Math.random()) * 2 - 1) //randomly spin around after firing + //is player in beam path + if (Matter.Query.ray([player], this.fireTarget, this.position).length) { + unit = Vector.mult(Vector.normalise(Vector.sub(this.vertices[1], this.position)), this.distanceToPlayer() - 100) + this.fireTarget = Vector.add(this.vertices[1], unit) + } + //damage player if in range + if (Vector.magnitude(Vector.sub(player.position, this.fireTarget)) < this.pulseRadius && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage + m.damage(0.045 * simulation.dmgScale); + } + simulation.drawList.push({ //add dmg to draw queue + x: this.fireTarget.x, + y: this.fireTarget.y, + radius: this.pulseRadius, + color: "rgba(120,0,255,0.6)", + time: simulation.drawTime + }); + ctx.beginPath(); + ctx.moveTo(this.vertices[1].x, this.vertices[1].y) + ctx.lineTo(this.fireTarget.x, this.fireTarget.y) + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(120,0,255,0.3)"; + ctx.stroke(); + ctx.lineWidth = 5; + ctx.strokeStyle = "rgba(120,0,255,1)"; + ctx.stroke(); + } else { //delay before firing + this.fireCycle++ + //draw explosion outline + ctx.beginPath(); + ctx.arc(this.fireTarget.x, this.fireTarget.y, this.pulseRadius, 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = "rgba(120,0,255,0.07)"; + ctx.fill(); + //draw path from mob to explosion + ctx.beginPath(); + ctx.moveTo(this.vertices[1].x, this.vertices[1].y) + ctx.lineTo(this.fireTarget.x, this.fireTarget.y) + ctx.setLineDash([40 * Math.random(), 200 * Math.random()]); + ctx.lineWidth = 2; + ctx.strokeStyle = "rgba(120,0,255,0.3)"; + ctx.stroke(); + ctx.setLineDash([]); + } + } else { //aim at player + this.fireCycle++ + this.fireDir = Vector.normalise(Vector.sub(m.pos, this.position)); //set direction to turn to fire + //rotate towards fireAngle + const angle = this.angle + Math.PI / 2; + const c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + const threshold = 0.04; + if (c > threshold) { + this.torque += 0.0000015 * this.inertia; + } else if (c < -threshold) { + this.torque -= 0.0000015 * this.inertia; + } else if (this.fireCycle > 45) { //fire + unit = Vector.mult(Vector.normalise(Vector.sub(this.vertices[1], this.position)), this.distanceToPlayer() - 100) + this.fireTarget = Vector.add(this.vertices[1], unit) + if (Vector.magnitude(Vector.sub(m.pos, this.fireTarget)) < 1000) { //if's possible for this to be facing 180 degrees away from the player, this makes sure that doesn't occur + Matter.Body.setAngularVelocity(this, 0) + this.fireLockCount = 0 + this.isFiring = true + this.fireCycle = 0 + } + } + } + //gently return to starting location + // const sub = Vector.sub(this.homePosition, this.position) + // const dist = Vector.magnitude(sub) + // if (dist > 250) this.force = Vector.mult(Vector.normalise(sub), this.mass * 0.0002) + } else { + this.isFiring = false + } + }; + }, + pulsar(x, y, radius = 40) { + mobs.spawn(x, y, 3, radius, "#f08"); + let me = mob[mob.length - 1]; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.radius *= 2 + // me.frictionAir = 0.02 + + me.vertices[1].x = me.position.x + Math.cos(me.angle) * me.radius; //make one end of the triangle longer + me.vertices[1].y = me.position.y + Math.sin(me.angle) * me.radius; + // me.homePosition = { x: x, y: y }; + Matter.Body.setDensity(me, 0.002); //extra dense //normal is 0.001 //makes effective life much larger + me.fireCycle = Infinity + me.fireTarget = { x: 0, y: 0 } + me.pulseRadius = Math.min(400, 170 + simulation.difficulty * 3) + me.fireDelay = Math.max(75, 140 - simulation.difficulty * 0.5) + me.isFiring = false + spawn.shield(me, x, y); + me.onHit = function () { }; + me.canSeeTarget = function () { + const angle = this.angle + Math.PI / 2; + const dot = Vector.dot({ + x: Math.cos(angle), + y: Math.sin(angle) + }, Vector.normalise(Vector.sub(this.fireTarget, this.position))); + //distance between the target and the player's location + if ( + m.isCloak || + dot > 0.03 || // not looking at target + Matter.Query.ray(map, this.fireTarget, this.position).length || Matter.Query.ray(body, this.fireTarget, this.position).length || //something blocking line of sight + Vector.magnitude(Vector.sub(m.pos, this.fireTarget)) > 1000 // distance from player to target is very far, (this is because dot product can't tell if facing 180 degrees away) + ) { + this.isFiring = false + return false + } else { + return true + } + } + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + if (this.seePlayer.recall) { + if (this.isFiring) { + if (this.fireCycle > this.fireDelay) { //fire + if (!this.canSeeTarget()) return + this.isFiring = false + this.fireCycle = 0 + this.torque += (0.00002 + 0.0002 * Math.random()) * this.inertia * (Math.round(Math.random()) * 2 - 1) //randomly spin around after firing + //is player in beam path + if (Matter.Query.ray([player], this.fireTarget, this.position).length) { + unit = Vector.mult(Vector.normalise(Vector.sub(this.vertices[1], this.position)), this.distanceToPlayer() - 100) + this.fireTarget = Vector.add(this.vertices[1], unit) + } + //damage player if in range + if (Vector.magnitude(Vector.sub(player.position, this.fireTarget)) < this.pulseRadius && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage + m.damage(0.03 * simulation.dmgScale); + } + simulation.drawList.push({ //add dmg to draw queue + x: this.fireTarget.x, + y: this.fireTarget.y, + radius: this.pulseRadius, + color: "rgba(255,0,100,0.6)", + time: simulation.drawTime + }); + ctx.beginPath(); + ctx.moveTo(this.vertices[1].x, this.vertices[1].y) + ctx.lineTo(this.fireTarget.x, this.fireTarget.y) + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(255,0,100,0.3)"; + ctx.stroke(); + ctx.lineWidth = 5; + ctx.strokeStyle = "rgba(255,0,100,1)"; + ctx.stroke(); + } else { //delay before firing + this.fireCycle++ + if (!(simulation.cycle % 3)) { + if (!this.canSeeTarget()) return //if can't see stop firing + } + //draw explosion outline + ctx.beginPath(); + ctx.arc(this.fireTarget.x, this.fireTarget.y, this.pulseRadius, 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = "rgba(255,0,100,0.07)"; + ctx.fill(); + //draw path from mob to explosion + ctx.beginPath(); + ctx.moveTo(this.vertices[1].x, this.vertices[1].y) + ctx.lineTo(this.fireTarget.x, this.fireTarget.y) + ctx.setLineDash([40 * Math.random(), 200 * Math.random()]); + ctx.lineWidth = 2; + ctx.strokeStyle = "rgba(255,0,100,0.3)"; + ctx.stroke(); + ctx.setLineDash([]); + } + } else { //aim at player + this.fireCycle++ + // this.fireDir = ; //set direction to turn to fire + const angle = this.angle + Math.PI / 2; + const dot = Vector.dot({ + x: Math.cos(angle), + y: Math.sin(angle) + }, Vector.normalise(Vector.sub(this.seePlayer.position, this.position))) + const threshold = 0.04; + if (dot > threshold) { //rotate towards fireAngle + this.torque += 0.0000015 * this.inertia; + } else if (dot < -threshold) { + this.torque -= 0.0000015 * this.inertia; + } else if (this.fireCycle > 60) { // aim + unit = Vector.mult(Vector.normalise(Vector.sub(this.vertices[1], this.position)), this.distanceToPlayer() - 100) + this.fireTarget = Vector.add(this.vertices[1], unit) + if (!this.canSeeTarget()) return + Matter.Body.setAngularVelocity(this, 0) + this.fireLockCount = 0 + this.isFiring = true + this.fireCycle = 0 + } + } + //gently return to starting location + // const sub = Vector.sub(this.homePosition, this.position) + // const dist = Vector.magnitude(sub) + // if (dist > 350) this.force = Vector.mult(Vector.normalise(sub), this.mass * 0.0002) + } else { + this.isFiring = false + } + }; + }, + laserLayer(x, y, radius = 18 + Math.floor(6 * Math.random())) { + const color = "#f09" + mobs.spawn(x, y, 4, radius, color); + let me = mob[mob.length - 1]; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + for (let i = 0; i < 4; i += 2) { + let spike = Vector.mult(Vector.normalise(Vector.sub(me.vertices[i], me.position)), radius * 2) + me.vertices[i].x = me.position.x + spike.x + me.vertices[i].y = me.position.y + spike.y + } + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.accelMag = 0.0002 * simulation.accelScale; + spawn.shield(me, x, y); + + me.laserArray = [] //keeps track of static laser beams + me.laserLimit = simulation.difficultyMode < 3 ? 1 : 2 + me.fireDelay = Math.max(75, 140 - simulation.difficulty * 0.5) + me.cycle = 0 + me.laserDelay = 150 + Math.floor(Math.random() * 120) + me.addLaser = function () { + if (this.cycle > this.laserDelay) { + this.cycle = 0 + const seeRange = 6000; + const angle = this.angle + Math.PI / 4 + const v1 = { x: this.position.x + seeRange * Math.cos(angle), y: this.position.y + seeRange * Math.sin(angle) }; + const v2 = { x: this.position.x + seeRange * Math.cos(angle + Math.PI), y: this.position.y + seeRange * Math.sin(angle + Math.PI) }; + //find where v1,v2 hit walls and make them stop there + let best1 = vertexCollision(this.position, v1, [map]); + let best2 = vertexCollision(this.position, v2, [map]); + if (best2.who === null) { + best2.x = v2.x + best2.y = v2.y + } + if (best1.who === null) { //if the path never hits the map , just stop at seeRange + best1.x = v1.x + best1.y = v1.y + } + if (best1.y > best2.y) { //make laser beams always fire from top to bottom so they are predicable, and not stopped by blocks on the ground + const save1X = best1.x + const save1Y = best1.y + best1.x = best2.x + best1.y = best2.y + best2.x = save1X + best2.y = save1Y + } + + this.laserArray.push({ a: { x: best1.x, y: best1.y }, b: { x: best2.x, y: best2.y }, fade: 0 }) + //friction to animate the mob dropping something + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.05)); + Matter.Body.setAngularVelocity(this, this.angularVelocity * 0.05) + // simulation.drawList.push({ x: best1.x, y: best1.y, radius: 10, color: "rgba(255,0,100,0.3)", time: simulation.drawTime * 2 }); + // simulation.drawList.push({ x: best2.x, y: best2.y, radius: 10, color: "rgba(255,0,100,0.3)", time: simulation.drawTime * 2 }); + + if (this.laserArray.length > this.laserLimit) this.laserArray.shift() //cap total laserArray + if (!this.seePlayer.recall && (Vector.magnitude(Vector.sub(this.position, this.driftGoal)) < 200 || 0.3 > Math.random())) { + //used in drift when can't find player + const radius = Math.random() * 1000; + const angle = Math.random() * 2 * Math.PI; + this.driftGoal = Vector.add(this.driftCenter, { x: radius * Math.cos(angle), y: radius * Math.sin(angle) }) + } + } + } + me.fireLaser = function () { + for (let i = 0; i < this.laserArray.length; i++) { //fire all lasers in the array + let best = vertexCollision(this.laserArray[i].a, this.laserArray[i].b, m.isCloak ? [body] : [body, [playerBody, playerHead]]); //not checking map to fix not hitting player bug, this might make some lasers look strange when the map changes + if (this.laserArray[i].fade > 0.99) { + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { // hitting player + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage after getting hit + const dmg = 0.03 * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(255,0,100,0.5)", + time: 20 + }); + this.laserArray.splice(i, 1) //remove this laser node + if (this.distanceToPlayer < 1000) { //mob jumps away from player + const forceMag = 0.03 * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x -= 2 * forceMag * Math.cos(angle); + this.force.y -= 2 * forceMag * Math.sin(angle); // - 0.0007 * this.mass; //antigravity + } + } else if (best.who && best.who.classType === "body") { //hitting block + ctx.beginPath(); + ctx.moveTo(best.x, best.y); + ctx.lineTo(this.laserArray[i].a.x, this.laserArray[i].a.y); + ctx.strokeStyle = `rgb(255,0,100)`; + ctx.lineWidth = 2; + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + } else { //hitting nothing + ctx.beginPath(); + ctx.moveTo(this.laserArray[i].b.x, this.laserArray[i].b.y); + ctx.lineTo(this.laserArray[i].a.x, this.laserArray[i].a.y); + ctx.strokeStyle = `rgb(255,0,100)`; + ctx.lineWidth = 2; + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + } + } else {//fade in warning + this.laserArray[i].fade += 0.01 + ctx.beginPath(); + ctx.moveTo(this.laserArray[i].a.x, this.laserArray[i].a.y); + ctx.lineTo(this.laserArray[i].b.x, this.laserArray[i].b.y); + ctx.lineWidth = 2 + 40 - 40 * this.laserArray[i].fade; + ctx.strokeStyle = `rgba(255,0,100,${0.02 + 0.1 * this.laserArray[i].fade})`; + ctx.stroke(); + } + } + } + me.driftCenter = { ...me.position }; //copy position with out reference so it doesn't change as mob moves + const r = Math.random() * 100; + const a = Math.random() * 2 * Math.PI; + me.driftGoal = Vector.add(me.driftCenter, { x: r * Math.cos(a), y: r * Math.sin(a) }) //updated in addLaser() + me.drift = function () { + //accelerate towards the player + if (this.seePlayer.recall) { + const force = Vector.mult(Vector.normalise(Vector.sub(this.seePlayer.position, this.position)), this.accelMag * this.mass) + this.force.x += force.x; + this.force.y += force.y; + } else { //drift + const force = Vector.mult(Vector.normalise(Vector.sub(this.driftGoal, this.position)), 0.00002 * this.mass) + // const force = Vector.mult(this.driftGoal, 0.0001 * this.mass) + this.force.x += force.x; + this.force.y += force.y; + } + } + me.do = function () { + this.cycle++ + this.torque = this.lookTorque * this.inertia * 0.6; + this.seePlayerCheck(); + this.checkStatus(); + this.drift(); + //add new laser to lasers array + this.addLaser() + this.fireLaser() + // if (this.seePlayer.recall) { + // //set direction to turn to fire + // if (!(simulation.cycle % this.seePlayerFreq)) this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + // } + }; + }, + laserLayerBoss(x, y, radius = 65) { + const color = "#f09" + mobs.spawn(x, y, 4, radius, color); + let me = mob[mob.length - 1]; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + for (let i = 0; i < 4; i += 2) { + let spike = Vector.mult(Vector.normalise(Vector.sub(me.vertices[i], me.position)), radius * 2) + me.vertices[i].x = me.position.x + spike.x + me.vertices[i].y = me.position.y + spike.y + } + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.accelMag = 0.0001 * simulation.accelScale; + me.isBoss = true; + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + Matter.Body.setDensity(me, 0.03); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.36 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.nextHealthThreshold = 0.75 + me.invulnerableCount = 0 + me.onDamage = function () { + if (this.health < this.nextHealthThreshold) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 //0.75,0.5,0.25 + this.invulnerableCount = 90 + this.isInvulnerable = true + this.damageReduction = 0 + this.laserDelay = 130 + } + }; + me.laserArray = [] //keeps track of static laser beams + me.laserLimit = 2 + (simulation.difficultyMode > 2) + (simulation.difficultyMode > 4) + me.fireDelay = Math.max(75, 140 - simulation.difficulty * 0.5) + me.cycle = 0 + me.laserDelay = 210 + me.addLaser = function () { + if (this.cycle > this.laserDelay) { + this.cycle = 0 + const seeRange = 6000; + let add = (where, angle) => { + const v1 = { x: where.x + seeRange * Math.cos(angle), y: where.y + seeRange * Math.sin(angle) }; + const v2 = { x: where.x + seeRange * Math.cos(angle + Math.PI), y: where.y + seeRange * Math.sin(angle + Math.PI) }; + //find where v1,v2 hit walls and make them stop there + let best1 = vertexCollision(where, v1, [map]); + let best2 = vertexCollision(where, v2, [map]); + if (best2.who === null) { + best2.x = v2.x + best2.y = v2.y + } + if (best1.who === null) { //if the path never hits the map , just stop at seeRange + best1.x = v1.x + best1.y = v1.y + } + if (best1.y > best2.y) { //make laser beams always fire from top to bottom so they are predicable, and not stopped by blocks on the ground + const save1X = best1.x + const save1Y = best1.y + best1.x = best2.x + best1.y = best2.y + best2.x = save1X + best2.y = save1Y + } + this.laserArray.push({ a: { x: best1.x, y: best1.y }, b: { x: best2.x, y: best2.y }, fade: 0 }) + } + // add(m.pos, m.angle) + add(m.pos, this.angle + Math.PI / 4 + Math.PI / 2) + add(this.position, this.angle + Math.PI / 4) + //friction to animate the mob dropping something + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.05)); + Matter.Body.setAngularVelocity(this, this.angularVelocity * 0.05) + if (!this.seePlayer.recall && (Vector.magnitude(Vector.sub(this.position, this.driftGoal)) < 200 || 0.3 > Math.random())) { + //used in drift when can't find player + const radius = Math.random() * 1000; + const angle = Math.random() * 2 * Math.PI; + this.driftGoal = Vector.add(this.driftCenter, { x: radius * Math.cos(angle), y: radius * Math.sin(angle) }) + } + } + } + me.fireLaser = function () { + for (let i = 0; i < this.laserArray.length; i++) { //fire all laserArray in the array + let best = vertexCollision(this.laserArray[i].a, this.laserArray[i].b, m.isCloak ? [body] : [body, [playerBody, playerHead]]); //not checking map to fix not hitting player bug, this might make some lasers look strange when the map changes + if (this.laserArray[i].fade > 0.99) { + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { // hitting player + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage after getting hit + const dmg = 0.03 * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(255,0,100,0.5)", + time: 20 + }); + this.laserArray.splice(i, 1) //remove this laser node + if (this.distanceToPlayer < 1000) { //mob jumps away from player + const forceMag = 0.03 * this.mass; + const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + this.force.x -= 2 * forceMag * Math.cos(angle); + this.force.y -= 2 * forceMag * Math.sin(angle); // - 0.0007 * this.mass; //antigravity + } + } else if (best.who && best.who.classType === "body") { //hitting block + ctx.beginPath(); + ctx.moveTo(best.x, best.y); + ctx.lineTo(this.laserArray[i].a.x, this.laserArray[i].a.y); + ctx.strokeStyle = `rgb(255,0,100)`; + ctx.lineWidth = 2; + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + } else { //hitting nothing + ctx.beginPath(); + ctx.moveTo(this.laserArray[i].b.x, this.laserArray[i].b.y); + ctx.lineTo(this.laserArray[i].a.x, this.laserArray[i].a.y); + ctx.strokeStyle = `rgb(255,0,100)`; + ctx.lineWidth = 2; + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + } + } else {//fade in warning + this.laserArray[i].fade += 0.007 + ctx.beginPath(); + ctx.moveTo(this.laserArray[i].a.x, this.laserArray[i].a.y); + ctx.lineTo(this.laserArray[i].b.x, this.laserArray[i].b.y); + ctx.lineWidth = 2 + 40 - 40 * this.laserArray[i].fade; + ctx.strokeStyle = `rgba(255,0,100,${0.02 + 0.1 * this.laserArray[i].fade})`; + ctx.stroke(); + if (this.laserArray[i].fade > 0.99) { + this.laserArray[i].fade = 1; + if (this.laserArray.length > this.laserLimit) this.laserArray.shift() //cap total lasers + break + } + } + } + } + me.driftCenter = { ...me.position }; //copy position with out reference so it doesn't change as mob moves + const r = Math.random() * 100; + const a = Math.random() * 2 * Math.PI; + me.driftGoal = Vector.add(me.driftCenter, { x: r * Math.cos(a), y: r * Math.sin(a) }) //updated in addLaser() + me.drift = function () { + //accelerate towards the player + if (this.seePlayer.recall) { + const force = Vector.mult(Vector.normalise(Vector.sub(this.seePlayer.position, this.position)), this.accelMag * this.mass) + this.force.x += force.x; + this.force.y += force.y; + } else { //drift + const force = Vector.mult(Vector.normalise(Vector.sub(this.driftGoal, this.position)), 0.00001 * this.mass) + this.force.x += force.x; + this.force.y += force.y; + } + this.torque = this.lookTorque * this.inertia * 0.9; + } + me.do = function () { + this.cycle++ + this.seePlayerCheck(); + this.checkStatus(); + this.drift(); + //add new laser to lasers array + this.addLaser() + this.fireLaser() + if (this.isInvulnerable) { + this.invulnerableCount-- + if (this.invulnerableCount < 0) { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + } + //draw invulnerable + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + }; + }, + laser(x, y, radius = 30) { + const color = "#f00" + mobs.spawn(x, y, 3, radius, color); + let me = mob[mob.length - 1]; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + Matter.Body.rotate(me, Math.random() * Math.PI * 2); + me.accelMag = 0.0001 * simulation.accelScale; + me.laserInterval = 100 + spawn.shield(me, x, y); + me.onHit = function () { + //run this function on hitting player + this.explode(); + }; + me.do = function () { + this.torque = this.lookTorque * this.inertia * 0.5; + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + if (this.seePlayer.recall) { + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + + if (simulation.cycle % this.laserInterval > this.laserInterval / 2) { + const seeRange = 8000; + let best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { x: this.position.x + seeRange * Math.cos(this.angle), y: this.position.y + seeRange * Math.sin(this.angle) }; + best = vertexCollision(this.position, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + + // hitting player + if ((best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + const dmg = 0.003 * simulation.dmgScale; + m.damage(dmg); + //draw damage + ctx.fillStyle = color; + ctx.beginPath(); + ctx.arc(best.x, best.y, dmg * 1500, 0, 2 * Math.PI); + ctx.fill(); + } + //draw beam + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); + ctx.moveTo(this.vertices[1].x, this.vertices[1].y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = color; + ctx.lineWidth = 3; + ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]); + ctx.stroke(); + ctx.setLineDash([]); + + ctx.beginPath(); + ctx.arc(this.vertices[1].x, this.vertices[1].y, 1 + 0.3 * (this.laserInterval - simulation.cycle % this.laserInterval), 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = color; + ctx.fill(); + } else { + ctx.beginPath(); + ctx.arc(this.vertices[1].x, this.vertices[1].y, 1 + 0.3 * (simulation.cycle % this.laserInterval), 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = color; + ctx.fill(); + } + } + }; + }, + laserBoss(x, y, radius = 30) { + mobs.spawn(x, y, 3, radius, "#f00"); + let me = mob[mob.length - 1]; + setTimeout(() => { //fix mob in place, but allow rotation + me.constraint = Constraint.create({ + pointA: { x: me.position.x, y: me.position.y }, + bodyB: me, + stiffness: 1, + damping: 1 + }); + Composite.add(engine.world, me.constraint); + }, 2000); //add in a delay in case the level gets flipped left right + me.count = 0; + me.frictionAir = 0.03; + // me.torque -= me.inertia * 0.002 + spawn.spawnOrbitals(me, radius + 50 + 200 * Math.random()) + Matter.Body.setDensity(me, 0.03); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.25 + me.isBoss = true; + // spawn.shield(me, x, y, 1); //not working, not sure why + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.rotateVelocity = Math.min(0.0045, 0.0015 * simulation.accelScale * simulation.accelScale) * (level.levelsCleared > 8 ? 1 : -1) * (simulation.isHorizontalFlipped ? -1 : 1) + me.do = function () { + this.fill = '#' + Math.random().toString(16).substr(-6); //flash colors + this.checkStatus(); + if (!this.isStunned) { + //check if slowed + let slowed = false + for (let i = 0; i < this.status.length; i++) { + if (this.status[i].type === "slow") { + slowed = true + break + } + } + if (!slowed) { + this.count++ + Matter.Body.setAngle(this, this.count * this.rotateVelocity) + Matter.Body.setAngularVelocity(this, 0) + } + ctx.beginPath(); + this.laserArray(this.vertices[0], this.angle + Math.PI / 3); + this.laserArray(this.vertices[1], this.angle + Math.PI); + this.laserArray(this.vertices[2], this.angle - Math.PI / 3); + ctx.strokeStyle = "#50f"; + ctx.lineWidth = 1.5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(80,0,255,0.07)"; + ctx.stroke(); // Draw it + } + }; + me.laserArray = function (where, angle) { + const seeRange = 7000; + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + const look = { x: where.x + seeRange * Math.cos(angle), y: where.y + seeRange * Math.sin(angle) }; + best = vertexCollision(where, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + const dmg = 0.14 * simulation.dmgScale; + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: dmg * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + //draw beam + if (best.dist2 === Infinity) best = look; + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + } + }, + stabber(x, y, radius = 25 + Math.ceil(Math.random() * 12), spikeMax = 7) { + if (radius > 80) radius = 65; + mobs.spawn(x, y, 6, radius, "rgb(220,50,205)"); //can't have sides above 6 or collision events don't work (probably because of a convex problem) + let me = mob[mob.length - 1]; + me.isVerticesChange = true + me.accelMag = 0.0006 * simulation.accelScale; + // me.g = 0.0002; //required if using this.gravity + me.delay = 360 * simulation.CDScale; + me.spikeVertex = 0; + me.spikeLength = 0; + me.isSpikeGrowing = false; + me.spikeGrowth = 0; + me.isSpikeReset = true; + me.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.player //can't touch other mobs + Matter.Body.rotate(me, Math.PI * 0.1); + spawn.shield(me, x, y); + me.onDeath = function () { + if (this.spikeLength > 4) { + this.spikeLength = 4 + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[this.spikeVertex], this.position)), this.radius * this.spikeLength) + this.vertices[this.spikeVertex].x = this.position.x + spike.x + this.vertices[this.spikeVertex].y = this.position.y + spike.y + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) + } + }; + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + this.attraction(); + if (this.isSpikeReset) { + if (this.seePlayer.recall) { + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + if (distMag < radius * spikeMax) { + //find nearest vertex + let nearestDistance = Infinity + for (let i = 0, len = this.vertices.length; i < len; i++) { + //find distance to player for each vertex + const dist = Vector.sub(this.seePlayer.position, this.vertices[i]); + const distMag = Vector.magnitude(dist); + //save the closest distance + if (distMag < nearestDistance) { + this.spikeVertex = i + nearestDistance = distMag + } + } + this.spikeLength = 1 + this.isSpikeGrowing = true; + this.isSpikeReset = false; + Matter.Body.setAngularVelocity(this, 0) + } + } + } else { + if (this.isSpikeGrowing) { + this.spikeLength += Math.pow(this.spikeGrowth += 0.02, 8) + if (this.spikeLength > spikeMax) { + this.isSpikeGrowing = false; + this.spikeGrowth = 0 + } + } else { + Matter.Body.setAngularVelocity(this, this.angularVelocity * 0.8) //reduce rotation + this.spikeLength -= 0.3 + if (this.spikeLength < 1) { + this.spikeLength = 1 + this.isSpikeReset = true + this.radius = radius + } + } + const spike = Vector.mult(Vector.normalise(Vector.sub(this.vertices[this.spikeVertex], this.position)), radius * this.spikeLength) + this.vertices[this.spikeVertex].x = this.position.x + spike.x + this.vertices[this.spikeVertex].y = this.position.y + spike.y + // this.radius = radius * this.spikeLength; + } + }; + }, + striker(x, y, radius = 14 + Math.ceil(Math.random() * 25)) { + mobs.spawn(x, y, 5, radius, "rgb(221,102,119)"); + let me = mob[mob.length - 1]; + me.accelMag = 0.00034 * simulation.accelScale; + me.g = 0.00015; //required if using this.gravity + me.frictionStatic = 0; + me.friction = 0; + me.delay = 30 + 60 * simulation.CDScale; + me.cd = Infinity; + me.strikeRange = 300 + Matter.Body.rotate(me, Math.PI * 0.1); + spawn.shield(me, x, y); + me.onDamage = function () { + this.cd = simulation.cycle + this.delay; + }; + me.do = function () { + this.gravity(); + if (!(simulation.cycle % this.seePlayerFreq)) { // this.seePlayerCheck(); from mobs + if ( + this.distanceToPlayer2() < this.seeAtDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + // Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 && + !m.isCloak + ) { + this.foundPlayer(); + if (this.cd === Infinity) this.cd = simulation.cycle + this.delay * 0.7; + } else if (this.seePlayer.recall) { + this.lostPlayer(); + this.cd = Infinity + } + } + this.checkStatus(); + this.attraction(); + if (this.cd < simulation.cycle && this.seePlayer.recall) { + const dist = Vector.sub(this.seePlayer.position, this.position); + const distMag = Vector.magnitude(dist); + this.cd = simulation.cycle + this.delay; + ctx.beginPath(); + ctx.moveTo(this.position.x, this.position.y); + if (distMag < 400) { + Matter.Body.translate(this, Vector.mult(Vector.normalise(dist), distMag - 20 - radius)); + } else { + Matter.Body.translate(this, Vector.mult(Vector.normalise(dist), this.strikeRange)); + } + ctx.lineTo(this.position.x, this.position.y); + ctx.lineWidth = radius * 2.1; + ctx.strokeStyle = this.fill; //"rgba(0,0,0,0.5)"; //'#000' + ctx.stroke(); + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.5, + y: this.velocity.y * 0.5 + }); + } + }; + }, + revolutionBoss(x, y, radius = 70) { + const sides = 9 + Math.floor(Math.min(12, 0.2 * simulation.difficulty)) + const coolBends = [-1.8, 0, 0, 0.9, 1.2] + const bendFactor = coolBends[Math.floor(Math.random() * coolBends.length)]; + mobs.spawn(x, y, sides, radius, "rgb(201,202,225)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.00018 + 0.00018 * Math.sqrt(simulation.accelScale); + me.frictionAir = 0.01; + me.swordRadiusMax = 400 + 10 * simulation.difficulty; + me.laserAngle = 0; + me.swordDamage = 0.025 * simulation.dmgScale //0.033 * simulation.dmgScale; previous //0.14 * simulation.dmgScale;laserBoss + + // spawn.shield(me, x, y, 1); + Matter.Body.setDensity(me, 0.005); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.13 + me.isBoss = true; + me.onDamage = function () { }; + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + + //invulnerability every 1/4 fraction of life lost + //required setup for invulnerable + me.isInvulnerable = false + me.isNextInvulnerability = 0.75 + me.invulnerabilityCountDown = 0 + me.invulnerable = function () { + if (this.health < this.isNextInvulnerability) { + this.isNextInvulnerability = Math.floor(this.health * 4) / 4 //0.75,0.5,0.25 + this.isInvulnerable = true + this.startingDamageReduction = this.damageReduction + this.damageReduction = 0 + this.invulnerabilityCountDown = 106 + } + if (this.isInvulnerable) { + if (this.invulnerabilityCountDown > 0) { + this.invulnerabilityCountDown-- + //draw invulnerability + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } else { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + } + } + } + me.do = function () { + this.invulnerable(); + this.checkStatus(); + this.seePlayerByHistory(60); + this.attraction(); + //traveling laser + this.laserAngle += this.isInvulnerable ? 0.025 : 0.006 + for (let i = 0, len = this.vertices.length; i < len; i++) { + // this.laserSword(this.vertices[1], this.angle + laserAngle); + const bend = bendFactor * Math.cos(this.laserAngle + 2 * Math.PI * i / len) + const long = this.swordRadiusMax * Math.sin(this.laserAngle + 2 * Math.PI * i / len) + if (long > 0) this.laserSword(this.vertices[i], bend + this.angle + (i + 0.5) / sides * 2 * Math.PI, Math.abs(long)); + } + }; + me.laserSword = function (where, angle, length) { + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + length * Math.cos(angle), y: where.y + length * Math.sin(angle) }; + best = vertexCollision(where, look, m.isCloak ? [map] : [map, [playerBody, playerHead]]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(100,100,255,0.1)"; // Purple path + ctx.lineWidth = 10; + ctx.stroke(); + ctx.strokeStyle = "rgba(100,100,255,0.5)"; // Purple path + ctx.lineWidth = 2; + // ctx.stroke(); + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + sprayBoss(x, y, radius = 40, isSpawnBossPowerUp = true) { + mobs.spawn(x, y, 16, radius, "rgb(255,255,255)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + me.isReactorBoss = true; + me.inertia = Infinity; //no rotation + me.burstFireFreq = 22 + Math.floor(13 * simulation.CDScale) + me.burstTotalPhases = 3 + Math.floor(1.4 / simulation.CDScale) + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0; + me.restitution = 1 + // spawn.spawnOrbitals(me, radius + 50 + 125 * Math.random(), 1) + Matter.Body.setDensity(me, 0.002 + 0.00005 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.11 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.nextHealthThreshold = 0.75 + me.onDeath = function () { + if (isSpawnBossPowerUp) powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.onDamage = function () { + if (this.health < this.nextHealthThreshold) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 //0.75,0.5,0.25 + + this.phaseCycle = -2 + this.do = this.burstFire + this.frictionAir = 1 + this.isInvulnerable = true + this.damageReduction = 0 + } + }; + + //draw radial lines from verticies showing future bullet paths? + me.radialLines = function () { + ctx.beginPath(); + for (let i = 0, len = this.vertices.length; i < len; i++) { + ctx.moveTo(this.vertices[i].x, this.vertices[i].y) + const unit = Vector.add(Vector.mult(Vector.normalise(Vector.sub(this.vertices[i], this.position)), 1000), this.vertices[i]) + ctx.lineTo(unit.x, unit.y) + } + ctx.lineWidth = 10 + ctx.strokeStyle = "rgb(200,0,200,0.03)" + ctx.stroke(); + } + + me.phaseCycle = 0 + me.normalDoStuff = function () { + this.checkStatus(); + me.seePlayer.recall = 1 + //maintain speed //faster in the vertical to help avoid repeating patterns + if (this.speed < 0.01) { + Matter.Body.setVelocity(this, Vector.mult(Vector.normalise(Vector.sub(player.position, this.position)), 0.1)); + } else { + if (Math.abs(this.velocity.y) < 9) Matter.Body.setVelocity(this, { x: this.velocity.x, y: this.velocity.y * 1.03 }); + if (Math.abs(this.velocity.x) < 7) Matter.Body.setVelocity(this, { x: this.velocity.x * 1.03, y: this.velocity.y }); + } + } + me.burstFire = function () { + this.normalDoStuff(); + this.radialLines() + //draw invulnerable + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + + if (!(simulation.cycle % this.burstFireFreq)) { + this.phaseCycle++ + if (this.phaseCycle > this.burstTotalPhases) { //start spiral fire mode + // this.phaseCycle = -7 + this.do = this.normalDoStuff + this.frictionAir = 0; + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + Matter.Body.setVelocity(this, Vector.rotate({ x: 20, y: 0 }, 2 * Math.PI * Math.random())); + if (this.isShielded) { //remove shield + for (let i = 0; i < mob.length; i++) { + if (mob[i].shield) mob[i].death() + } + } + } + if (this.phaseCycle > -1) { + Matter.Body.rotate(this, 0.02) + for (let i = 0, len = this.vertices.length; i < len; i++) { //fire a bullet from each vertex + spawn.sniperBullet(this.vertices[i].x, this.vertices[i].y, 3, 4); + const velocity = Vector.mult(Vector.normalise(Vector.sub(this.position, this.vertices[i])), -15) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: velocity.x, + y: velocity.y + }); + } + } + } + }; + me.do = me.normalDoStuff + Matter.Body.setVelocity(me, { x: 10 * (Math.random() - 0.5), y: 10 * (Math.random() - 0.5) }); + }, + mineBoss(x, y, radius = 120, isSpawnBossPowerUp = true) { + mobs.spawn(x, y, 0, radius, "rgba(255,255,255,0.5)") // "rgb(201,202,225)"); + let me = mob[mob.length - 1]; + // Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.isBoss = true; + me.isReactorBoss = true; + Matter.Body.setDensity(me, 0.001); //normal is 0.001 + me.damageReduction = 0.04 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.nextHealthThreshold = 0.75 + me.invulnerableCount = 0 + + me.cycle = 0 + me.inertia = Infinity; + me.frictionAir = 0.01 + me.restitution = 1 + me.friction = 0 + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob + me.explodeRange = 400 + Matter.Body.setVelocity(me, { x: 10 * (Math.random() - 0.5), y: 10 * (Math.random() - 0.5) }); + me.seePlayer.recall = 1; + // spawn.shield(me, x, y, 1); + me.onDamage = function () { + if (this.health < this.nextHealthThreshold) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 + this.invulnerableCount = 60 + simulation.difficulty * 1.5 + this.isInvulnerable = true + this.damageReduction = 0 + + //slow time to look cool + // simulation.fpsCap = 10 //new fps + // simulation.fpsInterval = 1000 / simulation.fpsCap; + //how long to wait to return to normal fps + // m.defaultFPSCycle = m.cycle + 20 + 90 + + + for (let i = 0, len = mob.length; i < len; ++i) { //trigger nearby mines + if (mob[i].isMine && Vector.magnitude(Vector.sub(this.position, mob[i].position)) < this.explodeRange) mob[i].isExploding = true + } + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: this.explodeRange, + color: "rgba(255,25,0,0.6)", + time: simulation.drawTime * 2 + }); + + } + }; + me.onDeath = function () { + if (isSpawnBossPowerUp) powerUps.spawnBossPowerUp(this.position.x, this.position.y) + for (let i = 0, len = mob.length; i < len; ++i) { //trigger nearby mines + if (mob[i].isMine && Vector.magnitude(Vector.sub(this.position, mob[i].position)) < this.explodeRange) mob[i].isExploding = true + } + }; + // console.log(me.mass) //100 + me.do = function () { + me.seePlayer.recall = 1 + //maintain speed //faster in the vertical to help avoid repeating patterns + if (this.speed < 0.01) { + const unit = Vector.sub(player.position, this.position) + Matter.Body.setVelocity(this, Vector.mult(Vector.normalise(unit), 0.1)); + // this.invulnerableCount = 10 + simulation.difficulty * 0.5 + // this.isInvulnerable = true + // this.damageReduction = 0 + } else { + if (Math.abs(this.velocity.y) < 10) { + Matter.Body.setVelocity(this, { x: this.velocity.x, y: this.velocity.y * 1.03 }); + } + if (Math.abs(this.velocity.x) < 7) { + Matter.Body.setVelocity(this, { x: this.velocity.x * 1.03, y: this.velocity.y }); + } + } + if (this.isInvulnerable) { + this.invulnerableCount-- + if (this.invulnerableCount < 0) { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + } + //draw invulnerable + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + this.checkStatus(); + if (!(simulation.cycle % 15) && mob.length < 360) spawn.mine(this.position.x, this.position.y) + }; + }, + mine(x, y) { + mobs.spawn(x, y, 8, 10, "rgb(255, 255, 255)"); //"rgb(100,170,150)" //"rgb(61, 125, 121)" + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.0001); //normal is 0.001 + // Matter.Body.setStatic(me, true); //make static (disables taking damage) + me.frictionAir = 1 + me.damageReduction = 2 + me.collisionFilter.mask = cat.bullet //| cat.body + // me.collisionFilter.category = cat.mobBullet; + // me.collisionFilter.mask = cat.bullet | cat.body // | cat.player + me.isMine = true + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.isUnstable = true; //dies when blocked + me.showHealthBar = false; + me.explodeRange = 210 + 140 * Math.random() + me.isExploding = false + me.countDown = Math.ceil(4 * Math.random()) + me.isInvulnerable = true //not actually invulnerable, just prevents block + ice-9 interaction + + // me.onHit = function() { + // this.isExploding = true + // }; + // me.onDamage = function() { + // this.health = 1 + // this.isExploding = true + // }; + me.do = function () { + this.checkStatus(); + + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) this.isExploding = true + + if (this.isExploding) { + if (this.countDown-- < 0) { //explode + this.death(); + //hit player + if (Vector.magnitude(Vector.sub(this.position, player.position)) < this.explodeRange && m.immuneCycle < m.cycle) { + m.damage(0.02 * simulation.dmgScale * (tech.isRadioactiveResistance ? 0.2 : 1)); + m.energy -= 0.2 * (tech.isRadioactiveResistance ? 0.2 : 1) + if (m.energy < 0) m.energy = 0 + } + // mob[i].isInvulnerable = false //make mineBoss not invulnerable ? + const range = this.explodeRange + 50 //mines get a slightly larger range to explode + for (let i = 0, len = mob.length; i < len; ++i) { + if (mob[i].alive && Vector.magnitude(Vector.sub(this.position, mob[i].position)) < range) { + if (mob[i].isMine) mob[i].isExploding = true //explode other mines + } + } + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: this.explodeRange, + color: "rgba(80,220,190,0.45)", + time: 16 + }); + } + } + }; + }, + bounceBoss(x, y, radius = 80, isSpawnBossPowerUp = true) { + mobs.spawn(x, y, 0, radius, "rgb(255,255,255)") // "rgb(201,202,225)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.isBoss = true; + me.isReactorBoss = true; + Matter.Body.setDensity(me, 0.003); //normal is 0.001 + me.damageReduction = 0.1 + me.startingDamageReduction = me.damageReduction + me.inertia = Infinity; + me.isInvulnerable = false + me.frictionAir = 0.01 + me.restitution = 1 + me.friction = 0 + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob + Matter.Body.setVelocity(me, { x: 10 * (Math.random() - 0.5), y: 10 * (Math.random() - 0.5) }); + me.seePlayer.recall = 1; + // spawn.shield(me, x, y, 1); + me.onDamage = function () { + if (this.health < this.nextHealthThreshold) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 //0.75,0.5,0.25 + this.fireCount = 60 + simulation.difficulty * 1.5 + this.isInvulnerable = true + this.damageReduction = 0 + } + }; + if (isSpawnBossPowerUp) me.onDeath = function () { powerUps.spawnBossPowerUp(this.position.x, this.position.y) }; + me.cycle = 0 + me.nextHealthThreshold = 0.75 + me.fireCount = 0 + // console.log(me.mass) //100 + me.do = function () { + me.seePlayer.recall = 1 + //maintain speed //faster in the vertical to help avoid repeating patterns + if (this.speed < 0.01) { + const unit = Vector.sub(player.position, this.position) + Matter.Body.setVelocity(this, Vector.mult(Vector.normalise(unit), 0.1)); + // this.fireCount = 10 + simulation.difficulty * 0.5 + // this.isInvulnerable = true + // this.damageReduction = 0 + } else { + if (Math.abs(this.velocity.y) < 15) Matter.Body.setVelocity(this, { x: this.velocity.x, y: this.velocity.y * 1.03 }); + if (Math.abs(this.velocity.x) < 11) Matter.Body.setVelocity(this, { x: this.velocity.x * 1.03, y: this.velocity.y }); + } + + if (this.isInvulnerable) { + this.fireCount-- + if (this.fireCount < 0) { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + } + + if (this.mass > 10) Matter.Body.scale(this, 0.99, 0.99); + + // for (let i = 0; i < 1; i++) { + const velocity = Vector.rotate(Vector.mult(Vector.normalise(this.velocity), -5 - 10 * Math.random()), 0.5 * (Math.random() - 0.5)) + spawn.bounceBullet(this.position.x, this.position.y, velocity) + // } + //draw invulnerable + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } else if (this.mass < 100) { + Matter.Body.scale(this, 1.01, 1.01); //grow back to normal size + } + + this.checkStatus(); + //horizontal attraction + // const xMag = 0.0005 + // if (player.position.x > this.position.x + 200) { + // this.force.x += xMag * this.mass; + // } else if (player.position.x < this.position.x - 200) { + // this.force.x -= xMag * this.mass; + // } + }; + }, + timeBoss(x, y, radius = 50, isSpawnBossPowerUp = true) { + mobs.spawn(x, y, 0, radius, `hsl(0, 100%, 50%)`) // "rgb(201,202,225)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.isBoss = true; + me.isReactorBoss = true; + me.inertia = Infinity; + me.frictionAir = 0.01 + me.restitution = 1 + me.friction = 0 + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob + Matter.Body.setVelocity(me, { x: 10 * (Math.random() - 0.5), y: 10 * (Math.random() - 0.5) }); + me.seePlayer.recall = 1; + // for (let i = 0; i < 4; i++) spawn.spawnOrbitals(me, radius + 25, 1) + for (let i = 0, len = 2 + 0.3 * Math.sqrt(simulation.difficulty); i < len; i++) spawn.spawnOrbitals(me, radius + 10 + 10 * i, 1); + // me.skipRate = 1 + Math.floor(simulation.difficulty*0.02) + // spawn.shield(me, x, y, 1); + Matter.Body.setDensity(me, 0.001); //normal is 0.001 + me.damageReduction = 0.05 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.onDamage = function () { + if (this.health < this.nextHealthThreshold) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 //0.75,0.5,0.25 + this.invulnerableCount = 420 + simulation.difficulty * 5 //how long does invulnerable time last + this.isInvulnerable = true + this.damageReduction = 0 + // requestAnimationFrame(() => { simulation.timePlayerSkip(300) }); //wrapping in animation frame prevents errors, probably + } + }; + me.onDeath = function () { + if (isSpawnBossPowerUp) powerUps.spawnBossPowerUp(this.position.x, this.position.y) + requestAnimationFrame(() => { simulation.timePlayerSkip(60) }); //wrapping in animation frame prevents errors, probably + }; + + me.cycle = Math.floor(360 * Math.random()) + me.nextHealthThreshold = 0.75 + me.invulnerableCount = 0 + // console.log(me.mass) //100 + me.do = function () { + this.cycle++ + this.fill = `hsl(${this.cycle * 0.5}, 100%, 80%)`; + // this.fill = `hsl(${270 + 50*Math.sin(this.cycle*0.02)}, 100%, 60%)`; + this.seePlayer.recall = 1 + //maintain speed //faster in the vertical to help avoid repeating patterns + if (this.speed < 0.01) { + const unit = Vector.sub(player.position, this.position) + Matter.Body.setVelocity(this, Vector.mult(Vector.normalise(unit), 0.1)); + } else { + if (Math.abs(this.velocity.y) < 10) Matter.Body.setVelocity(this, { x: this.velocity.x, y: this.velocity.y * 1.02 }); + if (Math.abs(this.velocity.x) < 7) Matter.Body.setVelocity(this, { x: this.velocity.x * 1.02, y: this.velocity.y }); + } + + if (this.isInvulnerable) { + this.invulnerableCount-- + if (this.invulnerableCount < 0) { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + } + //time dilation + if (!simulation.isTimeSkipping) { + requestAnimationFrame(() => { + simulation.timePlayerSkip(2) + m.walk_cycle += m.flipLegs * m.Vx //makes the legs look like they are moving fast + }); //wrapping in animation frame prevents errors, probably + + // simulation.timePlayerSkip(2) + // m.walk_cycle += m.flipLegs * m.Vx //makes the legs look like they are moving fast + + //draw invulnerable + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 15 + 6 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + } + + this.checkStatus(); + //horizontal attraction + // const xMag = 0.0005 + // if (player.position.x > this.position.x + 200) { + // this.force.x += xMag * this.mass; + // } else if (player.position.x < this.position.x - 200) { + // this.force.x -= xMag * this.mass; + // } + }; + }, + bounceBullet(x, y, velocity = { x: 0, y: 0 }, radius = 11, sides = 6) { + //bullets + mobs.spawn(x, y, sides, radius, "rgb(255,0,155)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.00001); //normal is 0.001 + me.timeLeft = 360 + Math.floor(180 * Math.random()) + me.inertia = Infinity; + me.damageReduction = 1 + me.frictionAir = 0 + me.friction = 0 + me.restitution = 1 + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map | cat.mob + + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.onHit = function () { + this.explode(this.mass * 12); + }; + me.do = function () { + this.timeLimit(); + }; + Matter.Body.setVelocity(me, velocity); + }, + slashBoss(x, y, radius = 80) { + mobs.spawn(x, y, 5, radius, "rgb(201,202,225)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.isBoss = true; + me.damageReduction = 0.11 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.frictionAir = 0.02 + me.seeAtDistance2 = 1000000; + me.accelMag = 0.0004 + 0.00015 * simulation.accelScale; + Matter.Body.setDensity(me, 0.0005); //normal is 0.001 + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map + me.memory = Infinity; + me.seePlayerFreq = 20 + me.lockedOn = null; + + me.torqueMagnitude = 0.00024 * me.inertia * (Math.random() > 0.5 ? -1 : 1); + me.delay = 70 + 70 * simulation.CDScale; + me.cd = 0; + me.swordRadius = 50; + me.swordVertex = 1 + me.swordRadiusMax = 1100 + 20 * simulation.difficulty; + me.swordRadiusGrowRate = me.swordRadiusMax * (0.005 + 0.0003 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.07 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + const seeDistance2 = 200000 + spawn.shield(me, x, y); + me.onDamage = function () { }; + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.do = function () { + this.seePlayerByHistory(40); + this.attraction(); + this.checkStatus(); + this.sword() //does various things depending on what stage of the sword swing + + // ctx.beginPath(); //hide map + // ctx.arc(this.position.x, this.position.y, 3000, 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + // ctx.fillStyle = "#444"; + // ctx.fill(); + }; + me.swordWaiting = function () { + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + !m.isCloak && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + //find vertex farthest away from player + // let dist = 0 + // for (let i = 0, len = this.vertices.length; i < len; i++) { + // const D = Vector.magnitudeSquared(Vector.sub({ x: this.vertices[i].x, y: this.vertices[i].y }, m.pos)) + // if (D > dist) { + // dist = D + // this.swordVertex = i + // } + // } + // this.laserAngle = this.swordVertex / 5 * 2 * Math.PI + 0.6283 + + this.sword = this.swordGrow + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + Matter.Body.setAngularVelocity(this, 0) + this.accelMag = 0 + this.damageReduction = 0 + this.isInvulnerable = true + this.frictionAir = 1 + } + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); //always see the tip of the sword + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.swordRadius += this.swordRadiusGrowRate + if (this.swordRadius > this.swordRadiusMax) { + this.sword = this.swordSlash + this.spinCount = 0 + } + + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + me.swordSlash = function () { + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.torque += this.torqueMagnitude; + this.spinCount++ + if (this.spinCount > 80) { + this.sword = this.swordWaiting + this.swordRadius = 50 + this.accelMag = 0.001 * simulation.accelScale; + this.cd = simulation.cycle + this.delay; + this.damageReduction = this.startingDamageReduction + this.isInvulnerable = false + this.frictionAir = 0.01 + } + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } + me.laserSword = function (where, angle) { + + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + best = vertexCollision(where, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(100,100,255,0.1)"; // Purple path + ctx.lineWidth = 25; + ctx.stroke(); + ctx.strokeStyle = "rgba(100,100,255,0.5)"; // Purple path + ctx.lineWidth = 5; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + slasher(x, y, radius = 33 + Math.ceil(Math.random() * 30)) { + mobs.spawn(x, y, 5, radius, "rgb(201,202,225)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.0008 * simulation.accelScale; + me.torqueMagnitude = 0.00002 * me.inertia * (Math.random() > 0.5 ? -1 : 1); + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.035; + me.delay = 120 * simulation.CDScale; + me.cd = 0; + me.swordRadius = 0; + me.swordVertex = 1 + me.swordRadiusMax = 350 + 5 * simulation.difficulty; + me.swordRadiusGrowRate = me.swordRadiusMax * (0.018 + 0.0006 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.04 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + const seeDistance2 = 200000 + spawn.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.checkStatus(); + this.seePlayerByHistory(15); + this.attraction(); + this.sword() //does various things depending on what stage of the sword swing + }; + me.swordWaiting = function () { + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + //find vertex farthest away from player + let dist = 0 + for (let i = 0, len = this.vertices.length; i < len; i++) { + const D = Vector.magnitudeSquared(Vector.sub({ x: this.vertices[i].x, y: this.vertices[i].y }, m.pos)) + if (D > dist) { + dist = D + this.swordVertex = i + } + } + this.laserAngle = this.swordVertex / 5 * 2 * Math.PI + 0.6283 + this.sword = this.swordGrow + this.accelMag = 0 + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.swordRadius += this.swordRadiusGrowRate + if (this.swordRadius > this.swordRadiusMax || this.isStunned) { + this.sword = this.swordSlash + this.spinCount = 0 + } + } + me.swordSlash = function () { + this.laserSword(this.vertices[this.swordVertex], this.angle + this.laserAngle); + this.torque += this.torqueMagnitude; + this.spinCount++ + if (this.spinCount > 60 || this.isStunned) { + this.sword = this.swordWaiting + this.swordRadius = 0 + this.accelMag = 0.001 * simulation.accelScale; + this.cd = simulation.cycle + this.delay; + } + } + me.laserSword = function (where, angle) { + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + best = vertexCollision(where, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(100,100,255,0.1)"; // Purple path + ctx.lineWidth = 15; + ctx.stroke(); + ctx.strokeStyle = "rgba(100,100,255,0.5)"; // Purple path + ctx.lineWidth = 4; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + slasher2(x, y, radius = 33 + Math.ceil(Math.random() * 30)) { + mobs.spawn(x, y, 6, radius, "rgb(180,199,245)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.001 * simulation.accelScale; + me.torqueMagnitude = -0.000012 * me.inertia //* (Math.random() > 0.5 ? -1 : 1); + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.035; + me.delay = 140 * simulation.CDScale; + me.cd = 0; + me.swordRadius = 0; + me.swordVertex = 1 + me.swordRadiusMax = 320 + 3.6 * simulation.difficulty; + me.swordRadiusGrowRate = me.swordRadiusMax * (0.011 + 0.0002 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.03 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + const seeDistance2 = 200000 + spawn.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.checkStatus(); + this.seePlayerByHistory(15); + this.attraction(); + this.sword() //does various things depending on what stage of the sword swing + }; + me.swordWaiting = function () { + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + this.laserAngle = -Math.PI / 6 + this.sword = this.swordGrow + this.accelMag = 0 + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + this.laserSword(this.vertices[0], this.angle + this.laserAngle); + this.laserSword(this.vertices[3], this.angle + this.laserAngle + Math.PI); + this.swordRadius += this.swordRadiusGrowRate + if (this.swordRadius > this.swordRadiusMax || this.isStunned) { + this.sword = this.swordSlash + this.spinCount = 0 + } + } + me.swordSlash = function () { + this.laserSword(this.vertices[0], this.angle + this.laserAngle); + this.laserSword(this.vertices[3], this.angle + this.laserAngle + Math.PI); + + this.torque += this.torqueMagnitude; + this.spinCount++ + if (this.spinCount > 100 || this.isStunned) { + this.sword = this.swordWaiting + this.swordRadius = 0 + this.accelMag = 0.001 * simulation.accelScale; + this.cd = simulation.cycle + this.delay; + } + } + me.laserSword = function (where, angle) { + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + best = vertexCollision(where, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + if (best.who && (best.who === playerBody || best.who === playerHead) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(100,100,255,0.1)"; // Purple path + ctx.lineWidth = 15; + ctx.stroke(); + ctx.strokeStyle = "rgba(100,100,255,0.5)"; // Purple path + ctx.lineWidth = 4; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + slasher3(x, y, radius = 33 + Math.ceil(Math.random() * 30)) { + const sides = 6 + mobs.spawn(x, y, sides, radius, "rgb(180,215,235)"); + let me = mob[mob.length - 1]; + Matter.Body.rotate(me, 2 * Math.PI * Math.random()); + me.accelMag = 0.00055 * simulation.accelScale; + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.02; + me.delay = 150 * simulation.CDScale; + me.cd = 0; + me.cycle = 0; + me.swordVertex = 1 + me.swordRadiusInitial = radius / 2; + me.swordRadius = me.swordRadiusInitial; + me.swordRadiusMax = 800 + 6 * simulation.difficulty; + me.swordRadiusGrowRateInitial = 1.08 + me.swordRadiusGrowRate = me.swordRadiusGrowRateInitial//me.swordRadiusMax * (0.009 + 0.0002 * simulation.difficulty) + me.isSlashing = false; + me.swordDamage = 0.03 * simulation.dmgScale + me.laserAngle = 3 * Math.PI / 5 + const seeDistance2 = me.swordRadiusMax * me.swordRadiusMax + spawn.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.checkStatus(); + this.seePlayerByHistory(15); + this.sword() //does various things depending on what stage of the sword swing + }; + me.swordWaiting = function () { + this.attraction(); + if ( + this.seePlayer.recall && + this.cd < simulation.cycle && + this.distanceToPlayer2() < seeDistance2 && + Matter.Query.ray(map, this.position, this.playerPosRandomY()).length === 0 && + Matter.Query.ray(body, this.position, this.playerPosRandomY()).length === 0 + ) { + //find vertex closest to the player + let dist = Infinity + for (let i = 0, len = this.vertices.length; i < len; i++) { + const D = Vector.magnitudeSquared(Vector.sub({ x: this.vertices[i].x, y: this.vertices[i].y }, m.pos)) + if (D < dist) { + dist = D + this.swordVertex = i + } + } + this.laserAngle = this.swordVertex / sides * 2 * Math.PI + Math.PI / sides + this.sword = this.swordGrow + this.cycle = 0 + this.swordRadius = this.swordRadiusInitial + //slow velocity but don't stop + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.5)) + //set angular velocity to 50% + // Matter.Body.setAngularVelocity(this, this.angularVelocity * 0.5) + //gently rotate towards the player with a torque, use cross product to decided clockwise or counterclockwise + const laserStartVector = Vector.sub(this.position, this.vertices[this.swordVertex]) + const playerVector = Vector.sub(this.position, m.pos) + const cross = Matter.Vector.cross(laserStartVector, playerVector) + this.torque = 0.00002 * this.inertia * (cross > 0 ? 1 : -1) + } + } + me.sword = me.swordWaiting //base function that changes during different aspects of the sword swing + me.swordGrow = function () { + this.laserSpear(this.vertices[this.swordVertex], this.angle + this.laserAngle); + Matter.Body.setVelocity(this, Vector.mult(this.velocity, 0.9)) + // this.swordRadius += this.swordRadiusGrowRate + this.cycle++ + // this.swordRadius = this.swordRadiusMax * Math.sin(this.cycle * 0.03) + this.swordRadius *= this.swordRadiusGrowRate + + if (this.swordRadius > this.swordRadiusMax) this.swordRadiusGrowRate = 1 / this.swordRadiusGrowRateInitial + // if (this.swordRadius > this.swordRadiusMax) this.swordRadiusGrowRate = -Math.abs(this.swordRadiusGrowRate) + if (this.swordRadius < this.swordRadiusInitial || this.isStunned) { + // this.swordRadiusGrowRate = Math.abs(this.swordRadiusGrowRate) + this.swordRadiusGrowRate = this.swordRadiusGrowRateInitial + this.sword = this.swordWaiting + this.swordRadius = 0 + this.cd = simulation.cycle + this.delay; + } + } + me.laserSpear = function (where, angle) { + best = { x: null, y: null, dist2: Infinity, who: null, v1: null, v2: null }; + const look = { x: where.x + this.swordRadius * Math.cos(angle), y: where.y + this.swordRadius * Math.sin(angle) }; + best = vertexCollision(where, look, m.isCloak ? [map, body] : [map, body, [playerBody, playerHead]]); + + if (best.who && (best.who === playerBody || best.who === playerHead)) { + this.swordRadiusGrowRate = 1 / this.swordRadiusGrowRateInitial //!!!! this retracts the sword if it hits the player + + if (m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles + 60; //player is immune to damage for an extra second + m.damage(this.swordDamage); + simulation.drawList.push({ //add dmg to draw queue + x: best.x, + y: best.y, + radius: this.swordDamage * 1500, + color: "rgba(80,0,255,0.5)", + time: 20 + }); + } + } + if (best.dist2 === Infinity) best = look; + ctx.beginPath(); //draw beam + ctx.moveTo(where.x, where.y); + ctx.lineTo(best.x, best.y); + ctx.strokeStyle = "rgba(100,100,255,0.1)"; // Purple path + ctx.lineWidth = 15; + ctx.stroke(); + ctx.strokeStyle = "rgba(100,100,255,0.5)"; // Purple path + ctx.lineWidth = 4; + ctx.setLineDash([70 + 300 * Math.random(), 55 * Math.random()]); + ctx.stroke(); // Draw it + ctx.setLineDash([]); + } + }, + sneakBoss(x, y, radius = 70) { + mobs.spawn(x, y, 5, radius, "transparent"); + let me = mob[mob.length - 1]; + Matter.Body.setDensity(me, 0.001); //extra dense //normal is 0.001 //makes effective life much larger + me.isBoss = true; + me.damageReduction = 0.17 + + me.accelMag = 0.0017 * Math.sqrt(simulation.accelScale); + me.frictionAir = 0.01; + me.g = 0.0001; //required if using this.gravity + me.stroke = "transparent"; //used for drawSneaker + me.alpha = 1; //used in drawSneaker + me.isCloaked = true; //used in drawSneaker + me.isBadTarget = true; + me.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob //can't touch player + me.showHealthBar = false; + me.memory = 30; + me.vanishesLeft = Math.ceil(1 + simulation.difficultyMode * 0.5) + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + for (let i = 0; i < simulation.difficultyMode / 2 - 0.5; i++) spawn.sneaker(this.position.x + 10 * Math.random(), this.position.y + 10 * Math.random()) + }; + me.onDamage = function () { + if (this.vanishesLeft > 0 && this.health < 0.1) { //if health is below 10% teleport to a random spot on player history, heal, and cloak + this.vanishesLeft-- + + for (let i = 0; i < 8; i++) { //flash screen to hide vanish + simulation.drawList.push({ + x: this.position.x, + y: this.position.y, + radius: 5000, + color: `rgba(0, 0, 0,${1 - 0.1 * i})`, + time: (i + 2) * 4 + }); + } + //teleport to near the end of player history + const index = Math.floor((m.history.length - 1) * (0.66 + 0.2 * Math.random())) + let history = m.history[(m.cycle - index) % 600] + Matter.Body.setPosition(this, history.position) + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + + this.damageReduction = 0 //immune to harm for the rest of this game cycle + this.seePlayer.recall = 0 + this.cloak(); + this.health = 1; + for (let i = 0; i < simulation.difficultyMode / 2 - 0.5; i++) spawn.sneaker(this.position.x + 10 * Math.random(), this.position.y + 10 * Math.random()) + } + }; + me.cloak = function () { + if (!this.isCloaked) { //stealth + this.alpha = 0; + this.isCloaked = true; + this.isBadTarget = true; + this.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob //can't touch player + this.damageReduction = 0.04 + } + } + me.deCloak = function () { + if (this.isCloaked) { + this.damageReduction = 0.4 + this.isCloaked = false; + this.isBadTarget = false; + this.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob; //can touch player + } + } + me.do = function () { + if (this.damageReduction === 0) { + this.damageReduction = 0.04 + let i = this.status.length //clear bad status effects + while (i--) { + if (this.status[i].type === "stun" || this.status[i].type === "dot") this.status.splice(i, 1); + } + this.isStunned = false; + } + this.gravity(); + this.seePlayerByHistory(55); + this.checkStatus(); + if (this.alpha > 0.8) this.attraction(); + //draw + if (this.seePlayer.recall) { + if (this.alpha < 1) this.alpha += 0.005 + 0.003 / simulation.CDScale; + } else { + if (this.alpha > 0) this.alpha -= 0.04; + } + if (this.alpha > 0) { + if (this.alpha > 0.7) { + this.healthBar(); + this.deCloak() + } + //draw body + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.fillStyle = `rgba(0,0,0,${this.alpha * this.alpha})`; + ctx.fill(); + } else { + this.cloak() + } + }; + }, + sneaker(x, y, radius = 15 + Math.ceil(Math.random() * 10)) { + mobs.spawn(x, y, 5, radius, "transparent"); + let me = mob[mob.length - 1]; + // Matter.Body.setDensity(me, 0.001); //extra dense //normal is 0.001 //makes effective life much larger + me.accelMag = 0.001 * Math.sqrt(simulation.accelScale); + me.frictionAir = 0.01; + me.g = 0.0002; //required if using this.gravity + me.stroke = "transparent"; //used for drawSneaker + me.alpha = 1; //used in drawSneaker + me.isNotCloaked = false; //used in drawSneaker + me.isBadTarget = true; + me.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob //can't touch player + me.showHealthBar = false; + me.memory = 240; + me.isVanished = false; + // spawn.shield(me, x, y); //makes it too hard to stealth + + me.onDamage = function () { + if (!this.isVanished && this.health < 0.1 && !this.isStunned && !this.isSlowed) { //if health is below 10% teleport to a random spot on player history, heal, and cloak + this.health = 1; + this.isVanished = true + this.cloak(); + //teleport to near the end of player history + Matter.Body.setPosition(this, m.history[Math.floor((m.history.length - 1) * (0.3 + 0.4 * Math.random()))].position) + Matter.Body.setVelocity(this, { x: 0, y: 0 }); + this.damageReduction = 0 //immune to harm for the rest of this game cycle + } + }; + me.cloak = function () { + if (this.isNotCloaked) { //stealth + this.alpha = 0; + this.isNotCloaked = false; + this.isBadTarget = true; + this.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob //can't touch player + } + } + me.do = function () { + if (this.damageReduction === 0) { + this.damageReduction = 1 //stop being immune to harm immediately + let i = this.status.length //clear bad status effects + while (i--) { + if (this.status[i].type === "stun" || this.status[i].type === "dot") this.status.splice(i, 1); + } + this.isStunned = false; + } + this.gravity(); + this.seePlayerByHistory(25); + this.checkStatus(); + this.attraction(); + //draw + if (this.seePlayer.recall) { + if (this.alpha < 1) this.alpha += 0.003 + 0.003 / simulation.CDScale; + } else { + if (this.alpha > 0) this.alpha -= 0.03; + } + if (this.alpha > 0) { + if (this.alpha > 0.7) { + this.healthBar(); + if (!this.isNotCloaked) { + this.isNotCloaked = true; + this.isBadTarget = false; + this.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob; //can touch player + } + } + //draw body + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.fillStyle = `rgba(0,0,0,${this.alpha * this.alpha})`; + ctx.fill(); + } else { + this.cloak() + } + }; + }, + ghoster(x, y, radius = 50 + Math.ceil(Math.random() * 90)) { + mobs.spawn(x, y, 7, radius, "transparent"); + let me = mob[mob.length - 1]; + me.seeAtDistance2 = 500000; + me.accelMag = 0.00007 + 0.0001 * simulation.accelScale; + if (map.length) me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; //required for search + Matter.Body.setDensity(me, 0.0002); //normal is 0.001 + me.damageReduction = 0.1 + me.stroke = "transparent"; //used for drawGhost + me.alpha = 1; //used in drawGhost + me.isNotCloaked = false; //used in drawGhost + me.isBadTarget = true; + me.collisionFilter.mask = cat.bullet | cat.body + me.showHealthBar = false; + me.memory = 900; + me.delay = 60 + me.cd = 0; + me.onHit = function () { + if (this.cd < simulation.cycle) { + this.cd = simulation.cycle + this.delay; + //dislodge ammo + if (b.inventory.length) { + let isRemovedAmmo = false + const numRemoved = 3 + for (let j = 0; j < numRemoved; j++) { + for (let i = 0; i < b.inventory.length; i++) { + const gun = b.guns[b.inventory[i]] + if (gun.ammo > 0 && gun.ammo !== Infinity) { + gun.ammo -= Math.ceil(1.1 * (Math.random() + Math.random()) * gun.ammoPack) + if (gun.ammo < 0) gun.ammo = 0 + isRemovedAmmo = true + } + } + } + if (isRemovedAmmo) { + simulation.updateGunHUD(); + for (let j = 0; j < numRemoved; j++) powerUps.directSpawn(this.position.x + 10 * Math.random(), this.position.y + 10 * Math.random(), "ammo"); + powerUps.ejectGraphic(); + } + } + } + }; + me.onDamage = function () { + if (this.health < 0.8) me.seeAtDistance2 = 2000000; + } + me.do = function () { + if (this.speed > 7) Matter.Body.setVelocity(this, { x: this.velocity.x * 0.8, y: this.velocity.y * 0.8 }); //cap max speed to avoid getting launched by deflection, explosion + this.seePlayerCheckByDistance(); + this.checkStatus(); + this.attraction(); + this.search(); + //draw + if (this.distanceToPlayer2() < this.seeAtDistance2) { + if (this.alpha < 1) this.alpha += 0.011 * simulation.CDScale; //near player go solid + } else if (this.alpha > 0) { + this.alpha -= 0.05; ///away from player, hide + } + if (this.alpha > 0) { + if (this.alpha > 0.7 && this.seePlayer.recall) { + this.healthBar(); + if (!this.isNotCloaked) { + this.isNotCloaked = true; + this.isBadTarget = false; + this.collisionFilter.mask = cat.player | cat.bullet | cat.body + } + } + //draw body + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + // ctx.lineWidth = 1; + ctx.fillStyle = `rgba(255,255,255,${this.alpha * this.alpha})`; + ctx.fill(); + } else if (this.isNotCloaked) { + this.isNotCloaked = false; + this.isBadTarget = true; + this.collisionFilter.mask = cat.bullet | cat.body; //can't touch player or walls + } + }; + }, + // blinker(x, y, radius = 45 + Math.ceil(Math.random() * 70)) { + // mobs.spawn(x, y, 6, radius, "transparent"); + // let me = mob[mob.length - 1]; + // Matter.Body.setDensity(me, 0.0005); //normal is 0.001 //makes effective life much lower + // me.stroke = "rgb(0,200,255)"; //used for drawGhost + // Matter.Body.rotate(me, Math.random() * 2 * Math.PI); + // me.blinkRate = 40 + Math.round(Math.random() * 60); //required for blink + // me.blinkLength = 150 + Math.round(Math.random() * 200); //required for blink + // me.isStatic = true; + // me.memory = 360; + // me.seePlayerFreq = Math.round((40 + 30 * Math.random())); + // // me.isBig = false; + // // me.scaleMag = Math.max(5 - me.mass, 1.75); + // me.onDeath = function () { + // // if (this.isBig) { + // // Matter.Body.scale(this, 1 / this.scaleMag, 1 / this.scaleMag); + // // this.isBig = false; + // // } + // }; + // me.onHit = function () { + // simulation.timeSkip(120) + // }; + // me.do = function () { + // this.seePlayerCheck(); + // this.blink(); + // //strike by expanding + // // if (this.isBig) { + // // if (this.cd - this.delay + 15 < simulation.cycle) { + // // Matter.Body.scale(this, 1 / this.scaleMag, 1 / this.scaleMag); + // // this.isBig = false; + // // } + // // } else + // if (this.seePlayer.yes && this.cd < simulation.cycle) { + // const dist = Vector.sub(this.seePlayer.position, this.position); + // const distMag2 = Vector.magnitudeSquared(dist); + // if (distMag2 < 80000) { + // this.cd = simulation.cycle + this.delay; + + // // Matter.Body.scale(this, this.scaleMag, this.scaleMag); + // // this.isBig = true; + // } + // } + // }; + // }, + bomberBoss(x, y, radius = 88) { + //boss that drops bombs from above and holds a set distance from player + mobs.spawn(x, y, 3, radius, "rgba(255,0,200,0.5)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + + Matter.Body.setDensity(me, 0.0025 + 0.00009 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + + me.stroke = "transparent"; //used for drawGhost + me.seeAtDistance2 = 1500000; + me.fireFreq = 10 + Math.floor(70 * simulation.CDScale); + me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; //required for search + me.hoverElevation = 460 + (Math.random() - 0.5) * 200; //squared + me.hoverXOff = (Math.random() - 0.5) * 100; + me.accelMag = Math.floor(10 * (Math.random() + 4.5)) * 0.00001 * simulation.accelScale; + me.g = 0.0002; //required if using this.gravity // gravity called in hoverOverPlayer + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.01; + me.memory = Infinity; + me.collisionFilter.mask = cat.player | cat.bullet //| cat.body + spawn.shield(me, x, y, 1); + + const len = Math.floor(Math.min(15, 3 + Math.sqrt(simulation.difficulty))) + const speed = (0.007 + 0.003 * Math.random() + 0.004 * Math.sqrt(simulation.difficulty)) + let radiusOrbitals = radius + 125 + 350 * Math.random() + for (let i = 0; i < len; i++) spawn.orbital(me, radiusOrbitals, i / len * 2 * Math.PI, speed) + radiusOrbitals = radius + 125 + 350 * Math.random() + for (let i = 0; i < len; i++) spawn.orbital(me, radiusOrbitals, i / len * 2 * Math.PI, -speed) + + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.damageReduction = 0.22 + me.do = function () { + // this.armor(); + this.seePlayerCheckByDistance(); + this.checkStatus(); + if (this.seePlayer.recall) { + this.hoverOverPlayer(); + this.bomb(); + this.search(); + } + }; + }, + shooter(x, y, radius = 25 + Math.ceil(Math.random() * 50)) { + mobs.spawn(x, y, 3, radius, "rgb(255,100,150)"); + let me = mob[mob.length - 1]; + // me.vertices = Matter.Vertices.clockwiseSort(Matter.Vertices.rotate(me.vertices, Math.PI, me.position)); //make the pointy side of triangle the front + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + me.isVerticesChange = true + // Matter.Body.rotate(me, Math.PI) + + me.memory = 120; + me.fireFreq = 0.007 + Math.random() * 0.005; + me.noseLength = 0; + me.fireAngle = 0; + me.accelMag = 0.0005 * simulation.accelScale; + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.05; + me.lookTorque = 0.0000025 * (Math.random() > 0.5 ? -1 : 1); + me.fireDir = { x: 0, y: 0 }; + me.onDeath = function () { //helps collisions functions work better after vertex have been changed + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) + } + spawn.shield(me, x, y); + me.do = function () { + this.seePlayerByLookingAt(); + this.checkStatus(); + this.fire(); + }; + }, + shooterBoss(x, y, radius = 110, isSpawnBossPowerUp = true) { + mobs.spawn(x, y, 3, radius, "rgb(255,70,180)"); + let me = mob[mob.length - 1]; + setTimeout(() => { //fix mob in place, but allow rotation + me.constraint = Constraint.create({ + pointA: { + x: me.position.x, + y: me.position.y + }, + bodyB: me, + stiffness: 0.00004, + damping: 0.2 + }); + Composite.add(engine.world, me.constraint); + }, 2000); //add in a delay in case the level gets flipped left right + + me.isBoss = true; + Matter.Body.setDensity(me, 0.01 + 0.0003 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.22 + + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + me.isVerticesChange = true + me.memory = 240; + me.fireFreq = 0.01 + 0.0005 * Math.min(40, simulation.difficulty); //bigger number means more shots per second + me.noseLength = 0; + me.fireAngle = 0; + me.accelMag = 0.005 * simulation.accelScale; + me.frictionAir = 0.05; + me.lookTorque = 0.000006 * (Math.random() > 0.5 ? -1 : 1); + me.fireDir = { x: 0, y: 0 }; + setTimeout(() => { + for (let i = 0, len = 3 + 0.5 * Math.sqrt(simulation.difficulty); i < len; i++) spawn.spawnOrbitals(me, radius + 40 + 10 * i, 1); + }, 100); //have to wait a sec so the tether constraint doesn't attach to an orbital + me.onDeath = function () { + if (isSpawnBossPowerUp) powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) //helps collisions functions work better after vertex have been changed + }; + me.do = function () { + // this.armor(); + this.seePlayerByLookingAt(); + this.checkStatus(); + // this.fire(); + const setNoseShape = () => { + const mag = this.radius + this.radius * this.noseLength; + this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag; + }; + //throw a mob/bullet at player + if (this.seePlayer.recall) { + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + this.fireDir.y -= Math.abs(this.seePlayer.position.x - this.position.x) / 5000; //gives the bullet an arc //was / 1600 + } + //rotate towards fireAngle + const angle = this.angle + Math.PI / 2; + const dot = Vector.dot({ x: Math.cos(angle), y: Math.sin(angle) }, this.fireDir) + // c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + const threshold = 0.1; + if (dot > threshold) { + this.torque += 0.000004 * this.inertia; + } else if (dot < -threshold) { + this.torque -= 0.000004 * this.inertia; + } else if (this.noseLength > 1.5 && dot > -0.2 && dot < 0.2) { + //fire + for (let i = 0, len = 2 + 0.07 * simulation.difficulty; i < len; i++) { + spawn.bullet(this.vertices[1].x, this.vertices[1].y, 10 + Math.ceil(this.radius / 25)); + const spread = Vector.rotate({ x: Math.sqrt(len) + 4, y: 0 }, 2 * Math.PI * Math.random()) + const dir = Vector.add(Vector.mult(this.fireDir, 25), spread) + Matter.Body.setVelocity(mob[mob.length - 1], dir); + } + this.noseLength = 0; + } + if (this.noseLength < 1.5) this.noseLength += this.fireFreq; + setNoseShape(); + } else if (this.noseLength > 0.1) { + this.noseLength -= this.fireFreq / 2; + setNoseShape(); + } + }; + }, + bullet(x, y, radius = 9, sides = 0) { + //bullets + mobs.spawn(x, y, sides, radius, "rgb(255,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + this.explode(this.mass * 15); + }; + Matter.Body.setDensity(me, 0.00004); //normal is 0.001 + me.timeLeft = 220; + me.g = 0.001; //required if using this.gravity + me.frictionAir = 0; + me.restitution = 0.8; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet; + me.do = function () { + this.gravity(); + this.timeLimit(); + }; + }, + bomb(x, y, radius = 9, sides = 5) { + mobs.spawn(x, y, sides, radius, "rgb(255,0,0)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + this.explode(this.mass * 120); + }; + me.onDeath = function () { + spawn.bullet(this.position.x, this.position.y, this.radius / 3, 5); + spawn.bullet(this.position.x, this.position.y, this.radius / 3, 5); + spawn.bullet(this.position.x, this.position.y, this.radius / 3, 5); + const mag = 8 + const v1 = Vector.rotate({ + x: 1, + y: 1 + }, 2 * Math.PI * Math.random()) + const v2 = Vector.rotate({ + x: 1, + y: 1 + }, 2 * Math.PI * Math.random()) + const v3 = Vector.normalise(Vector.add(v1, v2)) //last vector is opposite the sum of the other two to look a bit like momentum is conserved + + Matter.Body.setVelocity(mob[mob.length - 1], { + x: mag * v1.x, + y: mag * v1.y + }); + Matter.Body.setVelocity(mob[mob.length - 2], { + x: mag * v2.x, + y: mag * v2.y + }); + Matter.Body.setVelocity(mob[mob.length - 3], { + x: -mag * v3.x, + y: -mag * v3.y + }); + } + Matter.Body.setDensity(me, 0.00005); //normal is 0.001 + me.timeLeft = 140 + Math.floor(Math.random() * 30); + me.g = 0.001; //required if using this.gravity + me.frictionAir = 0; + me.restitution = 1; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet; + me.do = function () { + this.gravity(); + this.timeLimit(); + }; + }, + sniper(x, y, radius = 35 + Math.ceil(Math.random() * 30)) { + mobs.spawn(x, y, 3, radius, "transparent"); //"rgb(25,0,50)") + let me = mob[mob.length - 1]; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + me.isVerticesChange = true + // Matter.Body.rotate(me, Math.PI) + me.stroke = "transparent"; //used for drawSneaker + me.alpha = 1; //used in drawSneaker + me.showHealthBar = false; + me.frictionStatic = 0; + me.friction = 0; + me.isNotCloaked = false; //used in drawSneaker + me.isBadTarget = true; + me.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob //can't touch player + + me.memory = 30 //140; + me.fireFreq = 0.005 + Math.random() * 0.002 + 0.0005 * simulation.difficulty; //larger = fire more often + me.noseLength = 0; + me.fireAngle = 0; + me.accelMag = 0.0005 * simulation.accelScale; + me.frictionAir = 0.05; + me.torque = 0.0001 * me.inertia; + me.fireDir = { x: 0, y: 0 }; + me.onDeath = function () { //helps collisions functions work better after vertex have been changed + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) + } + spawn.shield(me, x, y); + me.do = function () { + // this.seePlayerByLookingAt(); + this.seePlayerCheck(); + this.checkStatus(); + + const setNoseShape = () => { + const mag = this.radius + this.radius * this.noseLength; + this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag; + }; + //throw a mob/bullet at player + if (this.seePlayer.recall) { + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + // this.fireDir.y -= Math.abs(this.seePlayer.position.x - this.position.x) / 1600; //gives the bullet an arc + } + //rotate towards fireAngle + const angle = this.angle + Math.PI / 2; + // c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + //rotate towards fireAngle + const dot = Vector.dot({ + x: Math.cos(angle), + y: Math.sin(angle) + }, this.fireDir) + const threshold = 0.03; + if (dot > threshold) { + this.torque += 0.000004 * this.inertia; + } else if (dot < -threshold) { + this.torque -= 0.000004 * this.inertia; + } else if (this.noseLength > 1.5 && dot > -0.2 && dot < 0.2) { + //fire + spawn.sniperBullet(this.vertices[1].x, this.vertices[1].y, 7 + Math.ceil(this.radius / 15), 5); + const v = 10 + 8 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v + Math.random(), + y: this.velocity.y + this.fireDir.y * v + Math.random() + }); + this.noseLength = 0; + // recoil + this.force.x -= 0.005 * this.fireDir.x * this.mass; + this.force.y -= 0.005 * this.fireDir.y * this.mass; + } + if (this.noseLength < 1.5) this.noseLength += this.fireFreq; + setNoseShape(); + } else if (this.noseLength > 0.1) { + this.noseLength -= this.fireFreq / 2; + setNoseShape(); + } + // else if (this.noseLength < -0.1) { + // this.noseLength += this.fireFreq / 4; + // setNoseShape(); + // } + + if (this.seePlayer.recall) { + if (this.alpha < 1) this.alpha += 0.01; + } else { + if (this.alpha > 0) this.alpha -= 0.03; + } + //draw + if (this.alpha > 0) { + if (this.alpha > 0.95) { + this.healthBar(); + if (!this.isNotCloaked) { + this.isNotCloaked = true; + this.isBadTarget = false; + this.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob; //can touch player + } + } + //draw body + ctx.beginPath(); + const vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) { + ctx.lineTo(vertices[j].x, vertices[j].y); + } + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.fillStyle = `rgba(25,0,50,${this.alpha * this.alpha})`; + ctx.fill(); + } else if (this.isNotCloaked) { + this.isNotCloaked = false; + this.isBadTarget = true + this.collisionFilter.mask = cat.map | cat.body | cat.bullet | cat.mob //can't touch player + } + }; + }, + sniperBullet(x, y, radius = 9, sides = 5) { //bullets + mobs.spawn(x, y, sides, radius, "rgb(255,0,155)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + this.explode(this.mass * 20); + }; + Matter.Body.setDensity(me, 0.00005); //normal is 0.001 + me.timeLeft = 120; + // me.g = 0.0005; //required if using this.gravity + me.frictionAir = 0; + me.restitution = 0; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet; + me.onDeath = function () { + if (simulation.difficulty > 11) { //explode AoE + const radius = 100 + 0.5 * simulation.difficulty + 50 * Math.random() + if (m.immuneCycle < m.cycle && Vector.magnitude(Vector.sub(this.position, player.position)) < radius) m.damage(0.0003 * radius * simulation.dmgScale); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: radius, + color: "rgba(255,0,155,0.5)", + time: simulation.drawTime + }); + } + }; + me.do = function () { + // this.gravity(); + this.timeLimit(); + if (Matter.Query.collides(this, map).length > 0 || Matter.Query.collides(this, body).length > 0 && this.speed < 10) { + this.isDropPowerUp = false; + this.death(); //death with no power up + } + }; + }, + launcherOne(x, y, radius = 30 + Math.ceil(Math.random() * 40)) { + mobs.spawn(x, y, 3, radius, "rgb(150,150,255)"); + let me = mob[mob.length - 1]; + me.accelMag = 0.00004 * simulation.accelScale; + me.fireFreq = Math.floor(420 + 90 * Math.random() * simulation.CDScale) + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.015; + spawn.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + if (this.seePlayer.recall && !(simulation.cycle % this.fireFreq)) { + Matter.Body.setAngularVelocity(this, 0.14) + spawn.seeker(this.vertices[0].x, this.vertices[0].y, 20, 9); //give the bullet a rotational velocity as if they were attached to a vertex + const who = mob[mob.length - 1] + Matter.Body.setDensity(who, 0.00003); //normal is 0.001 + who.timeLeft = 840 //* (0.8 + 0.4 * Math.random()); + who.accelMag = 0.00035 * simulation.accelScale; //* (0.8 + 0.4 * Math.random()) + who.frictionAir = 0.01 //* (0.8 + 0.4 * Math.random()); + const velocity = Vector.mult(Vector.perp(Vector.normalise(Vector.sub(this.position, this.vertices[0]))), -6) + Matter.Body.setVelocity(who, { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }); + } + }; + }, + launcher(x, y, radius = 30 + Math.ceil(Math.random() * 40)) { + mobs.spawn(x, y, 3, radius, "rgb(150,150,255)"); + let me = mob[mob.length - 1]; + me.accelMag = 0.00004 * simulation.accelScale; + me.fireFreq = Math.floor(420 + 90 * Math.random() * simulation.CDScale) + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.02; + spawn.shield(me, x, y); + me.onDamage = function () { }; + me.do = function () { + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + if (this.seePlayer.recall && !(simulation.cycle % this.fireFreq)) { + Matter.Body.setAngularVelocity(this, 0.14) + //fire a bullet from each vertex + for (let i = 0, len = this.vertices.length; i < len; i++) { + spawn.seeker(this.vertices[i].x, this.vertices[i].y, 7) + //give the bullet a rotational velocity as if they were attached to a vertex + const velocity = Vector.mult(Vector.perp(Vector.normalise(Vector.sub(this.position, this.vertices[i]))), -8) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }); + } + } + }; + }, + launcherBoss(x, y, radius = 90, isSpawnBossPowerUp = true) { + mobs.spawn(x, y, 6, radius, "rgb(150,150,255)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + Matter.Body.setDensity(me, 0.0022 + 0.00015 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.22 + + me.accelMag = 0.0001 * simulation.accelScale; + me.fireFreq = Math.floor(330 * simulation.CDScale) + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.02; + me.memory = 420; + me.repulsionRange = 1000000; //squared + spawn.shield(me, x, y, 1); + spawn.spawnOrbitals(me, radius + 50 + 200 * Math.random()) + + me.onDeath = function () { + if (isSpawnBossPowerUp) powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) //helps collisions functions work better after vertex have been changed + }; + me.onDamage = function () { }; + me.do = function () { + // this.armor(); + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + this.repulsion(); + if (this.seePlayer.recall && !(simulation.cycle % this.fireFreq)) { + Matter.Body.setAngularVelocity(this, 0.11) + //fire a bullet from each vertex + for (let i = 0, len = this.vertices.length; i < len; i++) { + spawn.seeker(this.vertices[i].x, this.vertices[i].y, 8) + //give the bullet a rotational velocity as if they were attached to a vertex + const velocity = Vector.mult(Vector.perp(Vector.normalise(Vector.sub(this.position, this.vertices[i]))), -10) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }); + } + } + }; + }, + // blowSuckBoss(x, y, radius = 80) { + // mobs.spawn(x, y, 10, radius, "transparent"); + // let me = mob[mob.length - 1]; + // me.isBoss = true; + // Matter.Body.setDensity(me, 0.0022 + 0.0002 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + // me.damageReduction = 0.2 + + // me.fireFreq = Math.floor(60 * simulation.CDScale) + // me.seePlayerFreq = 15 + // me.seeAtDistance2 = 300000; + // me.accelMag = 0.0003 * simulation.accelScale; + // if (map.length) me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; //required for search + // // Matter.Body.setDensity(me, 0.001); //normal is 0.001 //makes effective life much lower + // me.stroke = "transparent"; //used for drawGhost + // me.alpha = 1; //used in drawGhost + // me.isNotCloaked = false; //used in drawGhost + // me.isBadTarget = true; + // // me.leaveBody = false; + // me.collisionFilter.mask = cat.bullet //| cat.body + // me.showHealthBar = false; + // me.memory = 480; + // me.onDeath = function() { + // powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // }; + // me.onDamage = function() {}; + // me.suck = function() { + // for (let i = 0; i < mob.length; i++) { + // if (mob[i].isBlowSuckBullet) { + // const unit = Vector.normalise(Vector.sub(this.position, mob[i].position)) + // const mag = Vector.mult(unit, 0.0008 * mob[i].mass) + // mob[i].force.x += mag.x + // mob[i].force.y += mag.y + // } + // } + // } + // me.do = function() { + // //cap max speed + // if (this.speed > 8) { + // Matter.Body.setVelocity(this, { + // x: this.velocity.x * 0.8, + // y: this.velocity.y * 0.8 + // }); + // } + // this.seePlayerCheckByDistance(); + // this.checkStatus(); + // this.attraction(); + // this.search(); + // //draw + // if (this.distanceToPlayer2() < this.seeAtDistance2) { + // if (this.alpha < 1) this.alpha += 0.005 * simulation.CDScale; //near player go solid + // } else { + // if (this.alpha > 0) this.alpha -= 0.05; ///away from player, hide + // } + // if (this.alpha > 0) { + // if (this.alpha > 0.8 && this.seePlayer.recall) { + // this.healthBar(); + // if (!this.isNotCloaked) { + // this.isNotCloaked = true; + // this.isBadTarget = false; + // this.collisionFilter.mask = cat.player | cat.bullet + // } + // } + // //draw body + // ctx.beginPath(); + // const vertices = this.vertices; + // ctx.moveTo(vertices[0].x, vertices[0].y); + // for (let j = 1, len = vertices.length; j < len; ++j) { + // ctx.lineTo(vertices[j].x, vertices[j].y); + // } + // ctx.lineTo(vertices[0].x, vertices[0].y); + // ctx.lineWidth = 1; + // ctx.fillStyle = `rgba(255,255,255,${this.alpha * this.alpha})`; + // ctx.fill(); + + + // this.suck(); + // if (this.seePlayer.recall && !(simulation.cycle % this.fireFreq)) { + // this.suckCount = 0; + // Matter.Body.setAngularVelocity(this, 0.11) + // //fire a bullet from each vertex + // for (let i = 0, len = this.vertices.length; i < len; i++) { + // spawn.bounceBullet(this.vertices[i].x, this.vertices[i].y, 8) + // //give the bullet a rotational velocity as if they were attached to a vertex + // const velocity = Vector.mult(Vector.perp(Vector.normalise(Vector.sub(this.position, this.vertices[i]))), -16) + // const who = mob[mob.length - 1] + // who.isBlowSuckBullet = true + // Matter.Body.setVelocity(who, { + // x: this.velocity.x + velocity.x, + // y: this.velocity.y + velocity.y + // }); + // } + // } + + + // } else if (this.isNotCloaked) { + // this.isNotCloaked = false; + // this.isBadTarget = true; + // this.collisionFilter.mask = cat.bullet; //can't touch player or walls + // } + // }; + // }, + // blowSuckBoss(x, y, radius = 80, isSpawnBossPowerUp = true) { + // mobs.spawn(x, y, 10, radius, "transparent"); //rgb(60,60,85) + // let me = mob[mob.length - 1]; + // me.isBoss = true; + // Matter.Body.setDensity(me, 0.0022 + 0.0002 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + // me.damageReduction = 0.2 + + // me.accelMag = 0.0001 * simulation.accelScale; + // me.fireFreq = Math.floor(180 * simulation.CDScale) + // me.frictionStatic = 0; + // me.friction = 0; + // me.frictionAir = 0.005; + // me.memory = 420; + // me.repulsionRange = 1000000; //squared + // // spawn.shield(me, x, y, 1); + // // spawn.spawnOrbitals(me, radius + 50 + 200 * Math.random()) + + // me.onDeath = function() { + // if (isSpawnBossPowerUp) powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // }; + // me.onDamage = function() {}; + // me.suck = function() { + // for (let i = 0; i < mob.length; i++) { + // if (mob[i].isBlowSuckBullet) { + // const unit = Vector.normalise(Vector.sub(this.position, mob[i].position)) + // const mag = Vector.mult(unit, 0.0008 * mob[i].mass) + // mob[i].force.x += mag.x + // mob[i].force.y += mag.y + // } + // } + // } + // me.do = function() { + // this.seePlayerCheck(); + // this.checkStatus(); + // this.attraction(); + // // this.repulsion(); + // this.suck(); + + // if (this.seePlayer.recall && !(simulation.cycle % this.fireFreq)) { + // this.suckCount = 0; + // Matter.Body.setAngularVelocity(this, 0.11) + // //fire a bullet from each vertex + // for (let i = 0, len = this.vertices.length; i < len; i++) { + // spawn.bounceBullet(this.vertices[i].x, this.vertices[i].y, 8) + // //give the bullet a rotational velocity as if they were attached to a vertex + // const velocity = Vector.mult(Vector.perp(Vector.normalise(Vector.sub(this.position, this.vertices[i]))), -16) + // const who = mob[mob.length - 1] + // who.isBlowSuckBullet = true + // Matter.Body.setVelocity(who, { + // x: this.velocity.x + velocity.x, + // y: this.velocity.y + velocity.y + // }); + // } + // } + // }; + // }, + grenadierBoss(x, y, radius = 95) { + mobs.spawn(x, y, 6, radius, "rgb(0,235,255)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + + me.accelMag = 0.0001 * simulation.accelScale; + me.fireFreq = Math.floor(360 * simulation.CDScale) + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.035; + me.memory = 420; + me.repulsionRange = 1200000; //squared + // spawn.shield(me, x, y, 1); + spawn.spawnOrbitals(me, radius + 50, 1); + spawn.spawnOrbitals(me, radius + 125, 1); + spawn.spawnOrbitals(me, radius + 200, 1); + Matter.Body.setDensity(me, 0.004 + 0.00015 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + me.onDeath = function () { //helps collisions functions work better after vertex have been changed + setTimeout(() => { //fix mob in place, but allow rotation + for (let i = 0, len = 6; i < len; i++) { + const speed = 2.25 * simulation.accelScale; + const angle = 2 * Math.PI * i / len + spawn.grenade(this.position.x, this.position.y, 170 * simulation.CDScale); + const who = mob[mob.length - 1] + Matter.Body.setVelocity(who, { + x: speed * Math.cos(angle), + y: speed * Math.sin(angle) + }); + } + }, 200); + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + } + me.grenadeLimiter = 0 + me.onDamage = function () { + if (this.grenadeLimiter < 240 && this.health > 0) { + this.grenadeLimiter += 60 + spawn.grenade(this.position.x, this.position.y, 80 + Math.floor(60 * Math.random())); + who = mob[mob.length - 1] + const velocity = Vector.mult(Vector.normalise(Vector.sub(player.position, who.position)), 3 * Math.sqrt(simulation.accelScale) + 4 * Math.random()) + Matter.Body.setVelocity(who, { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }); + } + }; + me.damageReduction = 0.27 + me.do = function () { + // this.armor(); + if (this.grenadeLimiter > 1) this.grenadeLimiter-- + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + }; + }, + grenadier(x, y, radius = 35 + Math.ceil(Math.random() * 20)) { + mobs.spawn(x, y, 3, radius, "rgb(0,235,255)"); //rgb(255,100,200) + let me = mob[mob.length - 1]; + me.vertices = Matter.Vertices.rotate(me.vertices, Math.PI, me.position); //make the pointy side of triangle the front + me.isVerticesChange = true + // Matter.Body.rotate(me, Math.PI) + // me.stroke = "transparent"; //used for drawSneaker + me.frictionStatic = 0; + me.friction = 0; + me.memory = 60 //140; + me.fireFreq = 0.0055 + Math.random() * 0.0015; + me.noseLength = 0; + me.fireAngle = 0; + me.accelMag = 0.0006 * simulation.accelScale; + me.frictionAir = 0.05; + me.torque = 0.0001 * me.inertia * (Math.random() > 0.5 ? -1 : 1) + me.fireDir = { x: 0, y: 0 }; + me.onDeath = function () { //helps collisions functions work better after vertex have been changed + spawn.grenade(this.position.x, this.position.y, 200 * simulation.CDScale); + // mob[mob.length - 1].collisionFilter.category = 0 + mob[mob.length - 1].collisionFilter.mask = cat.player | cat.map; + } + spawn.shield(me, x, y); + me.do = function () { + this.seePlayerCheck(); + this.checkStatus(); + + const setNoseShape = () => { + const mag = this.radius + this.radius * this.noseLength; + this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag; + this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag; + }; + //throw a mob/bullet at player + if (this.seePlayer.recall) { + //set direction to turn to fire + if (!(simulation.cycle % this.seePlayerFreq)) { + this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position)); + // this.fireDir.y -= Math.abs(this.seePlayer.position.x - this.position.x) / 1600; //gives the bullet an arc + } + //rotate towards fireAngle + const angle = this.angle + Math.PI / 2; + // c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y; + //rotate towards fireAngle + const dot = Vector.dot({ + x: Math.cos(angle), + y: Math.sin(angle) + }, this.fireDir) + const threshold = 0.03; + if (dot > threshold) { + this.torque += 0.000004 * this.inertia; + } else if (dot < -threshold) { + this.torque -= 0.000004 * this.inertia; + } else if (this.noseLength > 1.5 && dot > -0.2 && dot < 0.2) { + //fire + spawn.grenade(this.vertices[1].x, this.vertices[1].y); + const v = 5 * simulation.accelScale; + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + this.fireDir.x * v + Math.random(), + y: this.velocity.y + this.fireDir.y * v + Math.random() + }); + this.noseLength = 0; + // recoil + this.force.x -= 0.005 * this.fireDir.x * this.mass; + this.force.y -= 0.005 * this.fireDir.y * this.mass; + } + if (this.noseLength < 1.5) this.noseLength += this.fireFreq; + setNoseShape(); + } else if (this.noseLength > 0.1) { + this.noseLength -= this.fireFreq / 2; + setNoseShape(); + } + }; + }, + grenade(x, y, lifeSpan = 90 + Math.ceil(60 / simulation.accelScale), pulseRadius = Math.min(550, 250 + simulation.difficulty * 3), size = 3) { + mobs.spawn(x, y, 4, size, "rgb(215,0,190)"); //rgb(215,80,190) + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + this.explode(this.mass); + }; + Matter.Body.setDensity(me, 0.00004); //normal is 0.001 + + me.lifeSpan = lifeSpan; + me.timeLeft = me.lifeSpan; + // me.g = 0.0002; //required if using this.gravity + me.frictionAir = 0; + me.restitution = 0.8; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.onDeath = function () { + //damage player if in range + if (Vector.magnitude(Vector.sub(player.position, this.position)) < pulseRadius && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage + m.damage(0.015 * simulation.dmgScale); + } + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: pulseRadius, + color: "rgba(255,0,220,0.3)", + time: simulation.drawTime + }); + }; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.map | cat.body | cat.player + // me.collisionFilter.mask = 0 + me.do = function () { + this.timeLimit(); + ctx.beginPath(); //draw explosion outline + ctx.arc(this.position.x, this.position.y, pulseRadius * (1.01 - this.timeLeft / this.lifeSpan), 0, 2 * Math.PI); //* this.fireCycle / this.fireDelay + ctx.fillStyle = "rgba(255,0,220,0.05)"; + ctx.fill(); + }; + }, + shieldingBoss(x, y, radius = 200) { + mobs.spawn(x, y, 9, radius, "rgb(150, 150, 255)"); + let me = mob[mob.length - 1]; + setTimeout(() => { //fix mob in place, but allow rotation + me.constraint = Constraint.create({ + pointA: { + x: me.position.x, + y: me.position.y + }, + bodyB: me, + stiffness: 0.0001, + damping: 1 + }); + Composite.add(engine.world, me.constraint); + }, 2000); //add in a delay in case the level gets flipped left right + + Matter.Body.rotate(me, Math.random() * 2 * Math.PI) + // me.stroke = "rgb(220,220,255)" + me.isBoss = true; + me.cycle = 0 + me.maxCycles = 110; + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 1; + // me.homePosition = { x: x, y: y }; + spawn.shield(me, x, y, 1); + spawn.spawnOrbitals(me, radius + 50 + 200 * Math.random()) + + Matter.Body.setDensity(me, 0.0045); //extra dense //normal is 0.001 //makes effective life much larger + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) //helps collisions functions work better after vertex have been changed + }; + me.onDamage = function () { + this.cycle = 0 + }; + me.damageReduction = 0.39 + me.do = function () { + Matter.Body.rotate(this, 0.003) //gently spin around + this.checkStatus(); + ctx.beginPath(); //draw cycle timer + ctx.moveTo(this.vertices[this.vertices.length - 1].x, this.vertices[this.vertices.length - 1].y) + const phase = (this.vertices.length + 1) * this.cycle / this.maxCycles + if (phase > 1) ctx.lineTo(this.vertices[0].x, this.vertices[0].y) + for (let i = 1; i < phase - 1; i++) ctx.lineTo(this.vertices[i].x, this.vertices[i].y) + ctx.lineWidth = 5 + ctx.strokeStyle = "rgb(255,255,255)" + ctx.stroke(); + + this.cycle++ + if (this.cycle > this.maxCycles) { + this.cycle = 0 + ctx.beginPath(); + for (let i = 0; i < mob.length; i++) { + if (!mob[i].isShielded && !mob[i].shield && mob[i].isDropPowerUp && mob[i].alive && !mob[i].isBoss) { + ctx.moveTo(this.position.x, this.position.y) + ctx.lineTo(mob[i].position.x, mob[i].position.y) + spawn.shield(mob[i], mob[i].position.x, mob[i].position.y, 1, true); + // me.damageReduction = 0.075 + mob[mob.length - 1].damageReduction = 0.5 * 0.075 //shields are extra strong + } + } + if (!this.isShielded && this.alive) spawn.shield(this, this.position.x, this.position.y, 1, true); + ctx.lineWidth = 20 + ctx.strokeStyle = "rgb(200,200,255)" + ctx.stroke(); + } + }; + }, + timeSkipBoss(x, y, radius = 50) { + mobs.spawn(x, y, 15, radius, "transparent"); + let me = mob[mob.length - 1]; + me.isBoss = true; + me.eventHorizon = 0; //set in mob loop + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.005; + me.accelMag = 0.00008 + 0.00002 * simulation.accelScale + spawn.shield(me, x, y, 1); + spawn.spawnOrbitals(me, radius + 50 + 100 * Math.random()) + + Matter.Body.setDensity(me, 0.0025); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.07 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // requestAnimationFrame(() => { simulation.timePlayerSkip(120) }); //wrapping in animation frame prevents errors, probably + }; + me.onDamage = function () { + //find side of mob closest to player + //causes lag for foam,laser too many seekers //maybe scale chance with dmg + // const where = Vector.add(this.position, Vector.mult(Vector.normalise(Vector.sub(m.pos, this.position)), this.radius + 10)) + // spawn.seeker(where.x, where.y); //give the bullet a rotational velocity as if they were attached to a vertex + }; + me.do = function () { + this.seePlayerByHistory(60); + this.attraction(); + this.checkStatus(); + this.eventHorizon = 950 + 250 * Math.sin(simulation.cycle * 0.005) + if (!simulation.isTimeSkipping) { + if (Vector.magnitude(Vector.sub(this.position, m.pos)) < this.eventHorizon) { + this.attraction(); + this.damageReduction = this.startingDamageReduction + this.isInvulnerable = false + // if (!(simulation.cycle % 15)) requestAnimationFrame(() => { + // simulation.timePlayerSkip(5) + // // simulation.loop(); //ending with a wipe and normal loop fixes some very minor graphical issues where things are draw in the wrong locations + // }); //wrapping in animation frame prevents errors, probably + + // + // simulation.timePlayerSkip(1) + // m.walk_cycle += m.flipLegs * m.Vx //makes the legs look like they are moving fast + // }); //wrapping in animation frame prevents errors, probably + requestAnimationFrame(() => { + simulation.timePlayerSkip(1) + }); //wrapping in animation frame prevents errors, probably + + m.walk_cycle += m.flipLegs * m.Vx //makes the legs look like they are moving fast + + // if (simulation.fpsCap > 999){} + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.eventHorizon, 0, 2 * Math.PI); + ctx.fillStyle = "#fff"; + ctx.globalCompositeOperation = "destination-in"; //in or atop + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + ctx.beginPath(); + ctx.arc(this.position.x, this.position.y, this.eventHorizon, 0, 2 * Math.PI); + // ctx.stroke(); + ctx.clip(); + } else { + this.damageReduction = 0 + this.isInvulnerable = true + //prevents other things from being drawn later on in the draw cycle + requestAnimationFrame(() => { + simulation.camera(); + ctx.beginPath(); //gets rid of already draw shapes + ctx.arc(this.position.x, this.position.y, this.eventHorizon, 0, 2 * Math.PI, false); //part you can't see + ctx.fillStyle = document.body.style.backgroundColor; + ctx.fill(); + ctx.restore(); + }) + } + } + }; + }, + streamBoss(x, y, radius = 110) { + mobs.spawn(x, y, 5, radius, "rgb(245,180,255)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + // me.accelMag = 0.00023 * simulation.accelScale; + me.accelMag = 0.00008 * simulation.accelScale; + // me.fireFreq = Math.floor(30 * simulation.CDScale) + me.canFire = false; + me.closestVertex1 = 0; + me.closestVertex2 = 1; + me.cycle = 0 + me.frictionStatic = 0; + me.friction = 0; + me.frictionAir = 0.022; + me.memory = 240; + me.repulsionRange = 1200000; //squared + spawn.shield(me, x, y, 1); + spawn.spawnOrbitals(me, radius + 50 + 200 * Math.random()) + + Matter.Body.setDensity(me, 0.01); //extra dense //normal is 0.001 //makes effective life much larger + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + // this.vertices = Matter.Vertices.hull(Matter.Vertices.clockwiseSort(this.vertices)) //helps collisions functions work better after vertex have been changed + }; + me.onDamage = function () { }; + me.damageReduction = 0.28 + me.do = function () { + // this.armor(); + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + this.repulsion(); + + this.cycle++ + if (this.seePlayer.recall && ((this.cycle % 15) === 0)) { + if (this.canFire) { + if (this.cycle > 100) { + this.cycle = 0 + this.canFire = false + // Matter.Body.setAngularVelocity(this, 0.1) + // const forceMag = 0.01 * this.mass; + // const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + // this.force.x -= 2 * forceMag * Math.cos(angle); + // this.force.y -= 2 * forceMag * Math.sin(angle); // - 0.0007 * this.mass; //antigravity + } + spawn.seeker(this.vertices[this.closestVertex1].x, this.vertices[this.closestVertex1].y, 6) + Matter.Body.setDensity(mob[mob.length - 1], 0.000001); //normal is 0.001 + const velocity = Vector.mult(Vector.normalise(Vector.sub(this.position, this.vertices[this.closestVertex1])), -10) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }); + spawn.seeker(this.vertices[this.closestVertex2].x, this.vertices[this.closestVertex2].y, 6) + Matter.Body.setDensity(mob[mob.length - 1], 0.000001); //normal is 0.001 + const velocity2 = Vector.mult(Vector.normalise(Vector.sub(this.position, this.vertices[this.closestVertex2])), -10) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + velocity2.x, + y: this.velocity.y + velocity2.y + }); + } else if (this.cycle > 210) { + this.cycle = 0 + this.canFire = true + + //find closest 2 vertexes + let distance2 = Infinity + for (let i = 0; i < this.vertices.length; i++) { + const d = Vector.magnitudeSquared(Vector.sub(this.vertices[i], player.position)) + if (d < distance2) { + distance2 = d + this.closestVertex2 = this.closestVertex1 + this.closestVertex1 = i + } + } + if (this.closestVertex2 === this.closestVertex1) { + this.closestVertex2++ + if (this.closestVertex2 === this.vertices.length) this.closestVertex2 = 0 + } + } + } + }; + }, + seeker(x, y, radius = 8, sides = 6) { + //bullets + mobs.spawn(x, y, sides, radius, "rgb(255,0,255)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + me.onHit = function () { + this.explode(this.mass * 20); + }; + Matter.Body.setDensity(me, 0.000015); //normal is 0.001 + me.timeLeft = 420 //* (0.8 + 0.4 * Math.random()); + me.accelMag = 0.00017 * simulation.accelScale; //* (0.8 + 0.4 * Math.random()) + me.frictionAir = 0.01 //* (0.8 + 0.4 * Math.random()); + me.restitution = 0.5; + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isMobBullet = true; + me.showHealthBar = false; + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet; + me.do = function () { + // this.seePlayer.yes = false; + this.alwaysSeePlayer() + this.attraction(); + this.timeLimit(); + }; + }, + spawner(x, y, radius = 55 + Math.ceil(Math.random() * 50)) { + mobs.spawn(x, y, 4, radius, "rgb(255,150,0)"); + let me = mob[mob.length - 1]; + me.g = 0.0004; //required if using this.gravity + me.leaveBody = false; + // me.isDropPowerUp = false; + me.onDeath = function () { //run this function on death + for (let i = 0; i < Math.ceil(this.mass * 0.15 + Math.random() * 2.5); ++i) { + spawn.spawns(this.position.x + (Math.random() - 0.5) * radius * 2.5, this.position.y + (Math.random() - 0.5) * radius * 2.5); + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + (Math.random() - 0.5) * 15, + y: this.velocity.x + (Math.random() - 0.5) * 15 + }); + } + }; + spawn.shield(me, x, y); + me.do = function () { + this.gravity(); + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + }; + }, + spawns(x, y, radius = 15) { + mobs.spawn(x, y, 4, radius, "rgb(255,0,0)"); + let me = mob[mob.length - 1]; + me.onHit = function () { //run this function on hitting player + this.explode(); + }; + // me.stroke = "transparent" + me.collisionFilter.mask = cat.player | cat.bullet | cat.body | cat.map | cat.mob + me.showHealthBar = false; + Matter.Body.setDensity(me, 0.0001); //normal is 0.001 + me.g = 0.00002; //required if using this.gravity + me.accelMag = 0.00012 * simulation.accelScale; + // me.memory = 30; + me.isDropPowerUp = false + me.leaveBody = false; + me.seePlayerFreq = Math.floor((80 + 50 * Math.random())); + me.frictionAir = 0.004; + me.do = function () { + this.gravity(); + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + + // this.alwaysSeePlayer(); + // this.checkStatus(); + // this.attraction(); + }; + }, + exploder(x, y, radius = 40 + Math.ceil(Math.random() * 50)) { + mobs.spawn(x, y, 4, radius, "rgb(255,0,0)"); + let me = mob[mob.length - 1]; + me.onHit = function () { + //run this function on hitting player + this.explode(); + }; + me.g = 0.0004; //required if using this.gravity + spawn.shield(me, x, y); + me.do = function () { + this.gravity(); + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + }; + }, + snakeSpitBoss(x, y, radius = 50) { + let angle = Math.PI + const tailRadius = 300 + + const color1 = "rgb(235,180,255)" + mobs.spawn(x + tailRadius * Math.cos(angle), y + tailRadius * Math.sin(angle), 8, radius, color1); //"rgb(55,170,170)" + let me = mob[mob.length - 1]; + me.isBoss = true; + me.accelMag = 0.0001 + 0.0004 * Math.sqrt(simulation.accelScale) + // me.accelMag = 0.0004 + 0.0002 * Math.sqrt(simulation.accelScale) + me.memory = 250; + me.laserRange = 500; + Matter.Body.setDensity(me, 0.0022 + 0.00022 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + me.startingDamageReduction = 0.14 + me.damageReduction = 0 + me.isInvulnerable = true + + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + for (let i = 0, len = mob.length; i < len; i++) { + if (this.id === mob[i].snakeHeadID && mob[i].alive) mob[i].death() + } + }; + }; + me.canFire = false; + me.closestVertex1 = 0; + me.cycle = 0 + me.do = function () { + // this.armor(); + this.seePlayerByHistory(40) + this.checkStatus(); + this.attraction(); + this.cycle++ + if (this.seePlayer.recall && ((this.cycle % 10) === 0)) { + if (this.canFire) { + if (this.cycle > 120) { + this.cycle = 0 + this.canFire = false + // Matter.Body.setAngularVelocity(this, 0.1) + // const forceMag = 0.01 * this.mass; + // const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x); + // this.force.x -= 2 * forceMag * Math.cos(angle); + // this.force.y -= 2 * forceMag * Math.sin(angle); // - 0.0007 * this.mass; //antigravity + } + spawn.seeker(this.vertices[this.closestVertex1].x, this.vertices[this.closestVertex1].y, 6) + Matter.Body.setDensity(mob[mob.length - 1], 0.000001); //normal is 0.001 + const velocity = Vector.mult(Vector.normalise(Vector.sub(this.vertices[this.closestVertex1], this.position)), 15) + Matter.Body.setVelocity(mob[mob.length - 1], { + x: this.velocity.x + velocity.x, + y: this.velocity.y + velocity.y + }); + // spawn.seeker(this.vertices[this.closestVertex2].x, this.vertices[this.closestVertex2].y, 6) + // Matter.Body.setDensity(mob[mob.length - 1], 0.000001); //normal is 0.001 + // const velocity2 = Vector.mult(Vector.normalise(Vector.sub(this.position, this.vertices[this.closestVertex2])), -10) + // Matter.Body.setVelocity(mob[mob.length - 1], { + // x: this.velocity.x + velocity2.x, + // y: this.velocity.y + velocity2.y + // }); + } else if (this.cycle > 200) { + this.cycle = 0 + this.canFire = true + + //find closest 2 vertexes + let distance2 = Infinity + for (let i = 0; i < this.vertices.length; i++) { + const d = Vector.magnitudeSquared(Vector.sub(this.vertices[i], player.position)) + if (d < distance2) { + distance2 = d + // this.closestVertex2 = this.closestVertex1 + this.closestVertex1 = i + } + } + // if (this.closestVertex2 === this.closestVertex1) { + // this.closestVertex2++ + // if (this.closestVertex2 === this.vertices.length) this.closestVertex2 = 0 + // } + } + } + if (this.isInvulnerable) { + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 20; + ctx.strokeStyle = "rgba(255,255,255,0.7)"; + ctx.stroke(); + } + }; + //extra space to give head room + angle -= 0.07 + let previousTailID = 0 + const nodes = Math.min(10 + Math.ceil(0.6 * simulation.difficulty), 60) + for (let i = 0; i < nodes; ++i) { + angle -= 0.1 + spawn.snakeBody(x + tailRadius * Math.cos(angle), y + tailRadius * Math.sin(angle), i === 0 ? 25 : 20); + if (i < 4) mob[mob.length - 1].snakeHeadID = me.id + mob[mob.length - 1].previousTailID = previousTailID + previousTailID = mob[mob.length - 1].id + } + const damping = 1 + const stiffness = 1 + this.constrain2AdjacentMobs(nodes, stiffness, false, damping); + for (let i = mob.length - 1, len = i - nodes; i > len; i--) { //set alternating colors + if (i % 2) { + mob[i].fill = "#778" + } else { + mob[i].fill = color1 + } + } + //constraint with first 3 mobs in line + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - nodes], + bodyB: mob[mob.length - 1 - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - nodes + 1], + bodyB: mob[mob.length - 1 - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - nodes + 2], + bodyB: mob[mob.length - 1 - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + }, + dragonFlyBoss(x, y, radius = 42) { //snake boss with a laser head + let angle = Math.PI + const tailRadius = 300 + mobs.spawn(x + tailRadius * Math.cos(angle), y + tailRadius * Math.sin(angle), 8, radius, "#000"); //"rgb(55,170,170)" + let me = mob[mob.length - 1]; + me.isBoss = true; + Matter.Body.setDensity(me, 0.00165 + 0.00011 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + me.startingDamageReduction = 0.1 + me.damageReduction = 0 + me.isInvulnerable = true + + me.accelMag = 0.00008 + 0.00045 * Math.sqrt(simulation.accelScale) + me.memory = 250; + me.seePlayerFreq = 13 + me.flapRate = 0.4 + me.flapArc = 0.2 //don't go past 1.57 for normal flaps + me.wingLength = 150 + me.ellipticity = 0.3 + me.angleOff = 0.4 + + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + for (let i = 0, len = mob.length; i < len; i++) { + if (this.id === mob[i].snakeHeadID && mob[i].alive) mob[i].death() + } + }; + me.do = function () { + this.seePlayerByHistory(40) + this.checkStatus(); + this.attraction(); + + let a //used to set the angle of wings + if (this.isInvulnerable) { + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 12; + ctx.strokeStyle = "rgba(255,255,255,0.9)"; + ctx.stroke(); + const sub = Vector.sub(this.position, this.snakeBody1.position) + a = Math.atan2(sub.y, sub.x) + } else { + a = Math.atan2(this.velocity.y, this.velocity.x) + } + + ctx.fillStyle = `hsla(${160 + 40 * Math.random()}, 100%, ${25 + 25 * Math.random() * Math.random()}%, 0.9)`; //"rgba(0,235,255,0.3)"; // ctx.fillStyle = `hsla(44, 79%, 31%,0.4)`; //"rgba(0,235,255,0.3)"; + this.wing(a + Math.PI / 2 + this.angleOff + this.flapArc * Math.sin(simulation.cycle * this.flapRate), this.wingLength, this.ellipticity) + this.wing(a - Math.PI / 2 - this.angleOff - this.flapArc * Math.sin(simulation.cycle * this.flapRate), this.wingLength, this.ellipticity) + this.wing(a - Math.PI / 2 + this.angleOff + this.flapArc * Math.sin(simulation.cycle * this.flapRate), this.wingLength, this.ellipticity) + this.wing(a + Math.PI / 2 - this.angleOff - this.flapArc * Math.sin(simulation.cycle * this.flapRate), this.wingLength, this.ellipticity) + }; + + angle -= 0.07 + let previousTailID = 0 + const nodes = Math.min(10 + Math.ceil(0.6 * simulation.difficulty), 60) + for (let i = 0; i < nodes; ++i) { + angle -= 0.1 + spawn.snakeBody(x + tailRadius * Math.cos(angle), y + tailRadius * Math.sin(angle), i === 0 ? 25 : 20); + const who = mob[mob.length - 1] + who.fill = `hsl(${160 + 40 * Math.random()}, 100%, ${5 + 25 * Math.random() * Math.random()}%)` + if (i < 4) who.snakeHeadID = me.id + if (i === 0) me.snakeBody1 = who //track this segment, so the difference in position between this segment and the head can be used to angle the wings + who.previousTailID = previousTailID + previousTailID = who.id + } + const damping = 1 + const stiffness = 1 + this.constrain2AdjacentMobs(nodes, stiffness, false, damping); + //constraint with first few mobs in tail + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - nodes], + bodyB: mob[mob.length - 1 - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - nodes + 1], + bodyB: mob[mob.length - 1 - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - nodes + 2], + bodyB: mob[mob.length - 1 - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + }, + snakeBody(x, y, radius = 10) { + mobs.spawn(x, y, 8, radius, "rgba(0,180,180,0.4)"); + let me = mob[mob.length - 1]; + me.collisionFilter.mask = cat.bullet | cat.player | cat.body //| cat.mob + me.damageReduction = 0.031 + Matter.Body.setDensity(me, 0.0001); //normal is 0.001 + + // me.accelMag = 0.0007 * simulation.accelScale; + me.leaveBody = Math.random() < 0.33 ? true : false; + me.showHealthBar = false; + me.isDropPowerUp = false; + me.frictionAir = 0; + me.isSnakeTail = true; + me.stroke = "transparent" + me.onDeath = function () { + setTimeout(() => { + for (let i = 0, len = mob.length; i < len; i++) { + if (this.id === mob[i].previousTailID && mob[i].alive) mob[i].death() + if (this.snakeHeadID === mob[i].id) { + mob[i].isInvulnerable = false + mob[i].damageReduction = mob[i].startingDamageReduction + } else if (mob[i].isSnakeTail) { + //damage all snake tails + mob[i].health *= 0.95 + } + } + }, 500); + }; + me.do = function () { + this.checkStatus(); + }; + // me.doActive = function() { + // this.checkStatus(); + // this.alwaysSeePlayer(); + // this.attraction(); + // }; + }, + tetherBoss(x, y, constraint, radius = 90) { + // constrained mob boss for the towers level + // often has a ring of mobs around it + mobs.spawn(x, y, 8, radius, "rgb(0,60,80)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + Matter.Body.setDensity(me, 0.0006 + 0.0001 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.27 + me.startingDamageReduction = me.damageReduction + me.isInvulnerable = false + me.nextHealthThreshold = 0.75 + me.invulnerableCount = 0 + me.g = 0.0001; //required if using this.gravity + me.accelMag = 0.0012 + 0.0013 * simulation.accelScale; + me.memory = 20; + me.repulsionRange = 1800 * 1800 + + cons[cons.length] = Constraint.create({ + pointA: { x: constraint.x, y: constraint.y }, + bodyB: me, + stiffness: 0.00012 + }); + Composite.add(engine.world, cons[cons.length - 1]); + + spawn.shield(me, x, y, 1); + setTimeout(() => { spawn.spawnOrbitals(me, radius + 50 + 200 * Math.random()) }, 100); //have to wait a sec so the tether constraint doesn't attach to an orbital + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + this.removeCons(); //remove constraint + me.babies(0.05 * simulation.difficulty + 1) + }; + me.babies = function (len) { + const delay = Math.max(3, Math.floor(15 - len / 2)) + let i = 0 + let spawnFlutters = () => { + if (i < len) { + if (!(simulation.cycle % delay) && !simulation.paused && !simulation.isChoosing && m.alive) { + // const phase = i / len * 2 * Math.PI + // const where = Vector.add(this.position, Vector.mult({ x: Math.cos(phase), y: Math.sin(phase) }, radius * 1.5)) + const unit = Vector.normalise(Vector.sub(player.position, this.position)) + const velocity = Vector.mult(unit, 10 + 10 * Math.random()) + const where = Vector.add(this.position, Vector.mult(unit, radius * 1.2)) + spawn.allowShields = false + spawn.flutter(where.x, where.y, Math.floor(9 + 8 * Math.random())) + const who = mob[mob.length - 1] + Matter.Body.setDensity(who, 0.01); //extra dense //normal is 0.001 //makes effective life much larger + Matter.Body.setVelocity(who, velocity); + Matter.Body.setAngle(who, Math.atan2(velocity.y, velocity.x)) + + this.alertNearByMobs(); + spawn.allowShields = true + i++ + } + requestAnimationFrame(spawnFlutters); + } + } + requestAnimationFrame(spawnFlutters); + } + me.onDamage = function () { + if (this.health < this.nextHealthThreshold && this.alive) { + this.health = this.nextHealthThreshold - 0.01 + this.nextHealthThreshold = Math.floor(this.health * 4) / 4 + this.invulnerableCount = 90 + Math.floor(30 * Math.random()) + this.isInvulnerable = true + this.damageReduction = 0 + } + }; + me.do = function () { + this.gravity(); + if (this.isInvulnerable) { + this.repulsion(); + this.invulnerableCount-- + if (this.invulnerableCount < 0) { + this.isInvulnerable = false + this.damageReduction = this.startingDamageReduction + this.frictionAir = 0.05 + me.babies(0.07 * simulation.difficulty + 2) + if (this.radius > 15) { + const scale = 0.88; + Matter.Body.scale(this, scale, scale); + this.radius *= scale; + } + } + //draw invulnerable + ctx.beginPath(); + let vertices = this.vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1; j < vertices.length; j++) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.lineTo(vertices[0].x, vertices[0].y); + ctx.lineWidth = 13 + 5 * Math.random(); + ctx.strokeStyle = `rgba(255,255,255,${0.5 + 0.2 * Math.random()})`; + ctx.stroke(); + } else { + this.seePlayerCheck(); + this.checkStatus(); + this.attraction(); + } + }; + }, + //chance = Math.min(0.02 + simulation.difficulty * 0.005, 0.2) + tech.duplicationChance() + shield(target, x, y, chance = (level.isMobShields ? 4 : 1) * Math.min(0.02 + simulation.difficulty * 0.005, 0.2)) { + if (this.allowShields && Math.random() < chance) { + mobs.spawn(x, y, 9, target.radius + 30, "rgba(220,220,255,0.9)"); + let me = mob[mob.length - 1]; + me.stroke = "rgb(220,220,255)"; + Matter.Body.setDensity(me, 0.00001) //very low density to not mess with the original mob's motion + me.shield = true; + me.damageReduction = 0.05 + me.isUnblockable = true + me.collisionFilter.category = cat.mobShield + me.collisionFilter.mask = cat.bullet; + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: target, //attach shield to target + stiffness: 0.4, + damping: 0.1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + + me.onDamage = function () { + //make sure the mob that owns the shield can tell when damage is done + this.alertNearByMobs(); + this.fill = `rgba(220,220,255,${0.3 + 0.6 * this.health})` + }; + me.leaveBody = false; + me.isDropPowerUp = false; + me.showHealthBar = false; + + me.shieldTargetID = target.id + target.isShielded = true; + if (target.shieldCount > 0) { + target.shieldCount++ + } else { + target.shieldCount = 1 + } + me.shieldCount = target.shieldCount //used with "bubble fusion" + target.shieldID = me.id + + me.onDeath = function () { + //clear isShielded status from target + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].id === this.shieldTargetID) mob[i].isShielded = false; + } + }; + me.do = function () { + this.checkStatus(); + }; + + mob.unshift(me); //move shield to the front of the array, so that mob is behind shield graphically + + //swap order of shield and mob, so that mob is behind shield graphically + // mob[mob.length - 1] = mob[mob.length - 2]; + // mob[mob.length - 2] = me; + } + }, + groupShield(targets, x, y, radius, stiffness = 0.4) { + const nodes = targets.length + mobs.spawn(x, y, 9, radius, "rgba(220,220,255,0.9)"); + let me = mob[mob.length - 1]; + me.stroke = "rgb(220,220,255)"; + Matter.Body.setDensity(me, 0.00001) //very low density to not mess with the original mob's motion + me.frictionAir = 0; + me.shield = true; + me.damageReduction = 0.075 + me.collisionFilter.category = cat.mobShield + me.collisionFilter.mask = cat.bullet; + for (let i = 0; i < nodes; ++i) { + mob[mob.length - i - 2].isShielded = true; + //constrain to all mob nodes in group + consBB[consBB.length] = Constraint.create({ + bodyA: me, + bodyB: mob[mob.length - i - 2], + stiffness: stiffness, + damping: 0.1 + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + me.onDamage = function () { + this.alertNearByMobs(); //makes sure the mob that owns the shield can tell when damage is done + this.fill = `rgba(220,220,255,${0.3 + 0.6 * this.health})` + }; + me.onDeath = function () { + //clear isShielded status from target + for (let j = 0; j < targets.length; j++) { + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].id === targets[j]) mob[i].isShielded = false; + } + } + }; + me.leaveBody = false; + me.isDropPowerUp = false; + me.showHealthBar = false; + mob[mob.length - 1] = mob[mob.length - 1 - nodes]; + mob[mob.length - 1 - nodes] = me; + me.do = function () { + this.checkStatus(); + }; + }, + spawnOrbitals(who, radius, chance = Math.min(0.25 + simulation.difficulty * 0.005)) { + if (Math.random() < chance) { + const len = Math.floor(Math.min(15, 3 + Math.sqrt(simulation.difficulty))) + const speed = (0.003 + 0.004 * Math.random() + 0.002 * Math.sqrt(simulation.difficulty)) * ((Math.random() < 0.5) ? 1 : -1) + const offSet = 6.28 * Math.random() + for (let i = 0; i < len; i++) spawn.orbital(who, radius, i / len * 2 * Math.PI + offSet, speed) + } + }, + orbital(who, radius, phase, speed) { + // for (let i = 0, len = 7; i < len; i++) spawn.orbital(me, radius + 250, 2 * Math.PI / len * i) + mobs.spawn(who.position.x, who.position.y, 8, 12, "rgb(255,0,150)"); + let me = mob[mob.length - 1]; + me.stroke = "transparent"; + Matter.Body.setDensity(me, 0.01); //normal is 0.001 + me.leaveBody = false; + me.isDropPowerUp = false; + me.isBadTarget = true; + me.isUnstable = true; //dies when blocked + me.showHealthBar = false; + me.isOrbital = true; + // me.isShielded = true + me.collisionFilter.category = cat.mobBullet; + me.collisionFilter.mask = cat.bullet; //cat.player | cat.map | cat.body + me.do = function () { + //if host is gone + if (!who || !who.alive) { + this.death(); + return + } + //set orbit + const time = simulation.cycle * speed + phase + const orbit = { + x: Math.cos(time), + y: Math.sin(time) + } + Matter.Body.setPosition(this, Vector.add(Vector.add(who.position, who.velocity), Vector.mult(orbit, radius))) + //damage player + if (Matter.Query.collides(this, [player]).length > 0 && !(m.isCloak && tech.isIntangible) && m.immuneCycle < m.cycle) { + m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage for 30 cycles + const dmg = 0.03 * simulation.dmgScale + m.damage(dmg); + simulation.drawList.push({ //add dmg to draw queue + x: this.position.x, + y: this.position.y, + radius: Math.sqrt(dmg) * 200, + color: simulation.mobDmgColor, + time: simulation.drawTime + }); + this.death(); + } + }; + }, + orbitalBoss(x, y, radius = 70) { + const nodeBalance = Math.random() + const nodes = Math.min(15, Math.floor(2 + 4 * nodeBalance + 0.75 * Math.sqrt(simulation.difficulty))) + mobs.spawn(x, y, nodes, radius, "rgb(255,0,150)"); + let me = mob[mob.length - 1]; + me.isBoss = true; + Matter.Body.setDensity(me, 0.0018 + 0.00015 * Math.sqrt(simulation.difficulty)); //extra dense //normal is 0.001 //makes effective life much larger + me.damageReduction = 0.11 + + me.stroke = "transparent"; //used for drawGhost + me.seeAtDistance2 = 2000000; + me.collisionFilter.mask = cat.bullet | cat.player | cat.body | cat.map + me.memory = Infinity; + me.frictionAir = 0.04; + me.accelMag = 0.0002 + 0.00015 * simulation.accelScale + spawn.shield(me, x, y, 1); + + const rangeInnerVsOuter = Math.random() + let speed = (0.006 + 0.001 * Math.sqrt(simulation.difficulty)) * ((Math.random() < 0.5) ? 1 : -1) + let range = radius + 350 + 200 * rangeInnerVsOuter + nodes * 7 + for (let i = 0; i < nodes; i++) spawn.orbital(me, range, i / nodes * 2 * Math.PI, speed) + const orbitalIndexes = [] //find indexes for all the current nodes + for (let i = 0; i < nodes; i++) orbitalIndexes.push(mob.length - 1 - i) + // add orbitals for each orbital + range = Math.max(60, 100 + 100 * Math.random() - nodes * 3 - rangeInnerVsOuter * 80) + speed = speed * (1.25 + 2 * Math.random()) + const subNodes = Math.max(2, Math.floor(6 - 5 * nodeBalance + 0.5 * Math.sqrt(simulation.difficulty))) + for (let j = 0; j < nodes; j++) { + for (let i = 0, len = subNodes; i < len; i++) spawn.orbital(mob[orbitalIndexes[j]], range, i / len * 2 * Math.PI, speed) + } + for (let i = 0, len = 3 + 0.5 * Math.sqrt(simulation.difficulty); i < len; i++) spawn.spawnOrbitals(me, radius + 40 + 10 * i, 1); + + me.onDeath = function () { + powerUps.spawnBossPowerUp(this.position.x, this.position.y) + }; + me.do = function () { + this.seePlayerByHistory(); + this.checkStatus(); + this.attraction(); + }; + }, + //complex constrained mob templates********************************************************************** + //******************************************************************************************************* + allowShields: true, + nodeGroup( + x, + y, + spawn = "striker", + nodes = Math.min(2 + Math.ceil(Math.random() * (simulation.difficulty + 2)), 8), + //Math.ceil(Math.random() * 3) + Math.min(4,Math.ceil(simulation.difficulty/2)), + radius = Math.ceil(Math.random() * 10) + 18, // radius of each node mob + sideLength = Math.ceil(Math.random() * 100) + 70, // distance between each node mob + stiffness = Math.random() * 0.03 + 0.005 + ) { + this.allowShields = false; //don't want shields on individual group mobs + const angle = 2 * Math.PI / nodes + let targets = [] + for (let i = 0; i < nodes; ++i) { + let whoSpawn = spawn; + if (spawn === "random") { + whoSpawn = this.fullPickList[Math.floor(Math.random() * this.fullPickList.length)]; + } else if (spawn === "randomList") { + whoSpawn = this.pickList[Math.floor(Math.random() * this.pickList.length)]; + } + this[whoSpawn](x + sideLength * Math.sin(i * angle), y + sideLength * Math.cos(i * angle), radius); + targets.push(mob[mob.length - 1].id) //track who is in the group, for shields + } + if (Math.random() < 0.3) { + this.constrain2AdjacentMobs(nodes, stiffness * 2, true); + } else { + this.constrainAllMobCombos(nodes, stiffness); + } + //spawn shield for entire group + if (nodes > 2 && Math.random() < 0.998) { + this.groupShield(targets, x, y, sideLength + 2.5 * radius + nodes * 6 - 25); + } + this.allowShields = true; + }, + lineGroup( + x, + y, + spawn = "striker", + nodes = Math.min(3 + Math.ceil(Math.random() * simulation.difficulty + 2), 8), + //Math.ceil(Math.random() * 3) + Math.min(4,Math.ceil(simulation.difficulty/2)), + radius = Math.ceil(Math.random() * 10) + 17, + l = Math.ceil(Math.random() * 80) + 30, + stiffness = Math.random() * 0.06 + 0.01 + ) { + this.allowShields = false; //don't want shields on individual group mobs + for (let i = 0; i < nodes; ++i) { + let whoSpawn = spawn; + if (spawn === "random") { + whoSpawn = this.fullPickList[Math.floor(Math.random() * this.fullPickList.length)]; + } else if (spawn === "randomList") { + whoSpawn = this.pickList[Math.floor(Math.random() * this.pickList.length)]; + } + this[whoSpawn](x + i * radius + i * l, y, radius); + } + this.constrain2AdjacentMobs(nodes, stiffness); + this.allowShields = true; + }, + //constraints ************************************************************************************************ + //************************************************************************************************************* + constrainAllMobCombos(nodes, stiffness) { + //runs through every combination of last 'num' bodies and constrains them + for (let i = 1; i < nodes + 1; ++i) { + for (let j = i + 1; j < nodes + 1; ++j) { + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - i], + bodyB: mob[mob.length - j], + stiffness: stiffness + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + } + }, + constrain2AdjacentMobs(nodes, stiffness, loop = false, damping = 0) { + //runs through every combination of last 'num' bodies and constrains them + for (let i = 0; i < nodes - 1; ++i) { + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - i - 1], + bodyB: mob[mob.length - i - 2], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + if (nodes > 2) { + for (let i = 0; i < nodes - 2; ++i) { + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - i - 1], + bodyB: mob[mob.length - i - 3], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + } + //optional connect the tail to head + if (loop && nodes > 3) { + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - 1], + bodyB: mob[mob.length - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - 2], + bodyB: mob[mob.length - nodes], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + consBB[consBB.length] = Constraint.create({ + bodyA: mob[mob.length - 1], + bodyB: mob[mob.length - nodes + 1], + stiffness: stiffness, + damping: damping + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + } + }, + constraintPB(x, y, bodyIndex, stiffness) { + cons[cons.length] = Constraint.create({ + pointA: { + x: x, + y: y + }, + bodyB: body[bodyIndex], + stiffness: stiffness + }); + Composite.add(engine.world, cons[cons.length - 1]); + }, + constraintBB(bodyIndexA, bodyIndexB, stiffness) { + consBB[consBB.length] = Constraint.create({ + bodyA: body[bodyIndexA], + bodyB: body[bodyIndexB], + stiffness: stiffness + }); + Composite.add(engine.world, consBB[consBB.length - 1]); + }, + // body and map spawns ****************************************************************************** + //********************************************************************************************** + wireHead() { + //not a mob, just a graphic for level 1 + const breakingPoint = 1300 + mobs.spawn(breakingPoint, -100, 0, 7.5, "transparent"); + let me = mob[mob.length - 1]; + me.collisionFilter.category = cat.body; + me.collisionFilter.mask = cat.map; + me.inertia = Infinity; + me.g = 0.0004; //required for gravity + me.restitution = 0; + me.stroke = "transparent" + me.freeOfWires = false; + me.frictionStatic = 1; + me.friction = 1; + me.frictionAir = 0.01; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.isBadTarget = true; + me.isUnblockable = true; + + me.do = function () { + let wireX = -50; + let wireY = -1000; + if (this.freeOfWires) { + this.gravity(); + } else { + if (m.pos.x > breakingPoint || simulation.isCheating) { + this.freeOfWires = true; + this.fill = "#000" + this.force.x += -0.003; + player.force.x += 0.06; + // player.force.y -= 0.15; + //remove difficulty power up if the wire breaks to prevent getting power ups and then making the difficulty harder + for (let i = 0; i < powerUp.length; ++i) { + if (powerUp[i].name === "difficulty") { + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + } + } + + } + + //player is extra heavy from wires + Matter.Body.setVelocity(player, { x: player.velocity.x, y: player.velocity.y + 0.3 }) + + //player friction from the wires + if (m.pos.x > 700 && player.velocity.x > -2) { + let wireFriction = 0.75 * Math.min(0.6, Math.max(0, 100 / (breakingPoint - m.pos.x))); + if (!m.onGround) wireFriction *= 3 + Matter.Body.setVelocity(player, { + x: player.velocity.x - wireFriction, + y: player.velocity.y + }) + } + //move to player + Matter.Body.setPosition(this, { x: m.pos.x + (42 * Math.cos(m.angle + Math.PI)), y: m.pos.y + (42 * Math.sin(m.angle + Math.PI)) }) + } + //draw wire + ctx.beginPath(); + ctx.moveTo(wireX, wireY); + ctx.quadraticCurveTo(wireX, 0, this.position.x, this.position.y); + if (!this.freeOfWires) ctx.lineTo(m.pos.x + (30 * Math.cos(m.angle + Math.PI)), m.pos.y + (30 * Math.sin(m.angle + Math.PI))); + ctx.lineCap = "butt"; + ctx.lineWidth = 15; + ctx.strokeStyle = "#000"; + ctx.stroke(); + ctx.lineCap = "round"; + }; + }, + wireKnee() { + //not a mob, just a graphic for level 1 + const breakingPoint = 1425 + mobs.spawn(breakingPoint, -100, 0, 2, "transparent"); + let me = mob[mob.length - 1]; + //touch nothing + me.collisionFilter.category = cat.body; + me.collisionFilter.mask = cat.map; + me.g = 0.0003; //required for gravity + // me.restitution = 0; + me.stroke = "transparent" + // me.inertia = Infinity; + me.restitution = 0; + me.freeOfWires = false; + me.frictionStatic = 1; + me.friction = 1; + me.frictionAir = 0.01; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.isBadTarget = true; + me.isUnblockable = true; + + me.do = function () { + let wireX = -50 - 20; + let wireY = -1000; + + if (this.freeOfWires) { + this.gravity(); + } else { + if (m.pos.x > breakingPoint || simulation.isCheating) { + this.freeOfWires = true; + this.force.x -= 0.0004; + this.fill = "#222"; + } + //move mob to player + m.calcLeg(0, 0); + Matter.Body.setPosition(this, { + x: m.pos.x + m.flipLegs * m.knee.x - 5, + y: m.pos.y + m.knee.y + }) + } + //draw wire + ctx.beginPath(); + ctx.moveTo(wireX, wireY); + ctx.quadraticCurveTo(wireX, 0, this.position.x, this.position.y); + ctx.lineWidth = 5; + ctx.strokeStyle = "#222"; + ctx.lineCap = "butt"; + ctx.stroke(); + ctx.lineCap = "round"; + }; + }, + wireKneeLeft() { + //not a mob, just a graphic for level 1 + const breakingPoint = 1400 + mobs.spawn(breakingPoint, -100, 0, 2, "transparent"); + let me = mob[mob.length - 1]; + //touch nothing + me.collisionFilter.category = cat.body; + me.collisionFilter.mask = cat.map; + me.g = 0.0003; //required for gravity + // me.restitution = 0; + me.stroke = "transparent" + // me.inertia = Infinity; + me.restitution = 0; + me.freeOfWires = false; + me.frictionStatic = 1; + me.friction = 1; + me.frictionAir = 0.01; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.isBadTarget = true; + me.isUnblockable = true; + + me.do = function () { + let wireX = -50 - 35; + let wireY = -1000; + + if (this.freeOfWires) { + this.gravity(); + } else { + if (m.pos.x > breakingPoint || simulation.isCheating) { + this.freeOfWires = true; + this.force.x += -0.0003; + this.fill = "#333"; + } + //move mob to player + m.calcLeg(Math.PI, -3); + Matter.Body.setPosition(this, { + x: m.pos.x + m.flipLegs * m.knee.x - 5, + y: m.pos.y + m.knee.y + }) + } + //draw wire + ctx.beginPath(); + ctx.moveTo(wireX, wireY); + ctx.quadraticCurveTo(wireX, 0, this.position.x, this.position.y); + ctx.lineWidth = 5; + ctx.lineCap = "butt"; + ctx.strokeStyle = "#333"; + ctx.stroke(); + ctx.lineCap = "round"; + }; + }, + wireFoot() { + //not a mob, just a graphic for level 1 + const breakingPoint = 1350 + mobs.spawn(breakingPoint, -100, 0, 2, "transparent"); + let me = mob[mob.length - 1]; + //touch nothing + me.collisionFilter.category = cat.body; + me.collisionFilter.mask = cat.map; + me.g = 0.0003; //required for gravity + me.restitution = 0; + me.stroke = "transparent" + // me.inertia = Infinity; + me.freeOfWires = false; + // me.frictionStatic = 1; + // me.friction = 1; + me.frictionAir = 0.01; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.isBadTarget = true; + me.isUnblockable = true; + + me.do = function () { + let wireX = -50 + 16; + let wireY = -1000; + + if (this.freeOfWires) { + this.gravity(); + } else { + if (m.pos.x > breakingPoint || simulation.isCheating) { + this.freeOfWires = true; + this.force.x += -0.0006; + this.fill = "#111"; + } + //move mob to player + m.calcLeg(0, 0); + Matter.Body.setPosition(this, { + x: m.pos.x + m.flipLegs * m.foot.x - 5, + y: m.pos.y + m.foot.y - 1 + }) + } + //draw wire + ctx.beginPath(); + ctx.moveTo(wireX, wireY); + ctx.quadraticCurveTo(wireX, 0, this.position.x, this.position.y); + ctx.lineWidth = 5; + ctx.lineCap = "butt"; + ctx.strokeStyle = "#111"; + ctx.stroke(); + ctx.lineCap = "round"; + }; + }, + wireFootLeft() { + //not a mob, just a graphic for level 1 + const breakingPoint = 1325 + mobs.spawn(breakingPoint, -100, 0, 2, "transparent"); + let me = mob[mob.length - 1]; + //touch nothing + me.collisionFilter.category = cat.body; + me.collisionFilter.mask = cat.map; + me.g = 0.0003; //required for gravity + me.restitution = 0; + me.stroke = "transparent" + // me.inertia = Infinity; + me.freeOfWires = false; + // me.frictionStatic = 1; + // me.friction = 1; + me.frictionAir = 0.01; + me.isDropPowerUp = false; + me.showHealthBar = false; + me.isBadTarget = true; + me.isUnblockable = true; + + me.do = function () { + let wireX = -50 + 26; + let wireY = -1000; + + if (this.freeOfWires) { + this.gravity(); + } else { + if (m.pos.x > breakingPoint || simulation.isCheating) { + this.freeOfWires = true; + this.force.x += -0.0005; + this.fill = "#222"; + } + //move mob to player + m.calcLeg(Math.PI, -3); + Matter.Body.setPosition(this, { + x: m.pos.x + m.flipLegs * m.foot.x - 5, + y: m.pos.y + m.foot.y - 1 + }) + } + //draw wire + ctx.beginPath(); + ctx.moveTo(wireX, wireY); + ctx.quadraticCurveTo(wireX, 0, this.position.x, this.position.y); + ctx.lineWidth = 5; + ctx.strokeStyle = "#222"; + ctx.lineCap = "butt"; + ctx.stroke(); + ctx.lineCap = "round"; + }; + }, + boost(x, y, height = 1000) { + spawn.mapVertex(x + 50, y + 35, "120 40 -120 40 -50 -40 50 -40"); + level.addQueryRegion(x, y - 20, 100, 20, "boost", [ + [player], body, mob, powerUp, bullet + ], -1.21 * Math.sqrt(Math.abs(height))); + }, + blockDoor(x, y, blockSize = 60) { + spawn.mapRect(x, y - 290, 40, 60); // door lip + spawn.mapRect(x, y, 40, 50); // door lip + for (let i = 0; i < 4; ++i) { + spawn.bodyRect(x + 5, y - 260 + i * blockSize + i * 3, 30, blockSize); + } + }, + debris(x, y, width, number = Math.floor(2 + Math.random() * 9)) { + for (let i = 0; i < number; ++i) { + if (Math.random() < 0.15) { + powerUps.chooseRandomPowerUp(x + Math.random() * width, y); + } else { + const size = 18 + Math.random() * 25; + spawn.bodyRect(x + Math.random() * width, y, size * (0.6 + Math.random()), size * (0.6 + Math.random()), 1); + // body[body.length] = Bodies.rectangle(x + Math.random() * width, y, size * (0.6 + Math.random()), size * (0.6 + Math.random())); + } + } + }, + bodyRect(x, y, width, height, chance = 1, properties = { friction: 0.05, frictionAir: 0.001 }) { //this is the command that adds blocks to the world in the middle of a level + if (Math.random() < chance) { + body[body.length] = Bodies.rectangle(x + width / 2, y + height / 2, width, height, properties); + const who = body[body.length - 1] + who.collisionFilter.category = cat.body; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + Composite.add(engine.world, who); //add to world + who.classType = "body" + } + }, + bodyVertex(x, y, vector, properties) { //this is the command that adds blocks to the world in the middle of a level + body[body.length] = Matter.Bodies.fromVertices(x, y, Vertices.fromPath(vector), properties); + const who = body[body.length - 1] + who.collisionFilter.category = cat.body; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + Composite.add(engine.world, who); //add to world + who.classType = "body" + }, + mapRect(x, y, width, height, properties) { //adds rectangle to map array + map[map.length] = Bodies.rectangle(x + width / 2, y + height / 2, width, height, properties); + }, + mapVertex(x, y, vector, properties) { //adds shape to map array + map[map.length] = Matter.Bodies.fromVertices(x, y, Vertices.fromPath(vector), properties); + }, + mapRectNow(x, y, width, height, properties, isRedrawMap = true) { //adds rectangle to map array in the middle of a level + map[map.length] = Bodies.rectangle(x + width / 2, y + height / 2, width, height, properties); + const who = map[map.length - 1] + who.collisionFilter.category = cat.map; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(who, true); //make static + Composite.add(engine.world, who); //add to world + if (isRedrawMap) simulation.draw.setPaths() + }, + mapVertexNow(x, y, vector, properties, isRedrawMap = true) { //adds shape to map array in the middle of a level + map[map.length] = Matter.Bodies.fromVertices(x, y, Vertices.fromPath(vector), properties); + const who = map[map.length - 1] + who.collisionFilter.category = cat.map; + who.collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet; + Matter.Body.setStatic(who, true); //make static + Composite.add(engine.world, who); //add to world + if (isRedrawMap) simulation.draw.setPaths() //this is a bit slow on processing so maybe it's better to run after you spawn several different shapes + }, + //complex map templates + spawnBuilding(x, y, w, h, leftDoor, rightDoor, walledSide) { + this.mapRect(x, y, w, 25); //roof + this.mapRect(x, y + h, w, 35); //ground + if (walledSide === "left") { + this.mapRect(x, y, 25, h); //wall left + } else { + this.mapRect(x, y, 25, h - 150); //wall left + if (leftDoor) { + this.bodyRect(x + 5, y + h - 150, 15, 150, this.propsFriction); //door left + } + } + if (walledSide === "right") { + this.mapRect(x - 25 + w, y, 25, h); //wall right + } else { + this.mapRect(x - 25 + w, y, 25, h - 150); //wall right + if (rightDoor) { + this.bodyRect(x + w - 20, y + h - 150, 15, 150, this.propsFriction); //door right + } + } + }, + spawnStairs(x, y, num, w, h, stepRight) { + w += 50; + if (stepRight) { + for (let i = 0; i < num; i++) { + this.mapRect(x - (w / num) * (1 + i), y - h + (i * h) / num, w / num + 50, h - (i * h) / num + 50); + } + } else { + for (let i = 0; i < num; i++) { + this.mapRect(x + (i * w) / num, y - h + (i * h) / num, w / num + 50, h - (i * h) / num + 50); + } + } + }, + //pre-made property options************************************************************************************* + //************************************************************************************************************* + //Object.assign({}, propsHeavy, propsBouncy, propsNoRotation) //will combine properties into a new object + propsFriction: { + friction: 0.5, + frictionAir: 0.02, + frictionStatic: 1 + }, + propsFrictionMedium: { + friction: 0.15, + frictionStatic: 1 + }, + propsBouncy: { + friction: 0, + frictionAir: 0, + frictionStatic: 0, + restitution: 1 + }, + propsSlide: { + friction: 0.003, + frictionStatic: 0.4, + restitution: 0, + density: 0.002 + }, + propsLight: { + density: 0.001 + }, + propsOverBouncy: { + friction: 0, + frictionAir: 0, + frictionStatic: 0, + restitution: 1.05 + }, + propsHeavy: { + density: 0.01 //default density is 0.001 + }, + propsIsNotHoldable: { + isNotHoldable: true + }, + propsNoRotation: { + inertia: Infinity //prevents rotation + }, + propsHoist: { + inertia: Infinity, //prevents rotation + frictionAir: 0.001, + friction: 0.0001, + frictionStatic: 0, + restitution: 0, + isNotHoldable: true + // density: 0.0001 + }, + propsDoor: { + density: 0.001, //default density is 0.001 + friction: 0, + frictionAir: 0.03, + frictionStatic: 0, + restitution: 0 + }, + sandPaper: { + friction: 1, + frictionStatic: 1, + restitution: 0 + } +}; \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/js/tech.js b/WebGames-master/WebGames-master/n-gon-master/js/tech.js new file mode 100644 index 00000000..778fa1be --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/js/tech.js @@ -0,0 +1,12239 @@ +const tech = { + totalCount: null, + removeCount: 0, + resetAllTech() { + for (let i = 0, len = tech.tech.length; i < len; i++) { + tech.tech[i].isLost = false + tech.tech[i].isBanished = false + tech.tech[i].remove(); + tech.tech[i].count = 0 + if (tech.tech[i].isJunk) { + tech.tech[i].frequency = 0 + } else if (tech.tech[i].frequencyDefault) { + tech.tech[i].frequency = tech.tech[i].frequencyDefault + } else { + tech.tech[i].frequency = 1 + } + if (tech.tech[i].name === "heals" || tech.tech[i].name === "ammo" || tech.tech[i].name === "research") tech.tech[i].value = tech.tech[i].defaultValue + } + m.resetSkin(); + tech.removeCount = 0; + tech.pauseEjectTech = 1; //used in paradigm shift + lore.techCount = 0; + tech.duplication = 0; + tech.damage = 1 + tech.junkChance = 0; + tech.extraMaxHealth = 0; + tech.totalCount = 0; + simulation.updateTechHUD(); + simulation.updateGunHUD(); + }, + removeTech(index = 'random') { + if (index === 'random') { + const have = [] //find which tech you have + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].count > 0 && !tech.tech[i].isInstant) have.push(i) + } + if (have.length) { + index = have[Math.floor(Math.random() * have.length)] + } else { + return 0 //if none found don't remove any tech + } + } else if (isNaN(index)) { //find index by name + let found = false; + for (let i = 0; i < tech.tech.length; i++) { + if (index === tech.tech[i].name) { + index = i; + found = true; + break; + } + } + if (!found) return 0 //if name not found don't remove any tech + } + if (tech.tech[index].count === 0) return 0 + const totalRemoved = tech.tech[index].count + simulation.inGameConsole(`tech.removeTech("${tech.tech[index].name}")`, 360) + tech.tech[index].remove(); + tech.removeCount += totalRemoved + tech.tech[index].count = 0; + tech.totalCount -= totalRemoved + // simulation.updateTechHUD(); + tech.tech[index].isLost = true + simulation.updateTechHUD(); + return totalRemoved //return the total number of tech removed + }, + junkChance: 0, + addJunkTechToPool(percent) { //percent is number between 0-1 + tech.junkChance += percent + if (tech.junkChance < 0.001 || tech.junkChance === undefined) tech.junkChance = 0 + if (tech.junkChance > 1) tech.junkChance = 1 + simulation.inGameConsole(`+${(100 * percent).toFixed(0)}% JUNKtech chance (${(100 * tech.junkChance).toFixed(0)}% total chance)`) + // tech.junkChance += (1 - tech.junkChance) * percent + return percent + + //make an array for possible junk tech to add + // let options = []; + // for (let i = 0; i < tech.tech.length; i++) { + // if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].isJunk) options.push(i); + // } + // if (options.length) { + // let countNonJunk = 0 // count total non junk tech + // for (let i = 0, len = tech.tech.length; i < len; i++) { + // if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isJunk) countNonJunk += tech.tech[i].frequency + // } + // const num = Math.ceil(percent * countNonJunk) //scale number added + // for (let i = 0; i < num; i++) tech.tech[options[Math.floor(Math.random() * options.length)]].frequency++ //add random array options to tech pool + // simulation.inGameConsole(`tech.tech.push(${num.toFixed(0)} JUNK)`) + // return num + // } else { + // return 0 + // } + }, + removeJunkTechFromPool(percent) { + // for (let j = 0; j < num; j++) { + // for (let i = 0; i < tech.tech.length; i++) { + // if (tech.tech[i].isJunk && tech.tech[i].frequency > 0 && tech.tech[i].count < tech.tech[i].maxCount) { + // tech.tech[i].frequency-- + // break + // } + // } + // } + + // if (percent > 0) { + // tech.junkChance = (tech.junkChance - percent) / (1 - percent) + // if (tech.junkChance < 0.001 || tech.junkChance === undefined) tech.junkChance = 0 + // } + tech.junkChance -= percent + if (tech.junkChance < 0.001 || tech.junkChance === undefined) tech.junkChance = 0 + if (tech.junkChance > 1) tech.junkChance = 1 + }, + giveTech(index = 'random') { + if (index === 'random') { + let options = []; + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].count < tech.tech[i].maxCount && tech.tech[i].allowed() && !tech.tech[i].isJunk && !tech.tech[i].isLore && !tech.tech[i].isBadRandomOption) options.push(i); + } + // give a random tech from the tech I don't have + if (options.length > 0) { + let newTech = options[Math.floor(Math.random() * options.length)] + simulation.inGameConsole(`tech.giveTech("${tech.tech[newTech].name}") //random tech`); + tech.giveTech(newTech) + } + } else { + if (isNaN(index)) { //find index by name + let found = false; + for (let i = 0; i < tech.tech.length; i++) { + if (index === tech.tech[i].name) { + index = i; + found = true; + break; + } + } + if (!found) return //if name not found don't give any tech + } + if (tech.isMetaAnalysis && tech.tech[index].isJunk) { + simulation.inGameConsole(`//tech: meta-analysis replaced junk tech with random tech`); + tech.giveTech('random') + for (let i = 0; i < 2; i++) powerUps.spawn(m.pos.x + 40 * Math.random(), m.pos.y + 40 * Math.random(), "research"); + return + } + + if (tech.tech[index].isLost) tech.tech[index].isLost = false; //give specific tech + if (tech.isBanish && tech.tech[index].isBanished) tech.tech[index].isBanished = false //stops the bug where you can't gets stacks of tech you take with decoherence, I think + if (tech.isDamageFieldTech && tech.tech[index].isFieldTech) { + tech.damage *= 1.15 + // simulation.inGameConsole(`damage *= ${1.05}`) + simulation.inGameConsole(`tech.damage *= ${1.1} //hidden-variable theory`); + } + tech.tech[index].effect(); //give specific tech + tech.tech[index].count++ + if (!tech.tech[index].isInstant) tech.totalCount++ //used in power up randomization + if (tech.isWiki) { + async function getWikipediaIntro(subject) { + // const searchEndpoint = `https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&explaintext&titles=${encodeURIComponent(subject).replace(/' /g, '%27')}&format=json&origin=*`; + const searchEndpoint = `https://en.wikipedia.org/w/api.php?action=opensearch&search=${encodeURIComponent(subject).replace(/' /g, '%27')}&limit=1&namespace=0&format=json&origin=*`; + try { + // Perform a search to get the closest matching title + const searchResponse = await fetch(searchEndpoint); + const searchData = await searchResponse.json(); + if (searchData[1].length === 0) throw new Error('No matching pages found'); + const closestTitle = searchData[1][0]; + // Use the closest matching title to get the page content + const contentEndpoint = `https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&explaintext&titles=${encodeURIComponent(closestTitle)}&format=json&origin=*`; + const contentResponse = await fetch(contentEndpoint); + const contentData = await contentResponse.json(); + const pages = contentData.query.pages; + const pageId = Object.keys(pages)[0]; + return pages[pageId].extract + } catch (error) { + console.error('Error fetching Wikipedia intro:', error); + } + } + const subject = tech.tech[index].name + getWikipediaIntro(subject).then(intro => { + let tab = window.open(`https://en.wikipedia.org/w/index.php?search=${encodeURIComponent(subject).replace(/' /g, '%27')}&title=Special:Search`, "_blank"); + if (tab) { + let checkInterval = setInterval(() => { + if (tab.closed) { + clearInterval(checkInterval); // Stop checking once the tab is closed + + const introArray = intro.split(" ") + const wordLimit = 7 + const wordNumber = Math.ceil(Math.random() * wordLimit) + const answer = prompt(`On the wikipedia page for ${subject} what is word ${wordNumber + 1}?`) + console.log(introArray[wordNumber]) + if (introArray[wordNumber]) { + if (answer && answer.toLowerCase() === introArray[wordNumber].toLowerCase().replace(/[^a-zA-Z]/g, '')) { + powerUps.spawnDelay("research", 4) + simulation.inGameConsole(`correct!`, 360) + } else { + simulation.inGameConsole(`${answer} is wrong, it was ${introArray[wordNumber]}`, 360) + } + let text = `"` + for (let i = 0; i < wordLimit + 3; i++) { + if (i === wordNumber) { + text += `${introArray[i]} ` + } else { + text += `${introArray[i]} ` + } + } + simulation.inGameConsole(text + `..."`, 360) + } else { + simulation.inGameConsole(`hmmm I'm not sure the answer, so I'll say it's correct!`, 360) + powerUps.spawnDelay("research", 3) + } + } + }, 1000); // Check every 1 second + setTimeout(() => { + tab.close(); + }, 7000); // Close the tab after 7 seconds + } + }); + } + + + //move new tech to the top of the tech list + requestAnimationFrame(() => { + if (index > 0 && !build.isExperimentSelection) { + const [item] = tech.tech.splice(index, 1); // Remove the element from the array + tech.tech.unshift(item); // Add the element to the front of the array + } + simulation.updateTechHUD(); + }) + } + }, + setCheating() { + if (!simulation.isCheating) { + simulation.isCheating = true; + document.title = "n-gon:" + level.levelAnnounce(); + lore.techCount = 0; + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isLore) { + tech.tech[i].frequency = 0; + tech.tech[i].count = 0; + } + } + console.log('cheating') + sound.tone(250) + sound.tone(300) + sound.tone(375) + } + }, + haveGunCheck(name, needActive = true) { + if (b.activeGun === null || b.activeGun === undefined) return false + if (build.isExperimentSelection || !needActive) { + for (i = 0, len = b.inventory.length; i < len; i++) { + if (b.guns[b.inventory[i]].name === name) return true + } + return false + } else { //must be holding gun, this is the standard while playing + return b.inventory.length > 0 && b.guns[b.activeGun].name === name + } + + // if (build.isExperimentSelection || !needActive) { + // for (i = 0, len = b.inventory.length; i < len; i++) { + // if (b.guns[b.inventory[i]].name === name) return true + // } + // return false + // } else { //must be holding gun, this is the standard while playing + // return b.inventory.length > 0 && b.guns[b.activeGun].name === name + // } + }, + hasExplosiveDamageCheck() { + return tech.haveGunCheck("missiles") || (m.fieldMode === 4 && simulation.molecularMode === 1) || tech.missileBotCount > 0 || tech.isBoomBotUpgrade || tech.isIncendiary || tech.isPulseLaser || tech.isTokamak || (tech.haveGunCheck("grenades") && !tech.isNeutronBomb) + }, + damage: 1, //used for tech changes to player damage that don't have complex conditions + damageFromTech() { + let dmg = tech.damage * m.fieldDamage + if (level.isNoDamage && (m.cycle - 180 < level.noDamageCycle)) dmg *= 0.3 + if (tech.isMaxHealthDamage && m.health === m.maxHealth) dmg *= 2 + if (tech.noDefenseSettingDamage && m.defense() === 1) dmg *= 2.5 + if (tech.isImmunityDamage && m.immuneCycle > m.cycle) dmg *= 3 + if (tech.isPowerUpDamage) dmg *= 1 + 0.07 * powerUp.length + if (tech.isDamageCooldown) dmg *= m.lastKillCycle + tech.isDamageCooldownTime > m.cycle ? 0.4 : 4 + if (tech.isDamageAfterKillNoRegen && m.lastKillCycle + 300 > m.cycle) dmg *= 2 + if (tech.isDivisor && b.activeGun !== undefined && b.activeGun !== null && b.guns[b.activeGun].ammo % 3 === 0) dmg *= 1.9 + if (tech.isNoGroundDamage) dmg *= m.onGround ? 0.9 : 2 + if (tech.isDilate) dmg *= 1.9 + 1.1 * Math.sin(m.cycle * 0.01) + if (tech.isGunChoice) dmg *= 1 + 0.4 * b.inventory.length + if (powerUps.boost.endCycle > simulation.cycle) dmg *= 1 + powerUps.boost.damage + if (m.coupling && (m.fieldMode === 0 || m.fieldMode === 5)) dmg *= 1 + 0.025 * m.coupling + if (tech.isVerlet) dmg *= 3 + if (tech.isTechDebt) dmg *= tech.totalCount > 20 ? Math.pow(0.85, tech.totalCount - 20) : 4 - 0.15 * tech.totalCount + if (tech.isAnthropicDamage && tech.isDeathAvoidedThisLevel) dmg *= 2.71828 + if (tech.isDupDamage) dmg *= 1 + Math.min(1, tech.duplicationChance()) + if (tech.isDamageForGuns) dmg *= 1 + 0.22 * Math.max(0, b.inventory.length - 1) + if (tech.isOneGun && b.inventory.length < 2) dmg *= 1.3 + if (tech.isAcidDmg && m.health > 1) dmg *= 1.35; + if (tech.isRerollDamage) dmg *= 1 + Math.max(0, 0.05 * powerUps.research.count) + if (tech.isBotDamage) dmg *= 1 + 0.04 * b.totalBots() + if (tech.restDamage > 1 && player.speed < 1) dmg *= tech.restDamage + if (tech.isLowEnergyDamage) dmg *= 1 + 0.6 * Math.max(0, m.maxEnergy - m.energy) + if (tech.energyDamage) dmg *= 1 + m.energy * 0.23 * tech.energyDamage; + if (tech.isDamageFromBulletCount) dmg *= 1 + bullet.length * 0.01 + if (tech.isNoFireDamage && m.cycle > m.fireCDcycle + 120) dmg *= 2 + if (tech.isSpeedDamage) dmg *= 1 + Math.min(2, ((tech.speedAdded + player.speed) * 0.033))//1 + Math.min(1, (tech.speedAdded + player.speed) * 0.0193) + if (tech.isAxion && tech.isHarmDarkMatter) dmg *= ((tech.isMoveDarkMatter || tech.isNotDarkMatter) ? 3.2 : 2) + if (tech.isHarmDamage && m.lastHarmCycle + 480 > m.cycle) dmg *= 3; + if (tech.lastHitDamage && m.lastHit) dmg *= 1 + tech.lastHitDamage * m.lastHit + // if (tech.isLowHealthDmg) dmg *= 1 + 0.6 * Math.max(0, 1 - (tech.isEnergyHealth ? m.energy : m.health)) + if (tech.isLowHealthDmg) dmg *= 1 + 0.6 * Math.max(0, (tech.isEnergyHealth ? m.maxEnergy - m.energy : m.maxHealth - m.health)) + if (tech.isJunkDNA) dmg *= 1 + 2 * (tech.junkChance + level.junkAdded) + return dmg + }, + duplicationChance() { + if (level.isNoDuplicate) return 0 + return Math.min(1, Math.max(0, (tech.isPowerUpsVanish ? 0.13 : 0) + (tech.isStimulatedEmission ? 0.2 : 0) + tech.duplication + tech.duplicateChance + 0.05 * tech.isExtraGunField + m.duplicateChance + tech.fieldDuplicate + 0.08 * tech.isDuplicateMobs + 0.03 * tech.isMassProduction + 0.04 * tech.isHealAttract + tech.cloakDuplication + (tech.isAnthropicTech && tech.isDeathAvoidedThisLevel ? 0.6 : 0) + 0.06 * tech.isDupEnergy)) + }, + setTechFrequency(name, frequency) { + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].name === name) tech.tech[i].frequency = frequency + } + }, + setBotTechFrequency(f = 0) { + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isBotTech) { + switch (tech.tech[i].name) { + case "dynamo-bot": + tech.tech[i].frequency = f + break; + case "orbital-bot": + tech.tech[i].frequency = f + break; + case "laser-bot": + tech.tech[i].frequency = f + break; + case "boom-bot": + tech.tech[i].frequency = f + break; + case "foam-bot": + tech.tech[i].frequency = f + break; + case "nail-bot": + tech.tech[i].frequency = f + break; + } + } + } + }, + tech: [{ + name: "tungsten carbide", + description: "+500 maximum health
lose health after hard landings", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isSkin: true, + allowed() { + return !m.isAltSkin + }, + requires: "not skin", + effect() { + tech.isFallingDamage = true; + m.setMaxHealth(); + m.addHealth(5 / simulation.healScale) + m.skin.tungsten() + }, + remove() { + tech.isFallingDamage = false; + m.setMaxHealth(); + if (this.count) m.resetSkin(); + } + }, + { + name: "nitinol", + description: "1.3x movement and jumping
0.17 seconds of coyote time", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isSkin: true, + allowed() { + return !m.isAltSkin + }, + requires: "not skinned", + effect() { + m.skin.mech(); + m.setMovement() + }, + remove() { + if (this.count) m.resetSkin(); + } + }, + { + name: "Higgs mechanism", + description: "4x fire rate
while firing your position is fixed", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isSkin: true, + allowed() { + return !m.isAltSkin && !m.isShipMode && !tech.isAlwaysFire + }, + requires: "not skinned, ship mode, automatic", + effect() { + tech.isFireMoveLock = true; + b.setFireCD(); + b.setFireMethod(); + m.skin.strokeGap(); + }, + remove() { + tech.isFireMoveLock = false + if (tech.isFireMoveLock) { + b.setFireCD(); + b.setFireMethod(); + if (this.count) m.resetSkin(); + } + } + }, + { + name: "Verlet integration", + description: "3x damage
after mobs die advance time 0.5 seconds", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isSkin: true, + allowed() { + return !m.isAltSkin + }, + requires: "not skinned", + effect() { + tech.isVerlet = true + m.skin.verlet(); + }, + remove() { + tech.isVerlet = false + if (this.count) m.resetSkin(); + } + }, + { + name: "Hilbert space", + description: "4x damage
after a collision enter an alternate reality", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isAltRealityTech: true, + isSkin: true, + allowed() { + return !m.isAltSkin && !tech.isResearchReality && !tech.isSwitchReality + }, + requires: "not skinned, Ψ(t) collapse, many-worlds", + damage: 4, + effect() { + m.skin.anodize(); + tech.damage *= this.damage + tech.isCollisionRealitySwitch = true; + }, + remove() { + tech.isCollisionRealitySwitch = false; + if (this.count && m.alive) { + tech.damage /= this.damage + m.resetSkin(); + } + } + }, + { + name: "aperture", + description: "every 4 seconds your damage cycles
between 0.8x and 3x damage", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isSkin: true, + allowed() { + return !m.isAltSkin + }, + requires: "not skinned", + effect() { + tech.isDilate = true + m.skin.dilate() + }, + remove() { + tech.isDilate = false + if (this.count) m.resetSkin(); + } + }, + { + name: "diaphragm", + description: "every 4 seconds your damage taken cycles
between 0.9x and 0.2x damage taken", + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isSkin: true, + allowed() { + return tech.isDilate + }, + requires: "aperture", + effect() { + tech.isDiaphragm = true + m.resetSkin(); + m.skin.dilate2() + }, + remove() { + tech.isDiaphragm = false + if (this.count) m.resetSkin(); + } + }, + { + name: "mass-energy equivalence", + description: `energy protects you instead of health`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isSkin: true, + allowed() { + return !m.isAltSkin && !tech.isPiezo && !tech.isRewindAvoidDeath && !tech.isAnnihilation //&& !tech.isAmmoFromHealth && !tech.isRewindGun + }, + requires: "not piezoelectricity, CPT, annihilation", + effect() { + m.health = 0 + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + document.getElementById("dmg").style.backgroundColor = "#0cf"; + tech.isEnergyHealth = true; + simulation.mobDmgColor = "rgba(0, 255, 255,0.6)" //"#0cf" + m.displayHealth(); + m.lastCalculatedDefense = 0 //this triggers a redraw of the defense bar + m.skin.energy(); + }, + remove() { + if (this.count > 0) { + tech.isEnergyHealth = false; + if (tech.isEnergyHealth) { + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + } else if (!level.isHideHealth) { + document.getElementById("health").style.display = "inline" + document.getElementById("health-bg").style.display = "inline" + } + document.getElementById("dmg").style.backgroundColor = "#f67"; + m.health = Math.max(Math.min(m.maxHealth, m.energy), 0.1); + simulation.mobDmgColor = "rgba(255,0,0,0.7)" + m.displayHealth(); + m.lastCalculatedDefense = 0 //this triggers a redraw of the defense bar + m.resetSkin(); + } + tech.isEnergyHealth = false; + } + }, + { + name: "1st ionization energy", + link: `1st ionization energy`, + descriptionFunction() { + return `convert current and future
into

give +${14 * tech.largerHeals * (tech.isHalfHeals ? 0.5 : 1)} maximum energy` + }, + maxCount: 1, + count: 0, + frequency: 5, + frequencyDefault: 5, + allowed() { + return tech.isEnergyHealth && !tech.isOverHeal + }, + requires: "mass-energy equivalence, not quenching", + effect() { + powerUps.healGiveMaxEnergy = true; //tech.healMaxEnergyBonus given from heal power up + powerUps.heal.color = "#ff0" //"#0ae" + for (let i = 0; i < powerUp.length; i++) { //find active heal power ups and adjust color live + if (powerUp[i].name === "heal") powerUp[i].color = powerUps.heal.color + } + }, + remove() { + powerUps.healGiveMaxEnergy = false; + // tech.healMaxEnergyBonus = 0 + powerUps.heal.color = "#0eb" + for (let i = 0; i < powerUp.length; i++) { //find active heal power ups and adjust color live + if (powerUp[i].name === "heal") powerUp[i].color = powerUps.heal.color + } + } + }, + { + name: "depolarization", + descriptionFunction() { + return `4x damage, but if a mob dies
0.4x damage for ${(tech.isDamageCooldownTime / 60).toFixed(1)} seconds instead` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isSkin: true, + allowed() { + return !m.isAltSkin + }, + requires: "not skinned", + effect() { + m.skin.polar(); + tech.isDamageCooldown = true; + }, + remove() { + tech.isDamageCooldown = false; + if (this.count) m.resetSkin(); + } + }, + { + name: "repolarization", + descriptionFunction() { + return `the damage from depolarization
resets 1.25 seconds sooner after a mob dies` + }, + maxCount: 3, + count: 0, + frequency: 4, + frequencyDefault: 4, + allowed() { + return tech.isDamageCooldown + }, + requires: "depolarization", + effect() { + tech.isDamageCooldownTime -= 75 + }, + remove() { + tech.isDamageCooldownTime = 240 + } + }, + { + name: "CPT symmetry", + descriptionFunction() { + return `after losing health, if you have above ${(85 * Math.min(100, m.maxEnergy)).toFixed(0)} energy
rewind time for 20 energy per second` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isSkin: true, + allowed() { + return !m.isAltSkin && m.fieldUpgrades[m.fieldMode].name !== "standing wave" && !tech.isRewindField && !tech.isEnergyHealth + }, + requires: "not skinned, standing wave, max energy reduction, retrocausality, mass-energy", + effect() { + tech.isRewindAvoidDeath = true; + m.skin.CPT() + }, + remove() { + tech.isRewindAvoidDeath = false; + if (this.count) m.resetSkin(); + } + }, + { + name: "causality bots", + link: `causality bots`, + description: "when you rewind build scrap bots
that protect you for about 9 seconds", + maxCount: 3, + count: 0, + frequency: 2, + frequencyDefault: 2, + isBotTech: true, + allowed() { + return tech.isRewindAvoidDeath || tech.isRewindField + }, + requires: "CPT, retrocausality", + effect() { + tech.isRewindBot++; + }, + remove() { + tech.isRewindBot = 0; + } + }, + { + name: "causality bombs", + link: `causality bombs`, + description: "when you rewind drop several grenades", //
become invulnerable until they explode + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isRewindAvoidDeath || tech.isRewindField + }, + requires: "CPT, retrocausality", + effect() { + tech.isRewindGrenade = true; + }, + remove() { + tech.isRewindGrenade = false; + } + }, + { + name: "ternary", //"divisor", + descriptionFunction() { + return `1.9x damage while your ammo
is evenly divisible by 3(${((b.activeGun !== undefined && b.activeGun !== null && b.guns[b.activeGun].ammo % 3 === 0) ? "1.9" : "1")}x)` //if (tech.isDivisor && b.activeGun !== undefined && b.activeGun !== null && b.guns[b.activeGun].ammo % 3 === 0) dmg *= 1.9 + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => true, + requires: "", + // divisible: 3, // + Math.floor(6 * Math.random()), + effect() { + tech.isDivisor = true; + }, + remove() { + tech.isDivisor = false; + } + }, + { + name: "integrated armament", + link: `integrated armament`, + description: `1.3x damage, but new ${powerUps.orb.gun()} replace
current ${powerUps.orb.gun()} and convert your ${powerUps.orb.gunTech()}
`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return b.inventory.length === 1 + }, + requires: "only 1 gun", + effect() { + tech.isOneGun = true; + }, + remove() { + tech.isOneGun = false; + } + }, + { + name: "ordnance", + description: `spawn ${powerUps.orb.gun()} and get 2x frequency for ${powerUps.orb.gunTech()}
+6% JUNK choices`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isBadRandomOption: true, + allowed: () => tech.junkChance < 1, + requires: "", + effect() { + powerUps.spawn(m.pos.x, m.pos.y, "gun"); + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isGunTech) tech.tech[i].frequency *= 2 + } + this.refundAmount += tech.addJunkTechToPool(0.06) + }, + refundAmount: 0, + remove() { + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + }, + { + name: "arsenal", + descriptionFunction() { + return `for each unused ${powerUps.orb.gun()} in your inventory
1.25x damage (${(1 + 0.25 * Math.max(0, b.inventory.length - 1)).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => b.inventory.length > 1, + requires: "at least 2 guns", + effect() { + tech.isDamageForGuns = true; + }, + remove() { + tech.isDamageForGuns = false; + } + }, + { + name: "active cooling", + descriptionFunction() { + return `for each unused ${powerUps.orb.gun()} in your inventory
1.25x fire rate (${(1 / Math.pow(0.8, Math.max(0, b.inventory.length - 1))).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => b.inventory.length > 1, + requires: "at least 2 guns", + effect() { + tech.isFireRateForGuns = true; + b.setFireCD(); + }, + remove() { + tech.isFireRateForGuns = false; + b.setFireCD(); + } + }, + { + name: "pigeonhole principle", + descriptionFunction() { + return `1.4x damage per ${powerUps.orb.gun()}, but your equipped ${powerUps.orb.gun()}
cycles each level and you can't switch` + }, + // descriptionFunction() { + // let info = "" + // if (this.count > 0 && Number.isInteger(tech.buffedGun) && b.inventory.length) { + // let gun = b.guns[b.inventory[tech.buffedGun]].name + // info = `
this level: ${(1.3 * Math.max(0, b.inventory.length)).toFixed(2)}x damage for ${gun}` + // } + // return `a new ${powerUps.orb.gun()} in your inventory is chosen each level
if it's equipped, 1.3x damage per ${powerUps.orb.gun()} in your inventory${info}
` + // }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return b.inventory.length > 1 + }, + requires: "at least 2 guns", + effect() { + tech.isGunChoice = true + //switches gun on new level + //generalist uses the same chosen gun so they match + }, + remove() { + tech.isGunChoice = false; + } + }, + { + name: "generalist", + description: `spawn 7 ${powerUps.orb.gun()}, but your equipped ${powerUps.orb.gun()}
cycles each level and you can't switch`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isBadRandomOption: true, + allowed() { + return (b.inventory.length < b.guns.length - 5) && b.inventory.length > 1 + }, + requires: "you have at least 2 guns and 5 unclaimed guns", + effect() { + tech.isGunCycle = true; + for (let i = 0; i < 7; i++) powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "gun"); + }, + remove() { + tech.isGunCycle = false; // only set to false if you don't have this tech + } + }, + { + name: "ad hoc", + descriptionFunction() { + return `spawn a ${powerUps.orb.heal()}, ${powerUps.orb.research()}, ${powerUps.orb.ammo()}, ${powerUps.orb.tech()}, ${powerUps.orb.gun()}, or ${powerUps.orb.field()}
for each ${powerUps.orb.gun()} in your inventory` + }, + maxCount: 1, //random power up + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + allowed() { + return b.inventory.length > 1 + }, + requires: "at least 2 guns", + effect() { + for (let i = 0; i < b.inventory.length; i++) { + if (Math.random() < 1 / 6) { + powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "gun"); + } else if (Math.random() < 1 / 5) { + powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "tech"); + } else if (Math.random() < 1 / 4) { + powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "field"); + } else if (Math.random() < 1 / 3) { + powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "heal"); + } else if (Math.random() < 1 / 2) { + powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "ammo"); + } else { + powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "research"); + } + } + }, + remove() { } + }, + { + name: "applied science", + description: `get a random ${powerUps.orb.gunTech()}
for each ${powerUps.orb.gun()} in your inventory`, //spawn ${powerUps.orb.research(1)} and + maxCount: 1, + count: 0, + isInstant: true, + frequency: 2, + frequencyDefault: 2, + allowed() { + return b.inventory.length > 1 + }, + requires: "at least 2 guns", + effect() { + const delay = 30 + let i = (b.inventory.length) * delay + let gunIndex = -1 + let cycle = () => { + if (i > 0) { + if (m.alive) requestAnimationFrame(cycle); + if (!simulation.paused && !simulation.isChoosing) { + i-- + if (!(i % delay)) { + gunIndex++ + //find gun tech for this gun + const gunTechPool = [] + for (let j = 0, len = tech.tech.length; j < len; j++) { + const originalActiveGunIndex = b.activeGun //set current gun to active so allowed works + b.activeGun = b.inventory[gunIndex] //to make the .allowed work for guns that aren't active + if (tech.tech[j].isGunTech && tech.tech[j].allowed() && !tech.tech[j].isJunk && !tech.tech[j].isBadRandomOption && tech.tech[j].count < tech.tech[j].maxCount) { + const regex = tech.tech[j].requires.search(b.guns[b.inventory[gunIndex]].name) //get string index of gun name + const not = tech.tech[j].requires.search(' not ') //get string index of ' not ' + if (regex !== -1 && (not === -1 || not > regex)) gunTechPool.push(j) //look for the gun name in the requirements, but the gun name needs to show up before the word ' not ' + } + b.activeGun = originalActiveGunIndex + if (!b.guns[b.activeGun].have) { + if (b.inventory.length === 0) { + b.activeGun = null + } else { + b.activeGun = b.inventory[0] + } + b.inventoryGun = 0; + } + } + + //give the tech that was found for this gun + if (gunTechPool.length) { + const index = Math.floor(Math.random() * gunTechPool.length) + simulation.inGameConsole(`tech.giveTech("${tech.tech[gunTechPool[index]].name}")`, 360) + tech.giveTech(gunTechPool[index]) // choose from the gun pool + simulation.boldActiveGunHUD(); + } + + } + } + } + } + requestAnimationFrame(cycle); + + // for (let i = b.inventory.length - 1; i > -1; i--) { //backwards because some tech can remove or add guns + // const gunTechPool = [] //find gun tech for this gun + // for (let j = 0, len = tech.tech.length; j < len; j++) { + // // console.log(j, tech.tech[j].isGunTech, tech.tech[j].allowed(), !tech.tech[j].isJunk, !tech.tech[j].isBadRandomOption, tech.tech[j].count < tech.tech[j].maxCount) + // const originalActiveGunIndex = b.activeGun //set current gun to active so allowed works + // b.activeGun = b.inventory[i] //to make the .allowed work for guns that aren't active + // if (tech.tech[j].isGunTech && tech.tech[j].allowed() && !tech.tech[j].isJunk && !tech.tech[j].isBadRandomOption && tech.tech[j].count < tech.tech[j].maxCount) { + // const regex = tech.tech[j].requires.search(b.guns[b.inventory[i]].name) //get string index of gun name + // const not = tech.tech[j].requires.search(' not ') //get string index of ' not ' + // if (regex !== -1 && (not === -1 || not > regex)) gunTechPool.push(j) //look for the gun name in the requirements, but the gun name needs to show up before the word ' not ' + // } + // b.activeGun = originalActiveGunIndex + // if (!b.guns[b.activeGun].have) { + // if (b.inventory.length === 0) { + // b.activeGun = null + // } else { + // b.activeGun = b.inventory[0] + // } + // b.inventoryGun = 0; + // } + // } + // if (gunTechPool.length) { + // const index = Math.floor(Math.random() * gunTechPool.length) + // // console.log(gunTechPool, index, gunTechPool[index], tech.tech[gunTechPool[index]].name) + // simulation.inGameConsole(`tech.giveTech("${tech.tech[gunTechPool[index]].name}")`, 360) + // // tech.tech[gunTechPool[index]].isInstant = true //makes it not remove properly under paradigm shift + // tech.giveTech(gunTechPool[index]) // choose from the gun pool + // // console.log(gunTechPool, index, gunTechPool[index], tech.tech[gunTechPool[index]].name) + // // tech.tech[gunTechPool[index]].isFromAppliedScience = true //makes it not remove properly under paradigm shift + // } + // } + // simulation.boldActiveGunHUD(); + }, + remove() { } + }, + { + name: "supply chain", + descriptionFunction() { + return `spawn ${powerUps.orb.gun()} ${powerUps.orb.ammo(10)}` + }, + maxCount: 9, + count: 0, + isInstant: true, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + // let ammoCount = 0 //count ammo + // if (b.activeGun && b.activeGun !== undefined && b.guns[b.activeGun].have && b.guns[b.activeGun].ammo !== Infinity) { + // ammoCount += b.guns[b.activeGun].ammo / b.guns[b.activeGun].ammoPack + // } + powerUps.spawnDelay("ammo", 10) + powerUps.spawn(m.pos.x, m.pos.y, "gun"); + }, + remove() { } + }, + { + name: "marginal utility", + descriptionFunction() { + if (this.count === 0) this.gun = Math.floor(Math.random() * (b.guns.length - 1)) //don't pick laser + return `2x ammo per ${powerUps.orb.ammo(1)} for ${b.guns[this.gun].name}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { return true }, + requires: "", + gun: undefined, + effect() { + if (this.gun === undefined) this.gun = Math.floor(Math.random() * (b.guns.length - 1)) //don't pick laser + + simulation.inGameConsole(`${b.guns[this.gun].ammoPack} → ${2 * b.guns[this.gun].ammoPack} average ammo per ${powerUps.orb.ammo(1)} for ${b.guns[this.gun].name}`) + b.guns[this.gun].ammoPack *= 2 + // simulation.inGameConsole(`${(tech.interestRate * 100).toFixed(0)}% interest on health = ${h > 20 ? h + powerUps.orb.heal(1) : powerUps.orb.heal(h)}`) + + // for (let i = 0; i < 4; i++) powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "ammo"); + }, + remove() { + if (this.count) { + b.guns[this.gun].ammoPack /= 2 + } + } + }, + { + name: "Pareto efficiency", + descriptionFunction() { + return `for each ${powerUps.orb.gun()} in your inventory
randomly get 5x or 0.2x ammo per ${powerUps.orb.ammo(1)}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return b.inventory.length > 2 + }, + requires: "at least 3 guns", + effect() { + + let options = [] + for (let i = 0; i < b.inventory.length; i++) options.push(b.inventory[i]) + options = shuffle(options) + for (let i = 0; i < options.length; i++) { + const index = options[i] + const scale = (i < options.length / 2) ? 4 : 0.25 + simulation.inGameConsole(`${(b.guns[index].ammoPack).toFixed(1)} → ${(b.guns[index].ammoPack * scale).toFixed(1)} average ammo per ${powerUps.orb.ammo(1)} for ${b.guns[index].name}`, Infinity) + b.guns[index].ammoPack *= scale + } + }, + remove() { } + }, + { + name: "logistics", + description: `2x ammo per ${powerUps.orb.ammo()}, but
ammo is only added to your current ${powerUps.orb.gun()}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isEnergyNoAmmo + }, + requires: "not non-renewables", + effect() { + tech.isAmmoForGun = true; + }, + remove() { + tech.isAmmoForGun = false; + } + }, + { + name: "cache", + link: `cache`, + description: `17x ammo per ${powerUps.orb.ammo()}, but
you can't store additional ammo`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isEnergyNoAmmo + }, + requires: "not non-renewables", + effect() { + tech.ammoCap = 17; + powerUps.ammo.effect() + }, + remove() { + tech.ammoCap = 0; + } + }, + { + name: "catabolism", + descriptionFunction() { + return `if you fire while out of ammo
spawn ${powerUps.orb.ammo(4)} and ${tech.isEnergyHealth ? "–4 maximum energy" : "–2 maximum health"}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isEnergyNoAmmo + }, + requires: "not non-renewables", + effect() { + tech.isAmmoFromHealth = true; + }, + remove() { + tech.isAmmoFromHealth = false; + } + }, + { + name: "non-renewables", + description: `2x damage
you can't pickup ${powerUps.orb.ammo()}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isAmmoFromHealth && !tech.isBoostReplaceAmmo + }, + requires: "not catabolism, quasiparticles", + damage: 2, + effect() { + tech.damage *= this.damage + tech.isEnergyNoAmmo = true; + powerUps.ammo.color = "#c1c6c9"//"#abb3b8"// "#535e63" + + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "ammo") powerUp[i].color = powerUps.ammo.color + } + + }, + remove() { + if (this.count && m.alive) tech.damage /= this.damage + tech.isEnergyNoAmmo = false; + powerUps.ammo.color = "#467" + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "ammo") powerUp[i].color = powerUps.ammo.color + } + } + }, + { + name: "desublimated ammunition", + description: `if crouching
alternating shots cost no ammo`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => true, + requires: "", + effect() { + tech.crouchAmmoCount = true + }, + remove() { + tech.crouchAmmoCount = false; + } + }, + { + name: "gun turret", + description: "if crouching
0.3x damage taken", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isTurret = true + }, + remove() { + tech.isTurret = false; + } + }, + { + name: "dead reckoning", + description: `if your speed is 0
1.5x damage`, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.restDamage += 0.5 + }, + remove() { + tech.restDamage = 1; + } + }, + { + name: "kinetic bombardment", + description: "far away mobs take more damage
up to 1.3x damage at 3000 displacement", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isFarAwayDmg = true; + }, + remove() { + tech.isFarAwayDmg = false; + } + }, + { + name: "microstates", + link: `microstates`, + descriptionFunction() { + return `use ${powerUps.orb.research(3)}
1.01x damage per bullet or bot (${(1 + bullet.length * 0.01).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return powerUps.research.count > 2 || build.isExperimentSelection + }, + requires: "", + effect() { + tech.isDamageFromBulletCount = true + for (let i = 0; i < 3; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.isDamageFromBulletCount = false + if (this.count > 0) { + powerUps.research.changeRerolls(3) + } + } + }, + { + name: "regression", + description: "bullet collisions increase vulnerability to
damage by 1.05x for mobs and +1.025x for bosses", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isLessDamageReduction = true + }, + remove() { + tech.isLessDamageReduction = false + } + }, + { + name: "simulated annealing", + description: "1.2x damage
0.8x fire rate", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + damage: 1.2, + effect() { + tech.damage *= this.damage + tech.slowFire = 1.25 + b.setFireCD(); + }, + remove() { + if (this.count && m.alive) tech.damage /= this.damage + tech.slowFire = 1; + b.setFireCD(); + } + }, + { + name: "heuristics", + descriptionFunction() { + let totalRate = 1 + for (let i = 0; i < this.totalRate.length; i++) totalRate *= this.totalRate[i] + let currentRate = "" + if (this.count) currentRate = `(${(totalRate).toFixed(2)}x)` + return `randomly gain between 1x and 2x fire rate
+5% JUNK choices` + currentRate + }, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.junkChance < 1 + }, + requires: "", + totalRate: [], //tracks the random damage upgrades so it can be removed and in descriptionFunction + effect() { + const rate = (Math.floor((Math.random() + 1) * 100)) / 100 + tech.fireRate /= rate + this.totalRate.push(rate) + b.setFireCD(); + simulation.inGameConsole(`tech.fireRate *= ${rate} //heuristics`); + this.refundAmount += tech.addJunkTechToPool(0.05) + }, + refundAmount: 0, + remove() { + if (this.count) { + // for (let i = 0; i < this.totalRate.length; i++) tech.fireRate *= this.totalRate[i] + if (this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + tech.fireRate = 1 + this.totalRate.length = 0 + b.setFireCD(); + } + }, + { + name: "mechatronics", + descriptionFunction() { + let damageTotal = 1 + for (let i = 0; i < this.damageSoFar.length; i++) damageTotal *= this.damageSoFar[i] + let currentDamage = "" + if (this.count) currentDamage = `
(${(damageTotal).toFixed(2)}x)` + return `randomly gain between 1x and 1.3x damage` + currentDamage + }, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { return true }, + requires: "", + damageSoFar: [], //tracks the random damage upgrades so it can be removed and in descriptionFunction + effect() { + const damage = (Math.floor((Math.random() * 0.3 + 1) * 100)) / 100 + tech.damage *= damage + this.damageSoFar.push(damage) + simulation.inGameConsole(`tech.damage *= ${damage} //mechatronics`); + }, + remove() { + if (this.count && m.alive) for (let i = 0; i < this.damageSoFar.length; i++) tech.damage /= this.damageSoFar[i] + this.damageSoFar.length = 0 + } + }, + { + name: "dynamical systems", + description: `use ${powerUps.orb.research(2)}
1.3x damage`, + // isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return powerUps.research.count > 1 || build.isExperimentSelection + }, + requires: "", + // allowed() { + // return (m.fieldMode === 5 || m.fieldMode === 7 || m.fieldMode === 8) && (build.isExperimentSelection || powerUps.research.count > 1) + // }, + // requires: "cloaking, pilot wave, or plasma torch", + damage: 1.3, + effect() { + tech.damage *= this.damage + tech.isCloakingDamage = true + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.isCloakingDamage = false + if (this.count && m.alive) { + tech.damage /= this.damage + powerUps.research.changeRerolls(2) + } + } + }, + { + name: "anti-shear topology", + link: `anti-shear topology`, + description: "your bullets last 1.3x longer", //
drone spore worm flea missile foam wave neutron ice", + maxCount: 3, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => true, + requires: "", + effect() { + tech.bulletsLastLonger += 0.3 + }, + remove() { + tech.bulletsLastLonger = 1; + } + }, + { + name: "fracture analysis", + description: "if a mob is stunned it takes
5x damage from bullet impacts", + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isStunField || tech.oneSuperBall || tech.isCloakStun || tech.isOrbitBotUpgrade || tech.isStun + }, + requires: "a stun effect", + effect() { + tech.isCrit = true; + }, + remove() { + tech.isCrit = false; + } + }, + { + name: "shear stress", + description: "after mobs die
they fire a nail at nearby mobs", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.sporesOnDeath && !tech.isExplodeMob && !tech.botSpawner && !tech.isMobBlockFling && !tech.iceIXOnDeath + }, + requires: "no other mob death tech", + effect() { + tech.nailsDeathMob++ + }, + remove() { + tech.nailsDeathMob = 0; + } + }, + { + name: "thermal runaway", + description: "after mobs die they explode", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.sporesOnDeath && !tech.nailsDeathMob && !tech.botSpawner && !tech.isMobBlockFling && !tech.iceIXOnDeath + }, + requires: "no other mob death tech", + effect() { + tech.isExplodeMob = true; + }, + remove() { + tech.isExplodeMob = false; + } + }, + { + name: "zoospore vector", + link: `zoospore vector`, + descriptionFunction() { + return `after mobs die there is a 13% chance
they grow ${b.guns[6].nameString('s')}` + }, + // description: "after mobs die
they have a +10% chance to grow spores", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.nailsDeathMob && !tech.isExplodeMob && !tech.botSpawner && !tech.isMobBlockFling && !tech.iceIXOnDeath + }, + requires: "no other mob death tech", + effect() { + tech.sporesOnDeath += 0.13; + // if (tech.isSporeWorm) { + // for (let i = 0; i < 4; i++) b.worm(m.pos) + // } else { + // for (let i = 0; i < 8; i++) b.spore(m.pos) + // } + }, + remove() { + tech.sporesOnDeath = 0; + } + }, + { + name: "exciton", + descriptionFunction() { + return `after mobs die they have a +14% chance to
spawn ${powerUps.orb.boost(1)} that give ${(1 + powerUps.boost.damage).toFixed(2)}x damage for ${(powerUps.boost.duration / 60).toFixed(0)} seconds
` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => true, + requires: "", + effect() { + tech.isBoostPowerUps = true + }, + remove() { + tech.isBoostPowerUps = false + } + }, + { + name: "band gap", + descriptionFunction() { + // return `${powerUps.orb.boost(1)} give ${(1 + powerUps.boost.damage).toFixed(2)}x ${(1 + powerUps.boost.damage + 0.77).toFixed(2)}x damage
but their duration is reduced by 1 second` + // const predict = this.count === 0 ? `${(1 + powerUps.boost.damage).toFixed(2)}x` : `` + return `${powerUps.orb.boost(1)} give an additional ${(1 + 0.75).toFixed(2)}x damage
but their duration is reduced by 1 second` + }, + maxCount: 9, + count: 1, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isBoostPowerUps || tech.isBoostReplaceAmmo + }, + requires: "exciton, quasiparticles", + effect() { + powerUps.boost.duration -= 60 + powerUps.boost.damage += 0.75 + }, + remove() { + powerUps.boost.duration = 600 + powerUps.boost.damage = 1.25 + } + }, + { + name: "polariton", + descriptionFunction() { + return `${powerUps.orb.boost(1)} also give 0.3x damage taken
for ${(powerUps.boost.duration / 60).toFixed(0)} seconds` + }, + maxCount: 1, + count: 1, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isBoostPowerUps || tech.isBoostReplaceAmmo + }, + requires: "exciton, quasiparticles", + effect() { + powerUps.boost.isDefense = true + }, + remove() { + powerUps.boost.isDefense = false + } + }, + { + name: "collider", + descriptionFunction() { + return `after mobs die existing power ups
collide to form new power ups` + }, + + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => true, + requires: "", + effect() { + tech.collidePowerUps = true + }, + remove() { + tech.collidePowerUps = false + } + }, + { + name: "bubble fusion", + descriptionFunction() { + return `after destroying a mob's shield
spawn 1-2 ${powerUps.orb.heal()}, ${powerUps.orb.ammo()}, or ${powerUps.orb.research(1)} (once per mob)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isHealTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.isShieldAmmo = true; + }, + remove() { + tech.isShieldAmmo = false; + } + }, + { + name: "enthalpy", + descriptionFunction() { + return `8% chance to spawn ${powerUps.orb.heal(1)} after mobs die` + }, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isHealTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.healSpawn += 0.08; + }, + remove() { + tech.healSpawn = 0; + } + }, + { + name: "cascading failure", + description: "3x damage to mobs below 25% durability", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return tech.mobSpawnWithHealth > 0 + }, + requires: "reaction inhibitor", + effect() { + tech.isMobLowHealth = true + }, + remove() { + tech.isMobLowHealth = false + } + }, + { + name: "reaction inhibitor", + description: "mobs spawn with 0.88x initial durability", + maxCount: 3, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isMobFullHealthCloak + }, + requires: "not topological defect", + effect() { + tech.mobSpawnWithHealth++ + mobs.setMobSpawnHealth() + for (let i = 0; i < mob.length; i++) { + if (mob.health > mobs.mobSpawnWithHealth) mob.health = mobs.mobSpawnWithHealth + } + }, + remove() { + tech.mobSpawnWithHealth = 0 + mobs.setMobSpawnHealth() + } + }, + { + name: "scrap bots", + link: `scrap bots`, + description: "after mobs die you have a 33% chance
to construct scrap bots that operate for 15 seconds", + maxCount: 3, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBotTech: true, + allowed() { + return !tech.sporesOnDeath && !tech.nailsDeathMob && !tech.isExplodeMob && !tech.isMobBlockFling && !tech.iceIXOnDeath + }, + requires: "no other mob death tech", + effect() { + tech.botSpawner += 0.33; + }, + remove() { + tech.botSpawner = 0; + } + }, + { + name: "scrap refit", + link: `scrap refit`, + description: "after mobs die reset scrap bots
to 15 seconds of operation", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBotTech: true, + allowed() { + return tech.botSpawner + }, + requires: "scrap bots", + effect() { + tech.isBotSpawnerReset = true; + }, + remove() { + tech.isBotSpawnerReset = false; + } + }, + { + name: "nail-bot", + link: `nail-bot`, + description: "construct a bot that fires nails at mobs", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.nailBotCount++; + b.nailBot(); + }, + remove() { + if (this.count) { + tech.nailBotCount -= this.count; + b.clearPermanentBots(); + b.respawnBots(); + } + } + }, + { + name: "nail-bot upgrade", + link: `nail-bot upgrade`, + description: "convert your bots to nail-bots
4x fire rate and 1.4x nail velocity", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBotTech: true, + allowed() { + return tech.nailBotCount > 1 && !b.hasBotUpgrade() + }, + requires: "2 or more nail bots and no other bot upgrade", + effect() { + tech.isNailBotUpgrade = true + b.convertBotsTo("nail-bot") + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'nail') bullet[i].isUpgraded = true + } + tech.setBotTechFrequency() + tech.setTechFrequency("nail-bot", 5) + }, + remove() { + if (this.count) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'nail') bullet[i].isUpgraded = false + } + tech.setBotTechFrequency(1) + } + tech.isNailBotUpgrade = false + } + }, + { + name: "foam-bot", + link: `foam-bot`, + description: "construct a bot that sprays sticky foam at mobs", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.foamBotCount++; + b.foamBot(); + }, + remove() { + if (this.count) { + tech.foamBotCount -= this.count; + b.clearPermanentBots(); + b.respawnBots(); + } + } + }, + { + name: "foam-bot upgrade", + link: `foam-bot upgrade`, + description: "convert your bots to foam-bots
2.5x foam size and fire rate", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBotTech: true, + allowed() { + return tech.foamBotCount > 1 && !b.hasBotUpgrade() + }, + requires: "2 or more foam bots and no other bot upgrade", + effect() { + tech.isFoamBotUpgrade = true + b.convertBotsTo("foam-bot") + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'foam') bullet[i].isUpgraded = true + } + tech.setBotTechFrequency() + tech.setTechFrequency("foam-bot", 5) + }, + remove() { + if (this.count) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'foam') bullet[i].isUpgraded = false + } + tech.setBotTechFrequency(1) + } + tech.isFoamBotUpgrade = false + } + }, + { + name: "sound-bot", + link: `sound-bot`, + description: "construct a bot that emits expanding
arcs of sound aimed towards nearby mobs", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + allowed() { return true }, + requires: "", + effect() { + tech.soundBotCount++; + b.soundBot(); + }, + remove() { + if (this.count) { + tech.soundBotCount -= this.count; + b.clearPermanentBots(); + b.respawnBots(); + } + } + }, + { + name: "sound-bot upgrade", + link: `sound-bot upgrade`, + description: "convert your bots to sound-bots
6x wave damage", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBotTech: true, + allowed() { + return tech.soundBotCount > 1 && !b.hasBotUpgrade() + }, + requires: "2 or more sound bots and no other bot upgrade", + effect() { + tech.isSoundBotUpgrade = true + b.convertBotsTo("sound-bot") + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'sound') bullet[i].isUpgraded = true + } + tech.setBotTechFrequency() + tech.setTechFrequency("sound-bot", 5) + }, + remove() { + if (this.count) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'sound') bullet[i].isUpgraded = false + } + tech.setBotTechFrequency(1) + } + tech.isSoundBotUpgrade = false + } + }, + { + name: "boom-bot", + link: `boom-bot`, + description: "construct a bot that explodes nearby mobs", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.boomBotCount++; + b.boomBot(); + }, + remove() { + if (this.count) { + tech.boomBotCount -= this.count; + b.clearPermanentBots(); + b.respawnBots(); + } + } + }, + { + name: "boom-bot upgrade", + link: `boom-bot upgrade`, + description: "convert your bots to boom-bots
4x explosion damage and size", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBotTech: true, + allowed() { + return tech.boomBotCount > 1 && !b.hasBotUpgrade() + }, + requires: "2 or more boom bots and no other bot upgrade", + effect() { + tech.isBoomBotUpgrade = true + b.convertBotsTo("boom-bot") + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'boom') bullet[i].isUpgraded = true + } + tech.setBotTechFrequency() + tech.setTechFrequency("boom-bot", 5) + }, + remove() { + if (this.count) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'boom') bullet[i].isUpgraded = false + } + tech.setBotTechFrequency(1) + } + tech.isBoomBotUpgrade = false + } + }, + { + name: "laser-bot", + link: `laser-bot`, + description: "construct a bot that uses energy to emit
a laser that targets mobs", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + allowed() { + return m.maxEnergy > 0.5 + }, + requires: "maximum energy above 50", + effect() { + tech.laserBotCount++; + b.laserBot(); + }, + remove() { + if (this.count) { + tech.laserBotCount -= this.count; + b.clearPermanentBots(); + b.respawnBots(); + } + } + }, + { + name: "laser-bot upgrade", + link: `laser-bot upgrade`, + description: "convert your bots to laser-bots
2x damage, efficiency, and range", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBotTech: true, + allowed() { + return tech.laserBotCount > 1 && !b.hasBotUpgrade() + }, + requires: "2 or more laser bots and no other bot upgrade", + effect() { + tech.isLaserBotUpgrade = true + b.convertBotsTo("laser-bot") + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'laser') bullet[i].isUpgraded = true + } + tech.setBotTechFrequency() + tech.setTechFrequency("laser-bot", 5) + }, + remove() { + if (this.count) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'laser') bullet[i].isUpgraded = false + } + tech.setBotTechFrequency(1) + } + tech.isLaserBotUpgrade = false + } + }, + { + name: "orbital-bot", + link: `orbital-bot`, + description: "construct a bot locked in orbit around you
that stuns and damages mobs", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + allowed() { + return true + }, + requires: "", + effect() { + b.orbitBot(); + tech.orbitBotCount++; + }, + remove() { + if (this.count) { + tech.orbitBotCount -= this.count; + b.clearPermanentBots(); + b.respawnBots(); + } + } + }, + { + name: "orbital-bot upgrade", + link: `orbital-bot upgrade`, + description: "convert your bots to orbital-bots
4x orbital damage and 2x radius", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBotTech: true, + allowed() { + return tech.orbitBotCount > 1 && !b.hasBotUpgrade() + }, + requires: "2 or more orbital bots and no other bot upgrade", + effect() { + tech.isOrbitBotUpgrade = true + b.convertBotsTo("orbital-bot") + const range = 190 + 120 * tech.isOrbitBotUpgrade + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'orbit') { + bullet[i].isUpgraded = true + bullet[i].range = range + bullet[i].orbitalSpeed = Math.sqrt(0.25 / range) + } + } + tech.setBotTechFrequency() + tech.setTechFrequency("orbital-bot", 5) + }, + remove() { + if (this.count) { + const range = 190 + 100 * tech.isOrbitBotUpgrade + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'orbit') { + bullet[i].range = range + bullet[i].orbitalSpeed = Math.sqrt(0.25 / range) + } + } + tech.setBotTechFrequency(1) + } + tech.isOrbitBotUpgrade = false + } + }, + { + name: "dynamo-bot", + link: `dynamo-bot`, + description: "construct a bot that damages mobs and
generates +8 energy per second when nearby", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.dynamoBotCount++; + b.dynamoBot(); + }, + remove() { + if (this.count) { + tech.dynamoBotCount -= this.count; + b.clearPermanentBots(); + b.respawnBots(); + } + } + }, + { + name: "dynamo-bot upgrade", + link: `dynamo-bot upgrade`, + description: "convert your bots to dynamo-bots
+24 energy per second when nearby", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBotTech: true, + allowed() { + return tech.dynamoBotCount > 1 && !b.hasBotUpgrade() + }, + requires: "2 or more dynamo bots and no other bot upgrade", + effect() { + tech.isDynamoBotUpgrade = true + b.convertBotsTo("dynamo-bot") + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'dynamo') bullet[i].isUpgraded = true + } + tech.setBotTechFrequency() + tech.setTechFrequency("dynamo-bot", 5) + }, + remove() { + if (this.count) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType === 'dynamo') bullet[i].isUpgraded = false + } + tech.setBotTechFrequency(1) + } + tech.isDynamoBotUpgrade = false + } + }, + { + name: "perimeter defense", + descriptionFunction() { + return `for each permanent bot
0.96x damage taken(${(0.96 ** b.totalBots()).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isBotTech: true, + allowed() { + return b.totalBots() > 1 + }, + requires: "at least 2 bots", + effect() { + tech.isBotArmor = true + }, + remove() { + tech.isBotArmor = false + } + }, + { + name: "network effect", + descriptionFunction() { + return `for each permanent bot
1.04x damage(${(1 + 0.04 * b.totalBots()).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isBotTech: true, + allowed() { + return b.totalBots() > 1 + }, + requires: "at least 2 bots", + effect() { + tech.isBotDamage = true + }, + remove() { + tech.isBotDamage = false + } + }, + { + name: "bot fabrication", + link: `bot fabrication`, + descriptionFunction() { + return `after you collect ${powerUps.orb.research(2 + Math.floor(0.25 * b.totalBots()))}use them
to construct a random bot (+1 cost every 3 bots)` + }, + // description: `if you collect ${powerUps.orb.research(2)}use them to build a
random bot (+1 cost every 5 bots)`, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isBotTech: true, + allowed() { + return powerUps.research.count > 1 || build.isExperimentSelection + }, + requires: "at least 2 research", + effect() { + tech.isRerollBots = true; + powerUps.research.changeRerolls(0) + simulation.inGameConsole(`m.research = 0`) + }, + remove() { + tech.isRerollBots = false; + // this.description = `if you collect ${powerUps.orb.research(2 + Math.floor(0.2 * b.totalBots()))}use them to build a
random bot (+1 cost every 5 bots)` + } + }, + { + name: "open-source", + description: `${powerUps.orb.tech()}, ${powerUps.orb.field()}, and ${powerUps.orb.gun()} have +1 bot choice
3x frequency for ${powerUps.orb.tech()} with bots`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBotTech: true, + allowed() { + return b.totalBots() > 1 && !tech.isDeterminism + }, + requires: "at least 2 bots", + effect() { + tech.isExtraBotOption = true + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isBotTech) tech.tech[i].frequency *= 3 + } + }, + remove() { + if (this.count > 0) { + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isBotTech) tech.tech[i].frequency = Math.ceil(tech.tech[i].frequency / 3) + } + } + tech.isExtraBotOption = false + } + }, + { + name: "ersatz bots", + link: `ersatz bots`, + description: `double your bots
remove all ${powerUps.orb.gun()} in your inventory`, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isBotTech: true, + isInstant: true, + isBadRandomOption: true, + numberOfGunsLost: 0, + allowed() { + return b.totalBots() > 3 && !build.isExperimentSelection + }, + requires: "NOT EXPERIMENT MODE, at least 4 bots", + effect() { + this.numberOfGunsLost = b.inventory.length + b.inventory = []; //removes guns and ammo + for (let i = 0, len = b.guns.length; i < len; ++i) { + b.guns[i].count = 0; + b.guns[i].have = false; + if (b.guns[i].ammo != Infinity) b.guns[i].ammo = 0; + } + tech.buffedGun = 0 + b.activeGun = null; + b.inventoryGun = 0; + simulation.drawCursor = simulation.drawCursorBasic //set cross hairs + + simulation.makeGunHUD(); + //double bots + for (let i = 0; i < tech.nailBotCount; i++) b.nailBot(); + tech.nailBotCount *= 2 + for (let i = 0; i < tech.laserBotCount; i++) b.laserBot(); + tech.laserBotCount *= 2 + for (let i = 0; i < tech.foamBotCount; i++) b.foamBot(); + tech.foamBotCount *= 2 + for (let i = 0; i < tech.boomBotCount; i++) b.boomBot(); + tech.boomBotCount *= 2 + for (let i = 0; i < tech.orbitBotCount; i++) b.orbitBot(); + tech.orbitBotCount *= 2 + for (let i = 0; i < tech.dynamoBotCount; i++) b.dynamoBot(); + tech.dynamoBotCount *= 2 + for (let i = 0; i < tech.soundBotCount; i++) b.soundBot(); + tech.soundBotCount *= 2 + for (let i = 0; i < tech.plasmaBotCount; i++) b.plasmaBot(); + tech.plasmaBotCount *= 2 + for (let i = 0; i < tech.missileBotCount; i++) b.missileBot(); + tech.missileBotCount *= 2 + }, + remove() { + // if (this.count) { + // //return guns + // for (let i = 0; i < this.numberOfGunsLost; i++) powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "gun"); + // this.numberOfGunsLost = 0; + + // //half all current bots + // tech.nailBotCount = Math.round(tech.nailBotCount / 2) + // tech.laserBotCount = Math.round(tech.laserBotCount / 2) + // tech.foamBotCount = Math.round(tech.foamBotCount / 2) + // tech.soundBotCount = Math.round(tech.soundBotCount / 2) + // tech.boomBotCount = Math.round(tech.boomBotCount / 2) + // tech.orbitBotCount = Math.round(tech.orbitBotCount / 2) + // tech.dynamoBotCount = Math.round(tech.dynamoBotCount / 2) + // tech.plasmaBotCount = Math.round(tech.plasmaBotCount / 2) + // tech.missileBotCount = Math.round(tech.missileBotCount / 2) + // b.clearPermanentBots(); + // b.respawnBots(); + // } + } + }, + { + name: "robotics", + description: `construct 2 random bots`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBotTech: true, + isInstant: true, + allowed() { + return b.totalBots() > 2 + }, + requires: "at least 3 bots", + effect() { + for (let i = 0; i < 2; i++) b.randomBot() + }, + remove() { + } + }, + { + name: "bot manufacturing", + description: `use ${powerUps.orb.research(2)} to construct
3 random bots`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBotTech: true, + isInstant: true, + allowed() { + return b.totalBots() > 3 && powerUps.research.count > 1 + }, + requires: "at least 4 bots", + effect() { + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + // m.energy = 0.01; + b.randomBot() + b.randomBot() + b.randomBot() + }, + remove() { } + }, + { + name: "bot prototypes", + description: `use ${powerUps.orb.research(3)}to build 2 random bots
and upgrade all bots to a random type`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBotTech: true, + isInstant: true, + allowed() { + return b.totalBots() > 5 && powerUps.research.count > 2 + }, + requires: "at least 6 bots", + effect() { + requestAnimationFrame(() => { + for (let i = 0; i < 3; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + //fill array of available bots + const notUpgradedBots = [] + const num = 2 + notUpgradedBots.push(() => { + tech.giveTech("nail-bot upgrade") + for (let i = 0; i < num; i++) { + b.nailBot() + tech.nailBotCount++; + } + simulation.inGameConsole(`tech.isNailBotUpgrade = true`) + }) + notUpgradedBots.push(() => { + tech.giveTech("foam-bot upgrade") + for (let i = 0; i < num; i++) { + b.foamBot() + tech.foamBotCount++; + } + simulation.inGameConsole(`tech.isFoamBotUpgrade = true`) + }) + notUpgradedBots.push(() => { + tech.giveTech("sound-bot upgrade") + for (let i = 0; i < num; i++) { + b.soundBot() + tech.soundBotCount++; + } + simulation.inGameConsole(`tech.isSoundBotUpgrade = true`) + }) + notUpgradedBots.push(() => { + tech.giveTech("boom-bot upgrade") + for (let i = 0; i < num; i++) { + b.boomBot() + tech.boomBotCount++; + } + simulation.inGameConsole(`tech.isBoomBotUpgrade = true`) + }) + notUpgradedBots.push(() => { + tech.giveTech("laser-bot upgrade") + for (let i = 0; i < num; i++) { + b.laserBot() + tech.laserBotCount++; + } + simulation.inGameConsole(`tech.isLaserBotUpgrade = true`) + }) + notUpgradedBots.push(() => { + tech.giveTech("orbital-bot upgrade") + for (let i = 0; i < num; i++) { + b.orbitBot() + tech.orbitBotCount++; + } + simulation.inGameConsole(`tech.isOrbitalBotUpgrade = true`) + }) + notUpgradedBots.push(() => { + tech.giveTech("dynamo-bot upgrade") + for (let i = 0; i < num; i++) { + b.dynamoBot() + tech.dynamoBotCount++; + } + simulation.inGameConsole(`tech.isDynamoBotUpgrade = true`) + }) + + notUpgradedBots[Math.floor(Math.random() * notUpgradedBots.length)]() //choose random function from the array and run it + }) + }, + remove() { } + }, + { + name: "decorrelation", + description: `if your ${powerUps.orb.gun()} and ${powerUps.orb.field()} keys are unused for 2 seconds
0.3x damage taken`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isRewindField + }, + requires: "not retrocausality", + effect() { + tech.isNoFireDefense = true + }, + remove() { + tech.isNoFireDefense = false + } + }, + { + name: "anticorrelation", + description: `if your ${powerUps.orb.gun()} and ${powerUps.orb.field()} keys are unused for 2 seconds
2x damage`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isRewindField + }, + requires: "not retrocausality", + effect() { + tech.isNoFireDamage = true + }, + remove() { + tech.isNoFireDamage = false + } + }, + { + name: "mass driver", + description: "4x block collision damage", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.fieldMode !== 9 && !tech.isTokamak && !tech.isReel + }, + requires: "not wormhole, reel, tokamak", + effect() { + tech.blockDamage = 0.3 + }, + remove() { + tech.blockDamage = 0.075 + } + }, + { + name: "Halbach array", + description: "throwing a block will
also throw other nearby blocks", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.blockDamage > 0.075 || tech.isPrinter) && m.fieldMode !== 8 && m.fieldMode !== 9 && !tech.isTokamak + }, + requires: "mass driver, printer, not wormhole, pilot wave, tokamak", + effect() { + tech.isGroupThrow = true + }, + remove() { + tech.isGroupThrow = false + } + }, + { + name: "inflation", + link: `inflation`, + description: "if holding a block 0.1x damage taken
after throwing a block it expands 3x", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (tech.blockDamage > 0.075 || tech.isPrinter) && m.fieldMode !== 8 && m.fieldMode !== 9 && !tech.isTokamak + }, + requires: "mass driver, printer, not pilot wave, tokamak, wormhole", + effect() { + tech.isAddBlockMass = true + }, + remove() { + tech.isAddBlockMass = false + } + }, + { + name: "restitution", + description: "2.5x block collision damage
after throwing a block it becomes very bouncy", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (tech.blockDamage > 0.075 || tech.isPrinter) && m.fieldUpgrades[m.fieldMode].name !== "pilot wave" && m.fieldUpgrades[m.fieldMode].name !== "wormhole" && !tech.isTokamak + }, + requires: "mass driver, printer, not pilot wave, tokamak, wormhole", + effect() { + tech.isBlockRestitution = true + }, + remove() { + tech.isBlockRestitution = false + } + }, + { + name: "flywheel", + description: "2.5x block collision damage
after a mob dies its block is flung at mobs", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (tech.blockDamage > 0.075 || tech.isPrinter) && !tech.nailsDeathMob && !tech.sporesOnDeath && !tech.isExplodeMob && !tech.botSpawner && !tech.iceIXOnDeath + }, + requires: "mass driver, printer, no other mob death tech", + effect() { + tech.isMobBlockFling = true + }, + remove() { + tech.isMobBlockFling = false + } + }, + { + name: "buckling", + descriptionFunction() { + return `if a block kills a mob there's a 50% chance
to spawn either ${powerUps.orb.coupling(1)}, ${powerUps.orb.boost(1)}, ${powerUps.orb.heal()}, ${powerUps.orb.ammo()}, or ${powerUps.orb.research(1)}` + }, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (tech.blockDamage > 0.075 || tech.isPrinter) && m.fieldUpgrades[m.fieldMode].name !== "pilot wave" && !tech.isTokamak + }, + requires: "mass driver, printer, not pilot wave, tokamak", + effect() { + tech.isBlockPowerUps = true + }, + remove() { + tech.isBlockPowerUps = false + } + }, + + { + name: "first derivative", + descriptionFunction() { + return `0.85x damage taken per ${powerUps.orb.gun()} in your inventory
while the 1st ${powerUps.orb.gun()} in your inventory is equipped(${(0.85 ** b.inventory.length).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isFirstDer = true + }, + remove() { + tech.isFirstDer = false; + } + }, + { + name: "dark matter", + //a MAssive Compact Halo Object follows you
+ descriptionFunction() { + return `dark matter slowly gravitates towards you
0.4x damage taken ${tech.isNotDarkMatter ? "outside" : "inside"} dark matter` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isDarkMatter = true; //this harm reduction comes from the particle toggling tech.isHarmDarkMatter + spawn.darkMatter() + }, + remove() { + tech.isDarkMatter = false; + tech.isHarmDarkMatter = false; + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isDarkMatter) mob[i].alive = false; + } + } + }, + { + name: "axion", + descriptionFunction() { + return `while ${tech.isNotDarkMatter ? "outside" : "inside"} dark matter
2x damage` + }, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isDarkMatter + }, + requires: "dark matter", + effect() { + tech.isAxion = true + }, + remove() { + tech.isAxion = false + } + }, + { + name: "dark energy", + descriptionFunction() { + return `while ${tech.isNotDarkMatter ? "outside" : "inside"} dark matter
generate 10 energy per second` + }, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isDarkMatter + }, + requires: "dark matter", + effect() { + tech.isDarkEnergy = true + }, + remove() { + tech.isDarkEnergy = false + } + }, + { + name: "MACHO", + description: "dark matter's effects are only active outside it's range
1.6x to all dark matter effects
", + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isDarkMatter && !tech.isMoveDarkMatter && !tech.isDarkStar + }, + requires: "dark matter, not entropic gravity, dark star", + effect() { + tech.isNotDarkMatter = true + }, + remove() { + tech.isNotDarkMatter = false + } + }, + { + name: "entropic gravity", + description: "crouching pulls dark matter towards you
1.6x to all dark matter effects", + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isDarkMatter && !tech.isNotDarkMatter + }, + requires: "dark matter, not MACHO", + effect() { + tech.isMoveDarkMatter = true + }, + remove() { + tech.isMoveDarkMatter = false + } + }, + { + name: "dark star", + description: `mobs inside dark matter are damaged
1.3x dark matter radius`, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isDarkMatter && !tech.isNotDarkMatter + }, + requires: "dark matter, not MACHO", + effect() { + tech.isDarkStar = true + }, + remove() { + tech.isDarkStar = false + } + }, + { + name: "non-Newtonian armor", + link: `non-Newtonian armor`, + description: "after mob collisions
0.3x damage taken for 10 seconds", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isHarmArmor = true; + }, + remove() { + tech.isHarmArmor = false; + } + }, + { + name: "tessellation", + description: `use ${powerUps.orb.research(2)}
0.6x damage taken`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return powerUps.research.count > 1 || build.isExperimentSelection + }, + requires: "", + effect() { + tech.isFieldHarmReduction = true + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.isFieldHarmReduction = false + if (this.count > 0) powerUps.research.changeRerolls(2) + } + }, + { + name: "Pauli exclusion", + description: `for 7 seconds after mob collisions
become invulnerable and inhibit energy regen`, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + m.collisionImmuneCycles += 420; + if (m.immuneCycle < m.cycle + m.collisionImmuneCycles) m.immuneCycle = m.cycle + m.collisionImmuneCycles; //player is immune to damage + }, + remove() { + m.collisionImmuneCycles = 30; + } + }, + { + name: "spin-statistics theorem", + description: `for 1.9 seconds out of every 7 seconds
become invulnerable and inhibit energy regen`, + maxCount: 3, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true //m.collisionImmuneCycles > 30 + }, + requires: "", + effect() { + tech.cyclicImmunity += 114; + }, + remove() { + tech.cyclicImmunity = 0; + } + }, + { + name: "fermion", + description: `for 6 seconds after mobs die
become invulnerable and inhibit energy regen`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isMobDeathImmunity = true; + }, + remove() { + tech.isMobDeathImmunity = false; + } + }, + { + name: "abelian group", + description: `3x damage while invulnerable`, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isMobDeathImmunity || tech.cyclicImmunity || m.collisionImmuneCycles > 30 + }, + requires: "invincibility tech", + effect() { + tech.isImmunityDamage = true; + }, + remove() { + tech.isImmunityDamage = false; + } + }, + { + name: "refrigerant", + descriptionFunction() { + return `after losing at least 5 ${tech.isEnergyHealth ? "energy" : "health"}
freeze all mobs for 7 seconds` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isHarmFreeze = true; + }, + remove() { + tech.isHarmFreeze = false; + } + }, + { + name: "piezoelectricity", + description: "if you collide with a mob
generate +2048 energy", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isEnergyHealth + }, + requires: "not mass-energy", + effect() { + tech.isPiezo = true; + }, + remove() { + tech.isPiezo = false; + } + }, + { + name: "ground state", + description: "+300 maximum energy
0.66x passive energy generation", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isTimeCrystals + }, + requires: "not time crystals", + effect() { + tech.isGroundState = true + m.setFieldRegen() + m.setMaxEnergy() + }, + remove() { + tech.isGroundState = false + m.setFieldRegen() + m.setMaxEnergy() + } + }, + { + name: "heat engine", + description: `1.4x damage
–50 maximum energy`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => true, + requires: "not CPT", + damage: 1.4, + effect() { + tech.damage *= this.damage + tech.isMaxEnergyTech = true; + m.setMaxEnergy() + }, + remove() { + if (this.count && m.alive) tech.damage /= this.damage + tech.isMaxEnergyTech = false; + m.setMaxEnergy() + } + }, + { + name: "exothermic process", + description: "1.6x damage
after mobs die –5 energy", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + damage: 1.6, + effect() { + tech.damage *= this.damage + tech.isEnergyLoss = true; + }, + remove() { + if (this.count && m.alive) tech.damage /= this.damage + tech.isEnergyLoss = false; + } + }, + { + name: "Gibbs free energy", + descriptionFunction() { + return `1.006x damage for each missing energy
(${(1 + 0.5 * Math.max(0, m.maxEnergy - m.energy)).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isLowEnergyDamage = true; + }, + remove() { + tech.isLowEnergyDamage = false; + } + }, + { + name: "overcharge", + description: "+100 maximum energy
+5% JUNK choices", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.junkChance < 1 + }, + requires: "", + effect() { + tech.bonusEnergy += 1 + m.setMaxEnergy() + this.refundAmount += tech.addJunkTechToPool(0.05) + }, + refundAmount: 0, + remove() { + tech.bonusEnergy = 0; + m.setMaxEnergy() + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + }, + { + name: "Maxwells demon", + description: "energy above maximum decays 30x slower
+5% JUNK choices", + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.energy > m.maxEnergy || build.isExperimentSelection) && tech.junkChance < 1 + }, + requires: "energy above your max", + effect() { + tech.overfillDrain = 0.99 //70% = 1-(1-0.75)/(1-0.15) //92% = 1-(1-0.75)/(1-0.87) + this.refundAmount += tech.addJunkTechToPool(0.05) + }, + refundAmount: 0, + remove() { + tech.overfillDrain = 0.7 + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + }, + { + name: "inductive charging", + description: "if crouched 7x passive energy generation
otherwise 0x passive energy generation", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isDamageAfterKillNoRegen + }, + requires: "not parasitism", + effect() { + tech.isCrouchRegen = true; //only used to check for requirements + m.regenEnergy = function () { + if (m.immuneCycle < m.cycle && m.crouch && m.fieldCDcycle < m.cycle) m.energy += 7 * m.fieldRegen * level.isReducedRegen; + if (m.energy < 0) m.energy = 0 + } + }, + remove() { + tech.isCrouchRegen = false; + m.regenEnergy = m.regenEnergyDefault + } + }, + { + name: "energy conservation", + description: "doing damage to mobs generates energy", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.energySiphon += 0.04; + }, + remove() { + tech.energySiphon = 0; + } + }, + { + name: "parasitism", + description: "if a mob has died in the last 5 seconds
2x damage, no passive energy generation", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isCrouchRegen + }, + requires: "not inductive charging", + effect() { + tech.isDamageAfterKillNoRegen = true; + m.regenEnergy = function () { + if (m.immuneCycle < m.cycle && (m.lastKillCycle + 300 < m.cycle) && m.fieldCDcycle < m.cycle) m.energy += m.fieldRegen * level.isReducedRegen; + if (m.energy < 0) m.energy = 0 + } + }, + remove() { + if (this.count) m.regenEnergy = m.regenEnergyDefault + tech.isDamageAfterKillNoRegen = false; + } + }, + { + name: "waste heat recovery", + description: "if a mob has died in the last 5 seconds
generate 0.05x maximum energy every second", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isEnergyRecovery = true; + }, + remove() { + tech.isEnergyRecovery = false; + } + }, + { + name: "recycling", + descriptionFunction() { + return `if a mob has died in the last 5 seconds
recover 0.005x maximum ${tech.isEnergyHealth ? "energy" : "health"} every second` + }, + description: "", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isHealTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.isHealthRecovery = true; + }, + remove() { + tech.isHealthRecovery = false; + } + }, + { + name: "torpor", + description: "if a mob has not died in the last 5 seconds
0.3x damage taken", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isHarmReduceNoKill = true; + }, + remove() { + tech.isHarmReduceNoKill = false; + } + }, + { + name: "stability", + descriptionFunction() { + return `0.2x damage taken
while your health is at maximum` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isMaxHealthDefense = true; + }, + remove() { + tech.isMaxHealthDefense = false; + } + }, + { + name: "instability", + descriptionFunction() { + return `2.5x damage while your damage taken is 1.00x
(current damage taken = ${(m.defense()).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.noDefenseSettingDamage = true; + }, + remove() { + tech.noDefenseSettingDamage = false; + } + }, + { + name: "control theory", + descriptionFunction() { + return `2x damage
while your health is at maximum` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isMaxHealthDamage = true; + }, + remove() { + tech.isMaxHealthDamage = false; + } + }, + { + name: "homeostasis", + descriptionFunction() { + // return `0.9x damage taken for each ${name} missing
(${(Math.pow(0.1 * max, Math.max(0, max - h))).toFixed(2)}x)` + const scale = 0.2 //adjust this to control the strength of this effect + return `missing ${tech.isEnergyHealth ? "energy" : "health"} reduces damage taken
down to a limit of ${scale}x at 0 ${tech.isEnergyHealth ? "energy" : "health"}(${(Math.pow(scale, Math.max(0, 1 - (tech.isEnergyHealth ? m.energy / m.maxEnergy : m.health / m.maxHealth)))).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.health < 0.9 || build.isExperimentSelection + }, + requires: "health below 60", + effect() { + tech.isLowHealthDefense = true; + }, + remove() { + tech.isLowHealthDefense = false; + } + }, + { + name: "negative feedback", + descriptionFunction() { + return `1.006x damage for each missing ${tech.isEnergyHealth ? "energy" : "health"}
(${(1 + 0.6 * Math.max(0, (tech.isEnergyHealth ? m.maxEnergy - m.energy : m.maxHealth - m.health))).toFixed(2)}x)` //1 + 0.6 * Math.max(0, (tech.isEnergyHealth ? m.maxEnergy - m.energy : m.maxHealth - m.health)) + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.health < 0.9 || build.isExperimentSelection + }, + requires: "health below 90", + effect() { + tech.isLowHealthDmg = true; //used in mob.damage() + }, + remove() { + tech.isLowHealthDmg = false; + } + }, + { + name: "Zenos paradox", + descriptionFunction() { + return `0.15x damage taken
–5% of current ${tech.isEnergyHealth ? "energy" : "health"} every 5 seconds` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + effect() { + tech.isZeno = true; + }, + remove() { + tech.isZeno = false; + } + }, + { + name: "antiscience", + descriptionFunction() { + return `–10 ${tech.isEnergyHealth ? "energy" : "health"} after picking up ${powerUps.orb.tech()}
1.7x damage` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + damage: 1.7, + effect() { + tech.damage *= this.damage + tech.isTechDamage = true; + }, + remove() { + if (this.count && m.alive) tech.damage /= this.damage + tech.isTechDamage = false; + } + }, + { + name: "ergodicity", + descriptionFunction() { + return `0.50x healing from ${powerUps.orb.heal()}
1.7x damage` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + damage: 1.7, + effect() { + tech.damage *= this.damage + tech.isHalfHeals = true; + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "heal") { + const scale = Math.sqrt(0.5) + powerUp[i].size *= scale + Matter.Body.scale(powerUp[i], scale, scale); //grow + } + } + }, + remove() { + if (this.count && m.alive) { + tech.damage /= this.damage + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "heal") { + const scale = 1 / Math.sqrt(0.5) + powerUp[i].size *= scale + Matter.Body.scale(powerUp[i], scale, scale); //grow + } + } + } + tech.isHalfHeals = false; + } + }, + { + name: "fluoroantimonic acid", + description: "if your health is above 100
1.35x damage", + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.maxHealth > 1; + }, + requires: "maximum health above 100", + effect() { + tech.isAcidDmg = true; + }, + remove() { + tech.isAcidDmg = false; + } + }, + { + name: "induction brake", + descriptionFunction() { + return `after using ${powerUps.orb.heal()}
slow nearby mobs for 17 seconds` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isPerfectBrake + }, + requires: "not eddy current brake", + effect() { + tech.isHealBrake = true; + }, + remove() { + tech.isHealBrake = false; + } + }, + { + name: "adiabatic healing", + descriptionFunction() { + return `2x healing from ${powerUps.orb.heal()}
+4% JUNK choices` + }, + maxCount: 3, + count: 0, + frequency: 1, + frequencyDefault: 1, + isHealTech: true, + allowed() { + return ((m.health / m.maxHealth) < 0.7 || build.isExperimentSelection) && tech.junkChance < 1 + }, + requires: "under 70% health", + effect() { + tech.largerHeals++; + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "heal") { + const oldSize = powerUp[i].size + powerUp[i].size = powerUps.heal.size() //update current heals + const scale = powerUp[i].size / oldSize + Matter.Body.scale(powerUp[i], scale, scale); //grow + } + } + this.refundAmount += tech.addJunkTechToPool(0.04) + }, + refundAmount: 0, + remove() { + tech.largerHeals = 1; + for (let i = 0; i < powerUp.length; i++) { + if (powerUp[i].name === "heal") { + const oldSize = powerUp[i].size + powerUp[i].size = powerUps.heal.size() //update current heals + const scale = powerUp[i].size / oldSize + Matter.Body.scale(powerUp[i], scale, scale); //grow + } + } + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + }, + { + name: "quenching", + descriptionFunction() { + return `0.5x of ${powerUps.orb.heal()} overhealing
is added to maximum health` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isHealTech: true, + allowed() { + return !tech.isEnergyHealth + }, + requires: "not mass-energy", + effect() { + tech.isOverHeal = true; + }, + remove() { + tech.isOverHeal = false; + } + }, + { + name: "accretion", + descriptionFunction() { + return `${powerUps.orb.heal(1)} follow you, even between levels
+4% chance to duplicate spawned power ups` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isHealTech: true, + allowed() { + return m.fieldMode !== 9 + }, + requires: "not wormhole", + effect() { + tech.isHealAttract = true + powerUps.setPowerUpMode(); + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.04); + }, + remove() { + tech.isHealAttract = false + powerUps.setPowerUpMode(); + }, + }, + { + name: "accretion disk", + descriptionFunction() { + return `1.07x damage for each power up on this level
+5% JUNK choices (${(1 + 0.07 * powerUp.length).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isHealTech: true, + allowed() { + return tech.isHealAttract + }, + requires: "accretion", + effect() { + tech.isPowerUpDamage = true + this.refundAmount += tech.addJunkTechToPool(0.05) + }, + refundAmount: 0, + remove() { + tech.isPowerUpDamage = false + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + }, + }, + { + name: "maintenance", + descriptionFunction() { + return `2x frequency for ${powerUps.orb.tech()} with healing
spawn ${powerUps.orb.heal(13)}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + effect() { + for (let i = 0; i < 13; i++) powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "heal"); + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isHealTech) tech.tech[i].frequency *= 2 + } + }, + remove() { } + }, + { + name: "self-assembly", + descriptionFunction() { + return `at the start of each level
for every 20 missing ${tech.isEnergyHealth ? "energy" : "health"} spawn ${powerUps.orb.heal()}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isHealTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.isHealLowHealth = true; + }, + remove() { + tech.isHealLowHealth = false; + } + }, + { + name: "interest", + descriptionFunction() { + return `at the start of each level spawn
${(100 * this.rate).toFixed(0)}% of your ${powerUps.orb.research(1)}, ${powerUps.orb.ammo(1)}, ${powerUps.orb.coupling(1)}, and ${powerUps.orb.heal(1)} (rounded up)` + }, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return true + }, + requires: "", + rate: 0.05, + effect() { + tech.interestRate += this.rate; + }, + remove() { + tech.interestRate = 0; + } + }, + { + name: "anthropic principle", + // nameInfo: "", + // addNameInfo() { + // setTimeout(function () { + // powerUps.research.changeRerolls(0) + // }, 1000); + // }, + descriptionFunction() { + return `once per level, instead of dying use ${powerUps.orb.research(1)} and
spawn ${powerUps.orb.heal(22)}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isHealTech: true, + allowed() { + return powerUps.research.count > 0 || build.isExperimentSelection + }, + requires: "at least 1 research", + effect() { + tech.isDeathAvoid = true; + tech.isDeathAvoidedThisLevel = false; + setTimeout(function () { + powerUps.research.changeRerolls(0) + }, 1000); + }, + remove() { + tech.isDeathAvoid = false; + } + }, + { + name: "weak anthropic principle", + description: "after anthropic principle prevents your death
+60% duplication chance for that level", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return tech.isDeathAvoid + }, + requires: "anthropic principle", + effect() { + tech.isAnthropicTech = true + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + }, + remove() { + tech.isAnthropicTech = false + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + } + }, + { + name: "strong anthropic principle", + description: "after anthropic principle prevents your death
2.71828x damage for that level", + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return tech.isDeathAvoid + }, + requires: "anthropic principle", + effect() { + tech.isAnthropicDamage = true + }, + remove() { + tech.isAnthropicDamage = false + } + }, + { + name: "quantum immortality", + description: "0.7x damage taken
after dying, continue in an alternate reality", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isAltRealityTech: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.isImmortal = true; + }, + remove() { + tech.isImmortal = false; + } + }, + { + name: "many-worlds", + description: `at the start of each level spawn ${powerUps.orb.tech()}
and enter an alternate reality`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isAltRealityTech: true, + allowed() { + return !tech.isResearchReality && !tech.isCollisionRealitySwitch + }, + requires: "not Ψ(t) collapse, Hilbert space", + effect() { + tech.isSwitchReality = true; + }, + remove() { + tech.isSwitchReality = false; + } + }, + { + name: "Ψ(t) collapse", + link: `Ψ(t) collapse`, + description: `after a boss dies spawn ${powerUps.orb.research(6)}
if you research enter an alternate reality`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isAltRealityTech: true, + allowed() { + return !tech.isSwitchReality && !tech.isCollisionRealitySwitch && !tech.isJunkResearch + }, + requires: "not many-worlds, Hilbert space, pseudoscience", + bonusResearch: 21, + effect() { + tech.isResearchReality = true; + // for (let i = 0; i < this.bonusResearch; i++) powerUps.spawn(m.pos.x + Math.random() * 60, m.pos.y + Math.random() * 60, "research", false); + }, + remove() { + tech.isResearchReality = false; + // if (this.count > 0) powerUps.research.changeRerolls(-this.bonusResearch) + } + }, + { + name: "decoherence", + description: `after a boss dies spawn ${powerUps.orb.research(3)}
${powerUps.orb.tech()} options you don't choose won't reoccur`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isSuperDeterminism + }, + requires: "not, superdeterminism", + effect() { + tech.isBanish = true + }, + remove() { + if (tech.isBanish) { + tech.isBanish = false + //reset banish list + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].isBanished) tech.tech[i].isBanished = false + } + } + tech.isBanish = false + } + }, + { + name: "coherence", + description: `after observing a ${powerUps.orb.tech()} choice
that choice is available for all all future ${powerUps.orb.tech()}`, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return tech.isBanish + }, + requires: "decoherence", + effect() { + tech.isRetain = true + }, + remove() { + tech.isRetain = false + } + }, + { + name: "peer review", + description: `after you research gain 1.05x damage
and +1% JUNK choices`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (powerUps.research.count > 0 || build.isExperimentSelection) && !tech.isSuperDeterminism + }, + requires: "at least 1 research, not superdeterminism", + effect() { + tech.isResearchDamage = true; + }, + remove() { + tech.isResearchDamage = false; + } + }, + { + name: "pseudoscience", + description: "research 2 times for free, but
+1% JUNK choices each time", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isResearchReality && !tech.isSuperDeterminism + }, + requires: "not Ψ(t) collapse, superdeterminism", + effect() { + tech.isJunkResearch = true; + }, + remove() { + tech.isJunkResearch = false; + } + }, + { + name: "renormalization", + description: `47% chance to spawn ${powerUps.orb.research(1)} after consuming ${powerUps.orb.research(1)}
+5% JUNK choices`, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (powerUps.research.count > 3 || build.isExperimentSelection) && !tech.isSuperDeterminism && tech.junkChance < 1 + }, + requires: "at least 4 research, not superdeterminism", + effect() { + tech.renormalization = true; + this.refundAmount += tech.addJunkTechToPool(0.05) + + }, + refundAmount: 0, + remove() { + tech.renormalization = false; + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + }, + { + name: "perturbation theory", + description: `if you have no ${powerUps.orb.research(1)} in your inventory
2x fire rate`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return powerUps.research.count === 0 + }, + requires: "no research", + effect() { + tech.isRerollHaste = true; + powerUps.research.changeRerolls(0) + b.setFireCD(); + }, + remove() { + tech.isRerollHaste = false; + tech.researchHaste = 1; + b.setFireCD(); + } + }, + { + name: "Bayesian statistics", + descriptionFunction() { + return `1.05x damage per ${powerUps.orb.research(1)} in your inventory
(${(1 + Math.max(0, 0.05 * powerUps.research.count)).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return powerUps.research.count > 1 || build.isExperimentSelection + }, + requires: "at least 2 research", + effect() { + tech.isRerollDamage = true; + }, + remove() { + tech.isRerollDamage = false; + } + }, + { + name: "ansatz", + description: `after choosing ${powerUps.orb.field()}, ${powerUps.orb.tech()}, or ${powerUps.orb.gun()}
if you have no ${powerUps.orb.research(1)} in your inventory spawn ${powerUps.orb.research(3)}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return powerUps.research.count < 1 && !tech.isSuperDeterminism && !tech.isRerollHaste + }, + requires: "no research, not superdeterminism, Ψ(t) collapse, perturbation theory", + effect() { + tech.isAnsatz = true; + }, + remove() { + tech.isAnsatz = false; + } + }, + { + name: "unified field theory", + description: `when paused you can click to change your ${powerUps.orb.field()}
2x frequency for ${powerUps.orb.fieldTech()}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isSuperDeterminism + }, + requires: "not superdeterminism", + effect() { + tech.isPauseSwitchField = true; + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isFieldTech) tech.tech[i].frequency *= 2 + } + }, + remove() { + tech.isPauseSwitchField = false; + if (this.count > 1) { + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].isFieldTech) tech.tech[i].frequency /= 2 + } + } + } + }, + { + name: "eternalism", + description: `1.3x damage, but time doesn't pause
while choosing ${powerUps.orb.field()}, ${powerUps.orb.tech()}, or ${powerUps.orb.gun()}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isPauseSwitchField && !tech.isPauseEjectTech && !tech.isWormHolePause + }, + requires: "not unified field theory, paradigm shift, invariant", + damage: 1.3, + effect() { + tech.damage *= this.damage + tech.isNoDraftPause = true + }, + remove() { + if (this.count && m.alive) tech.damage /= this.damage + tech.isNoDraftPause = false + } + }, + { + name: "brainstorming", + description: `randomize ${powerUps.orb.tech()} choices
every 1.5 seconds for 10 seconds`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isSuperDeterminism + }, + requires: "not superdeterminism", + effect() { + tech.isBrainstorm = true + tech.isBrainstormActive = false + tech.brainStormDelay = 2000 - simulation.difficultyMode * 100 + }, + remove() { + tech.isBrainstorm = false + tech.isBrainstormActive = false + } + }, + { + name: "cross-disciplinary", + description: `${powerUps.orb.tech()} have an extra ${powerUps.orb.field()} or ${powerUps.orb.gun()} choice
+5% chance to duplicate spawned power ups`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isDeterminism + }, + requires: "not determinism", + effect() { + tech.isExtraGunField = true; + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.05); + }, + remove() { + tech.isExtraGunField = false; + if (this.count) powerUps.setPowerUpMode(); //needed after adjusting duplication chance + } + }, + { + name: "emergence", + description: `${powerUps.orb.field()}, ${powerUps.orb.tech()}, and ${powerUps.orb.gun()} have +1 choice
1.1x damage`, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isDeterminism + }, + requires: "not determinism", + damage: 1.1, + effect() { + tech.extraChoices += 1; + tech.damage *= this.damage + }, + refundAmount: 0, + remove() { + tech.extraChoices = 0; + if (this.count && m.alive) tech.damage /= this.damage + } + }, + { + name: "path integral", + link: `path integral`, + description: `your next ${powerUps.orb.tech()} has all possible choices
+4% JUNK choices`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + // isJunk: true, + allowed() { + return !tech.isDeterminism && !tech.isBrainstorm && tech.junkChance < 1 + }, + requires: "not determinism, brainstorm", + effect() { + tech.tooManyTechChoices = 1 + // for (let i = 0; i < this.bonusResearch; i++) powerUps.spawn(m.pos.x + 40 * (Math.random() - 0.5), m.pos.y + 40 * (Math.random() - 0.5), "research", false); + this.refundAmount += tech.addJunkTechToPool(0.04) + }, + refundAmount: 0, + remove() { + tech.tooManyTechChoices = 0 + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + }, + { + name: "determinism", + description: `spawn ${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}
${powerUps.orb.field()}, ${powerUps.orb.tech()}, and ${powerUps.orb.gun()} have only 1 choice`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + isInstant: true, + allowed() { + return !tech.extraChoices && !tech.isExtraGunField && !tech.isExtraBotOption + }, + requires: "not emergence, cross-disciplinary, integrated circuit", + effect() { + tech.isDeterminism = true; + //if you change the number spawned also change it in Born rule + for (let i = 0; i < 5; i++) powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "tech"); + }, + remove() { + tech.isDeterminism = false; + } + }, + { + name: "superdeterminism", + description: `spawn ${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}
you can't cancel and ${powerUps.orb.research(1)} no longer spawn`, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBadRandomOption: true, + isInstant: true, + allowed() { + return tech.isDeterminism && !tech.isAnsatz && !tech.isJunkResearch && !tech.isBrainstorm + }, + requires: "determinism, not ansatz, pseudoscience, brainstorming", + effect() { + tech.isSuperDeterminism = true; + //if you change the number spawned also change it in Born rule + for (let i = 0; i < 5; i++) powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "tech"); + }, + remove() { + tech.isSuperDeterminism = false; + } + }, + { + name: "technical debt", + descriptionFunction() { + return `increase damage by 4x, but reduce damage
by 0.15x for each ${powerUps.orb.tech()} you have(${(tech.totalCount > 20 ? (Math.pow(0.85, tech.totalCount - 20)) : (4 - 0.15 * tech.totalCount)).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.isTechDebt = true; + }, + remove() { + tech.isTechDebt = false; + } + }, + { + name: "meta-analysis", + description: `if you choose JUNK
you get a random choice and ${powerUps.orb.research(2)} instead`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.junkChance > 0.1 + }, + requires: "some JUNK tech", + effect() { + tech.isMetaAnalysis = true + }, + remove() { + tech.isMetaAnalysis = false + } + }, + { + name: "dark patterns", + description: "1.3x damage
+15% JUNK choices", + maxCount: 3, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.junkChance < 1 + }, + requires: "", + damage: 1.3, + effect() { + tech.damage *= this.damage + this.refundAmount += tech.addJunkTechToPool(0.15) + }, + refundAmount: 0, + remove() { + if (this.count && m.alive) { + tech.damage /= this.damage + if (this.refundAmount > 0) tech.removeJunkTechFromPool(this.refundAmount) + } + } + }, + { + name: "junk DNA", + descriptionFunction() { + return `increase damage by twice your
JUNK chance (${(1 + 2 * (tech.junkChance + level.junkAdded)).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.junkChance > 0 + }, + requires: "JUNK in tech pool", + effect() { + tech.isJunkDNA = true + }, + remove() { + tech.isJunkDNA = false + } + }, + { + name: "mass production", + descriptionFunction() { + return `${powerUps.orb.tech()} have extra choices to spawn ${powerUps.orb.ammo(1)},  ${powerUps.orb.heal(1)},  or  ${powerUps.orb.research(1)}
+3% chance to duplicate spawned power ups` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { return true }, + requires: "", + effect() { + tech.isMassProduction = true + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.03); + }, + remove() { + tech.isMassProduction = false + if (this.count) powerUps.setPowerUpMode(); //needed after adjusting duplication chance + + } + }, + { + name: "research", + descriptionFunction() { + return `spawn ${this.value > 36 ? this.value + powerUps.orb.research(1) : powerUps.orb.research(this.value)}
next time increase amount spawned by +4${powerUps.orb.research(1)}` + }, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isMassProduction: true, + allowed() { return true }, + requires: "", + value: 8, + defaultValue: 8, + effect() { + powerUps.spawnDelay("research", this.value); + this.value += 4 + }, + remove() { } + }, + { + name: "ammo", + descriptionFunction() { + return `spawn ${this.value > 33 ? this.value + powerUps.orb.ammo(1) : powerUps.orb.ammo(this.value)}
next time increase amount spawned by +7${powerUps.orb.ammo(1)}` + }, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isMassProduction: true, + allowed() { return true }, + requires: "", + value: 10, + defaultValue: 10, + effect() { + powerUps.spawnDelay("ammo", this.value); + this.value += 7 + }, + remove() { } + }, + { + name: "heals", + descriptionFunction() { + return `spawn ${this.value > 30 ? this.value + powerUps.orb.heal(1) : powerUps.orb.heal(this.value)}
next time increase amount spawned by +7${powerUps.orb.heal(1)}` + }, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isMassProduction: true, + allowed() { return true }, + requires: "", + value: 10, + defaultValue: 10, + effect() { + powerUps.spawnDelay("heal", this.value); + this.value += 7 + }, + remove() { } + }, + { + name: "field coupling", + descriptionFunction() { + return `spawn ${powerUps.orb.coupling(10)}
${m.couplingDescription(1)} per ${powerUps.orb.coupling(1)}` + }, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + allowed() { + return true + }, + requires: "", + effect() { + powerUps.spawnDelay("coupling", 10) + }, + remove() { + // if (this.count) m.couplingChange(-this.count * 10) + } + }, + { + name: "quintessence", + descriptionFunction() { + if (this.count) { + converted = this.researchUsed * this.couplingToResearch + let orbText + if (converted > 15) { + orbText = `${converted} ${powerUps.orb.coupling()}` + } else { + orbText = powerUps.orb.coupling(converted) + } + return `convert ${this.researchUsed} ${powerUps.orb.research(1)} into ${orbText}
${m.couplingDescription(1)} per ${powerUps.orb.coupling(1)}` + } else { + let converted = powerUps.research.count * this.couplingToResearch + let orbText + if (converted > 15) { + orbText = `${converted} ${powerUps.orb.coupling()}` + } else { + orbText = powerUps.orb.coupling(converted) + } + return `convert ${powerUps.research.count} ${powerUps.orb.research(1)} into ${orbText}
${m.couplingDescription(1)} per ${powerUps.orb.coupling(1)}` + } + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + allowed() { + return powerUps.research.count > 3 + }, + requires: "", + researchUsed: 0, + couplingToResearch: 3, + effect() { + // let count = 0 + // while (powerUps.research.count > 0 && powerUps.research.count !== Infinity) { + // powerUps.research.changeRerolls(-1) + // count += 2.5 + // this.researchUsed++ + // } + // powerUps.spawnDelay("coupling", Math.floor(count)) + + let cycle = () => { + if (powerUps.research.count > 0 && powerUps.research.count !== Infinity) { + if (m.alive) requestAnimationFrame(cycle); + if (!simulation.paused && !simulation.isChoosing) { //&& !(simulation.cycle % 2) + powerUps.research.changeRerolls(-1) + this.researchUsed++ + powerUps.spawnDelay("coupling", this.couplingToResearch) + } + } // else exit delay loop + + } + requestAnimationFrame(cycle); + }, + remove() { + if (this.count) { + m.couplingChange(-this.researchUsed * this.couplingToResearch) + powerUps.research.changeRerolls(this.researchUsed) + this.researchUsed = 0 + } + } + }, + { + name: "virtual particles", + descriptionFunction() { + return `17% chance after mobs die to spawn ${powerUps.orb.coupling(1)}
${m.couplingDescription(1)} per ${powerUps.orb.coupling(1)}` + // return `17% chance after mobs die to spawn ${powerUps.orb.coupling(1)} that each give +0.1 coupling` //
${m.couplingDescription(1)} ${m.fieldMode === 0 ? "" : "per coupling"} + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => true, + requires: "", + effect() { + tech.isCouplingPowerUps = true //about 20-30 mobs per level so at 16% and 0.1 coupling that's about 25 * 0.16 * 0.1 = 0.4 coupling per level with out duplication + }, + remove() { + tech.isCouplingPowerUps = false + } + }, + { + name: "fine-structure constant", + descriptionFunction() { + // return `spawn ${this.value} ${powerUps.orb.coupling(1)} that each give +0.1 coupling
-0.5 coupling after mob collisions`//
${m.couplingDescription(1)} ${m.fieldMode === 0 ? "" : "per coupling"} + return `after a boss dies spawn ${powerUps.orb.coupling(9)}
lose ${powerUps.orb.coupling(3)} after mob collisions`//
${m.couplingDescription(1)} per ${powerUps.orb.coupling(1)} + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + // isInstant: true, + allowed: () => true, + requires: "", + value: 60, + effect() { + tech.isCouplingNoHit = true + // powerUps.spawnDelay("coupling", this.value) + }, + remove() { + // if (this.count) m.couplingChange(-this.value) + tech.isCouplingNoHit = false + } + }, + { + name: "residual dipolar coupling", + descriptionFunction() { + return `clicking cancel spawns ${powerUps.orb.coupling(8)}
${m.couplingDescription(1)} per ${powerUps.orb.coupling(1)}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isSuperDeterminism + }, + requires: "not superdeterminism", + effect() { + tech.isCancelCouple = true + }, + remove() { + tech.isCancelCouple = false + } + }, + { + name: "commodities exchange", + descriptionFunction() { + return `clicking cancel for ${powerUps.orb.field()}, ${powerUps.orb.tech()}, or ${powerUps.orb.gun()}
spawns 8-12 ${powerUps.orb.heal()}, ${powerUps.orb.ammo()}, or ${powerUps.orb.research(1)}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isSuperDeterminism + }, + requires: "not superdeterminism", + effect() { + tech.isCancelRerolls = true + }, + remove() { + tech.isCancelRerolls = false + } + }, + { + name: "options exchange", + link: `options exchange`, + description: `clicking cancel for ${powerUps.orb.field()}, ${powerUps.orb.tech()}, or ${powerUps.orb.gun()}
will randomize with 3x choices, once a level`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isSuperDeterminism //&& (tech.isCancelRerolls || tech.isCancelDuplication || tech.isCancelCouple) + }, + requires: "not superdeterminism", //residual dipolar coupling, commodities exchange, futures exchange, + effect() { + tech.isCancelTech = true + tech.cancelTechCount = 0 + }, + remove() { + tech.isCancelTech = false + tech.cancelTechCount = 0 + } + }, + { + name: "futures exchange", + description: `clicking cancel for ${powerUps.orb.field()}, ${powerUps.orb.tech()}, or ${powerUps.orb.gun()}
gives +6% power up duplication chance`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.duplicationChance() < 1 && !tech.isSuperDeterminism + }, + requires: "below 100% duplication chance, not superdeterminism", + effect() { + tech.isCancelDuplication = true //search for tech.duplication to balance + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + }, + remove() { + tech.isCancelDuplication = false + if (this.count) powerUps.setPowerUpMode(); //needed after adjusting duplication chance + } + }, + { + name: "replication", + description: "+10% chance to duplicate spawned power ups
+10% JUNK choices", + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.duplicationChance() < 1 && tech.junkChance < 1 + }, + requires: "below 100% duplication chance", + effect() { + tech.duplicateChance += 0.1 + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.1); + this.refundAmount += tech.addJunkTechToPool(0.10) + }, + refundAmount: 0, + remove() { + tech.duplicateChance = 0 + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + }, + { + name: "metastability", + description: "+13% chance to duplicate spawned power ups
duplicates explode with a 4 second half-life", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.duplicationChance() < 1 + }, + requires: "below 100% duplication chance", + effect() { + tech.isPowerUpsVanish = true + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.11); + }, + remove() { + tech.isPowerUpsVanish = false + if (this.count) powerUps.setPowerUpMode(); //needed after adjusting duplication chance } + } + }, + { + name: "correlated damage", + descriptionFunction() { + return `duplication increases damage
(${(1 + Math.min(1, tech.duplicationChance())).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.duplicationChance() > 0.03 + }, + requires: "duplication chance > 3%", + effect() { + tech.isDupDamage = true; + }, + remove() { + tech.isDupDamage = false; + } + }, + { + name: "parthenogenesis", + description: "+8% chance to duplicate spawned power ups
duplication also duplicates mobs", + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.duplicationChance() > 0 + }, + requires: "some duplication chance", + effect() { + tech.isDuplicateMobs = true; + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.08); + }, + remove() { + tech.isDuplicateMobs = false; + if (this.count) powerUps.setPowerUpMode(); //needed after adjusting duplication chance + } + }, + { + name: "stimulated emission", + description: `+20% chance to duplicate spawned power ups,
collisions eject a random ${powerUps.orb.tech()}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.duplicationChance() < 1 + }, + requires: "below 1% duplication chance", + effect() { + tech.isStimulatedEmission = true + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.20); + }, + remove() { + tech.isStimulatedEmission = false + if (this.count) powerUps.setPowerUpMode(); //needed after adjusting duplication chance + } + }, + { + name: "strange attractor", + descriptionFunction() { + return `1.1x damage
removing this increases duplication by +11%` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + damage: 1.1, + effect() { + tech.damage *= this.damage + }, + isRemoveBenefit: true, + remove() { + if (this.count > 0 && m.alive) { + tech.duplication += 0.11 + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.11); + tech.damage /= this.damage + this.frequency = 0 + } + } + }, + { + name: "strange loop", + description: `1.1x damage
removing this gives a random ${powerUps.orb.tech()} with remove`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + damage: 1.1, + effect() { + tech.damage *= this.damage + }, + isRemoveBenefit: true, + remove() { + if (this.count > 0 && m.alive) { + tech.damage /= this.damage + this.frequency = 0 + + requestAnimationFrame(() => { + const options = [] + for (let i = 0, len = tech.tech.length; i < len; i++) if (tech.tech[i].isRemoveBenefit && tech.tech[i].count === 0) options.push(i) + const index = options[Math.floor(Math.random() * options.length)] + tech.giveTech(tech.tech[index].name) + }); + } + } + }, + { + name: "null hypothesis", + description: `1.1x damage
removing this spawns ${powerUps.orb.research(15)}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + damage: 1.1, + effect() { + tech.damage *= this.damage + }, + isRemoveBenefit: true, + remove() { + if (this.count > 0 && m.alive) { + tech.damage /= this.damage + requestAnimationFrame(() => { powerUps.spawnDelay("research", 15) }); + this.frequency = 0 + } + } + }, + { + name: "martingale", + descriptionFunction() { + return `${(1 + this.damage).toFixed(1)}x damage. removing this has a 50%
chance return with 2x its damage (${(1 + this.damage).toFixed(1)}x→${(1 + 2 * this.damage).toFixed(1)}x)
` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + damage: 0.1, + effect() { + tech.damage *= 1 + this.damage + }, + isRemoveBenefit: true, + remove() { + if (this.count > 0 && m.alive) { + tech.damage /= 1 + this.damage + if (Math.random() < 0.5) { + this.damage *= 2 + requestAnimationFrame(() => { tech.giveTech("martingale") }); + } + this.frequency = 0 + } + } + }, + { + name: "externality", + descriptionFunction() { + return `1.1x damage
removing this spawns ${this.ammo} ${powerUps.orb.ammo()}` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + damage: 1.1, + ammo: 50, + effect() { + tech.damage *= this.damage + }, + isRemoveBenefit: true, + remove() { + if (this.count > 0 && m.alive) { + tech.damage /= this.damage + this.frequency = 0 + requestAnimationFrame(() => { powerUps.spawnDelay("ammo", this.ammo) }); + } + } + }, + { + name: "deprecated", + scale: 0.08, + descriptionFunction() { + return `after removing this gain ${1 + this.scale}x damage
per ${powerUps.orb.tech()} removed this game(${(1 + this.scale * ((this.frequency === 0 ? 0 : 1) + tech.removeCount)).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + damage: 1.1, + effect() { + }, + isRemoveBenefit: true, + remove() { + if (this.count > 0 && m.alive) { + tech.damage *= 1 + this.scale * (1 + tech.removeCount) + this.frequency = 0 + } + } + }, + { + name: "planned obsolescence", + descriptionFunction() { + return `at the start of each level eject your oldest ${powerUps.orb.tech()}
and gain 1.1x damage each time` //(${(tech.isEjectOld).toFixed(2)}x) + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBadRandomOption: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.isEjectOld = true + }, + remove() { + tech.isEjectOld = false + } + }, + { + name: "paradigm shift", + descriptionFunction() { + return `when paused clicking your ${powerUps.orb.tech()} ejects them
costs ${tech.pauseEjectTech.toFixed(1)} ${tech.isEnergyHealth ? "energy" : "health"} (1.3x cost each use)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isSuperDeterminism + }, + requires: "not superdeterminism", + effect() { + tech.isPauseEjectTech = true; + }, + remove() { + tech.isPauseEjectTech = false; + + } + }, + { + name: "Born rule", + description: `eject all your ${powerUps.orb.tech()}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isBadRandomOption: true, + allowed() { + return (tech.totalCount > 6) + }, + requires: "more than 6 tech", + effect() { + // //remove active bullets //to get rid of bots + // for (let i = 0; i < bullet.length; ++i) Matter.Composite.remove(engine.world, bullet[i]); + // bullet = []; + // let count = 1 //count tech + // for (let i = 0, len = tech.tech.length; i < len; i++) { // spawn new tech power ups + // if (!tech.tech[i].isInstant) count += tech.tech[i].count + // } + // if (tech.isDeterminism) count -= 4 //remove the bonus tech + // if (tech.isSuperDeterminism) count -= 4 //remove the bonus tech + // const removeCount = tech.removeCount + // tech.resetAllTech(); // remove all tech + // tech.removeCount = removeCount + // if (simulation.isCheating) tech.setCheating(); + // lore.techCount = 0; + // // tech.addLoreTechToPool(); + // for (let i = 0; i < count; i++) powerUps.spawn(m.pos.x + 100 * (Math.random() - 0.5), m.pos.y + 100 * (Math.random() - 0.5), "tech"); // spawn new tech power ups + // //have state is checked in m.death() + + + let count = 0 //count tech + for (let i = 0, len = tech.tech.length; i < len; i++) { // spawn new tech power ups + if (!tech.tech[i].isInstant && tech.tech[i].count) { + count += tech.tech[i].count + tech.removeTech(i) + // powerUps.ejectTech(index) + } + } + powerUps.spawnDelay("tech", count); + // for (let i = 0; i < count; i++) powerUps.spawn(m.pos.x + 100 * (Math.random() - 0.5), m.pos.y + 100 * (Math.random() - 0.5), "tech"); // spawn new tech power ups + }, + remove() { } + }, + + { + name: "Occams razor", + descriptionFunction() { + return `randomly remove half your ${powerUps.orb.tech()}
for each removed ${(1 + this.damagePerRemoved).toFixed(2)}x damage (~${((this.count === 0) ? 1 + this.damagePerRemoved * 0.5 * tech.totalCount : this.damage).toFixed(2)}x)` + }, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isBadRandomOption: true, + allowed() { + return (tech.totalCount > 6) + }, + requires: "more than 6 tech", + damagePerRemoved: 0.5, + damage: null, + effect() { + let pool = [] + for (let i = 0, len = tech.tech.length; i < len; i++) { // spawn new tech power ups + if (tech.tech[i].count && !tech.tech[i].isInstant) pool.push(i) + } + pool = shuffle(pool); //shuffles order of maps + let removeCount = 0 + for (let i = 0, len = pool.length * 0.5; i < len; i++) removeCount += tech.removeTech(pool[i]) + this.damage = this.damagePerRemoved * removeCount + tech.damage *= (1 + this.damage) + simulation.inGameConsole(`tech.damage *= ${(1 + this.damage).toFixed(2)} //from Occam's razor`); + }, + remove() { + if (this.count && m.alive) tech.damage /= (1 + this.damage) + } + }, + { + name: "exchange symmetry", + description: `remove a random ${powerUps.orb.tech()}
spawn ${powerUps.orb.gun()}${powerUps.orb.gun()}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isBadRandomOption: true, + allowed() { + return (tech.totalCount > 3) && !tech.isSuperDeterminism + }, + requires: "at least 4 tech, not superdeterminism", + effect() { + const have = [] //find which tech you have + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].count > 0 && !tech.tech[i].isInstant) have.push(i) + } + const choose = have[Math.floor(Math.random() * have.length)] + for (let i = 0; i < tech.tech[choose].count; i++) { + powerUps.spawn(m.pos.x, m.pos.y, "gun"); + } + powerUps.spawn(m.pos.x, m.pos.y, "gun"); + tech.removeTech(choose) + }, + remove() { } + }, + { + name: "Monte Carlo method", + description: `remove a random ${powerUps.orb.tech()}
spawn ${powerUps.orb.tech()}${powerUps.orb.tech()}`, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + isBadRandomOption: true, + allowed() { + return (tech.totalCount > 3) && tech.duplicationChance() > 0 && !tech.isSuperDeterminism + }, + requires: "some duplication, at least 4 tech, not superdeterminism", + effect() { + const removeTotal = tech.removeTech() + for (let i = 0; i < removeTotal + 1; i++) powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "tech"); + }, + remove() { } + }, + //************************************************** + //************************************************** gun + //************************************************** tech + //************************************************** + { + name: "needle ice", + description: `after needles impact walls
they chip off 1-2 freezing ice IX crystals`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.isNeedles || tech.isNeedles) && !tech.needleTunnel + }, + requires: "nail gun, needle gun, not nanowires", + effect() { + tech.isNeedleIce = true + }, + remove() { + tech.isNeedleIce = false + } + }, + { + name: "nanowires", + description: `needles tunnel through blocks and map
1.2x needle damage`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return ((tech.haveGunCheck("nail gun") && tech.isNeedles) || (tech.isNeedles && tech.haveGunCheck("shotgun"))) && !tech.isNeedleIce + }, + requires: "nail gun, needle gun, not needle ice", + effect() { + tech.needleTunnel = true + }, + remove() { + tech.needleTunnel = false + } + }, + { + name: "ceramics", + description: `needles and harpoons pierce shields
directly damaging shielded mobs`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (!tech.isLargeHarpoon && tech.haveGunCheck("harpoon")) || tech.isNeedles || tech.isHookDefense + }, + requires: "needle gun, harpoon, not Bessemer process", + effect() { + tech.isShieldPierce = true + }, + remove() { + tech.isShieldPierce = false + } + }, + { + name: "needle gun", + description: "nail gun and shotgun fire mob piercing needles", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return ((tech.haveGunCheck("nail gun") && !tech.nailInstantFireRate && !tech.nailRecoil && !tech.isRicochet) || (tech.haveGunCheck("shotgun") && !tech.isNailShot && !tech.isFoamShot && !tech.isSporeWorm && !tech.isSporeFlea)) && !tech.isRivets && !tech.isIncendiary && !tech.isIceCrystals && !tech.isIceShot + }, + requires: "nail gun, shotgun, not ice crystal, rivets, rotary cannon, pneumatic, incendiary, nail-shot, foam-shot, worm-shot, ice-shot", + effect() { + tech.isNeedles = true + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "nail gun") { + b.guns[i].ammo = Math.ceil(b.guns[i].ammo / this.ammoScale); + b.guns[i].ammoPack = b.guns[i].defaultAmmoPack / this.ammoScale; + b.guns[i].chooseFireMethod() + simulation.updateGunHUD(); + break + } + } + }, + ammoScale: 3, + remove() { + if (tech.isNeedles) { + tech.isNeedles = false + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "nail gun") { + b.guns[i].chooseFireMethod() + b.guns[i].ammo = Math.ceil(b.guns[i].ammo * this.ammoScale); + b.guns[i].ammoPack = b.guns[i].ammo * this.ammoScale; + simulation.updateGunHUD(); + break + } + } + } + } + }, + { + name: "stress concentration", + description: "mobs below half durability die after you shoot
them near their center with needles or rivets", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.isNeedles || tech.isRivets) && !tech.isNailCrit && !tech.isIncendiary + }, + requires: "needles, rivets, not incendiary, supercritical fission", + effect() { + tech.isCritKill = true + }, + remove() { + tech.isCritKill = false + } + }, + { + name: "rivet gun", + description: "nail gun and shotgun slowly lob a heavy rivet", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return ((tech.haveGunCheck("nail gun") && !tech.nailInstantFireRate && !tech.isRicochet) || (tech.haveGunCheck("shotgun") && !tech.isNailShot && !tech.isFoamShot && !tech.isSporeWorm && !tech.isSporeFlea)) && !tech.isNeedles && !tech.isIceCrystals && !tech.isIceShot + }, + requires: "nail gun, shotgun, not ice crystal, needles, or pneumatic actuator", + effect() { + tech.isRivets = true + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "nail gun") { + b.guns[i].chooseFireMethod() + break + } + } + }, + remove() { + if (tech.isRivets) { + tech.isRivets = false + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "nail gun") { + b.guns[i].chooseFireMethod() + break + } + } + } + tech.isRivets = false + } + }, + { + name: "pneumatic actuator", + description: "nail gun takes no time to ramp up
to its fastest fire rate", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("nail gun") && !tech.isRivets && !tech.isNeedles && !tech.nailRecoil + }, + requires: "nail gun, not rotary cannon, rivets, or needles", + effect() { + tech.nailInstantFireRate = true + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "nail gun") b.guns[i].chooseFireMethod() + } + }, + remove() { + if (tech.nailInstantFireRate) { + tech.nailInstantFireRate = false + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "nail gun") b.guns[i].chooseFireMethod() + } + } + } + }, + { + name: "ice crystal nucleation", + link: `ice crystal nucleation`, + description: "nail gun uses energy instead of ammo
to condense freezing ice nails", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("nail gun") && !tech.isRivets && !tech.isNeedles // && !tech.isNailRadiation && !tech.isNailCrit + }, + requires: "nail gun, not rivets, needles", + effect() { + tech.isIceCrystals = true; + b.guns[0].ammoPack = Infinity + b.guns[0].recordedAmmo = b.guns[0].ammo + b.guns[0].ammo = Infinity + simulation.updateGunHUD(); + }, + remove() { + if (tech.isIceCrystals) { + tech.isIceCrystals = false; + b.guns[0].ammoPack = b.guns[0].defaultAmmoPack; + if (b.guns[0].recordedAmmo) b.guns[0].ammo = b.guns[0].recordedAmmo + simulation.updateGunHUD(); + if (this.count) requestAnimationFrame(() => { simulation.updateGunHUD(); }); + } + tech.isIceCrystals = false; + if (b.guns[0].ammo === Infinity) b.guns[0].ammo = 0 + } + }, + { + name: "rotary cannon", + description: `nail gun has increased muzzle speed,
maximum fire rate, accuracy, and recoil`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("nail gun") && !tech.nailInstantFireRate && !tech.isNeedles + }, + requires: "nail gun, not pneumatic actuator, needle gun", + effect() { + tech.nailRecoil = true + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "nail gun") b.guns[i].chooseFireMethod() + } + }, + remove() { + if (tech.nailRecoil) { + tech.nailRecoil = false + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "nail gun") b.guns[i].chooseFireMethod() + } + } + } + }, + { + name: "gauge", + description: `rivets, needles, super balls, and nails
have 1.3x mass and physical damage`, + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.hookNails + tech.isMineDrop + tech.isNailBotUpgrade + tech.fragments + tech.nailsDeathMob + (tech.haveGunCheck("super balls") + (tech.haveGunCheck("mine") && !tech.isFoamMine) + (tech.haveGunCheck("nail gun")) + tech.isNeedles + tech.isNailShot + tech.isRivets) * 2 > 1 + }, + requires: "nails, nail gun, rivets, shotgun, super balls, mine", + effect() { + tech.bulletSize = 1 + 0.25 * Math.pow(this.count + 1, 0.5) + }, + remove() { + tech.bulletSize = 1; + } + }, + { + name: "supercritical fission", + description: "if nails, needles, or rivets strike mobs
near their center they trigger an explosion", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.isNailShot || tech.isNeedles || tech.isNailBotUpgrade || tech.haveGunCheck("nail gun") || tech.isRivets || ((tech.isMineDrop || tech.haveGunCheck("mine")) && !(tech.isFoamMine || tech.isSuperMine))) && !tech.isIncendiary && !tech.isCritKill + }, + requires: "nail gun, mine, needles, nails, rivets, not incendiary, stress concentration", + effect() { + tech.isNailCrit = true + }, + remove() { + tech.isNailCrit = false + } + }, + { + name: "irradiated nails", + link: `irradiated nails`, + description: "nails, needles, and rivets are radioactive
2x radioactive damage over 3 seconds", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isNailBotUpgrade || tech.hookNails || tech.fragments || tech.nailsDeathMob || ((tech.isMineDrop || tech.haveGunCheck("mine")) && !(tech.isFoamMine || tech.isSuperMine)) || (tech.haveGunCheck("nail gun") && !tech.isShieldPierce) || (tech.haveGunCheck("shotgun") && (tech.isNeedles || tech.isNailShot)) + }, + requires: "nail gun, nails, rivets, mine, not ceramic needles", + effect() { + tech.isNailRadiation = true; + }, + remove() { + tech.isNailRadiation = false; + } + }, + { + name: "6s half-life", + link: `6s half-life`, + description: "nails, needles, rivets are made of plutonium-238
radioactive damage lasts +3 seconds", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isNailRadiation && !tech.isFastRadiation + }, + requires: "nail gun, mine, irradiated nails, not 1s half-life", + effect() { + tech.isSlowRadiation = true; + }, + remove() { + tech.isSlowRadiation = false; + } + }, + { + name: "1s half-life", + link: `1s half-life`, + description: "nails, needles, rivets are made of lithium-8
4x radioactive damage for 1 second
", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isNailRadiation && !tech.isSlowRadiation + }, + requires: "nail gun, mine, irradiated nails, not 6s half-life", + effect() { + tech.isFastRadiation = true; + }, + remove() { + tech.isFastRadiation = false; + } + }, + { + name: "spin-statistics", + link: `spin-statistics`, + description: `after firing the shotgun you are invulnerable
shotgun has 0.7x bullets per ${powerUps.orb.ammo(1)}`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("shotgun") + }, + requires: "shotgun", + effect() { + tech.isShotgunImmune = true; + + //cut current ammo by 1/2 + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "shotgun") { + b.guns[i].ammo = Math.ceil(b.guns[i].ammo * 0.7); + b.guns[i].ammoPack *= 0.7 + break; + } + } + simulation.updateGunHUD(); + }, + remove() { + tech.isShotgunImmune = false; + if (this.count > 0) { + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "shotgun") { + b.guns[i].ammoPack /= 0.7 + b.guns[i].ammo = Math.ceil(b.guns[i].ammo / 0.7); + simulation.updateGunHUD(); + break; + } + } + } + } + }, + { + name: "Newtons 3rd law", + description: "1.7x shotgun fire rate and recoil", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("shotgun") && !tech.isShotgunReversed + }, + requires: "shotgun, not Noether violation", + effect() { + tech.isShotgunRecoil = true; + }, + remove() { + tech.isShotgunRecoil = false; + } + }, + { + name: "Noether violation", + link: `Noether violation`, + description: "1.5x shotgun damage
shotgun recoil is reversed", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.haveGunCheck("shotgun")) && !tech.isShotgunRecoil + }, + requires: "shotgun, not Newtons 3rd law", + effect() { + tech.isShotgunReversed = true; + }, + remove() { + tech.isShotgunReversed = false; + } + }, + { + name: "repeater", + description: "shotgun immediately fires again for no ammo
reduced 0.5x shotgun fire rate", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("shotgun")) + }, + requires: "shotgun, not Newtons 3rd law", + effect() { + tech.shotgunExtraShots++; + }, + remove() { + tech.shotgunExtraShots = 0 + } + }, + { + name: "nail-shot", + link: `nail-shot`, + description: "shotgun drives a long clip of nails", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("shotgun") && !tech.isIncendiary && !tech.isRivets && !tech.isIceShot && !tech.isFoamShot && !tech.isSporeWorm && !tech.isSporeFlea && !tech.isNeedles + }, + requires: "shotgun, not incendiary, rivets, foam-shot, worm-shot, ice-shot, needles", + effect() { + tech.isNailShot = true; + }, + remove() { + tech.isNailShot = false; + } + }, + { + name: "foam-shot", + link: `foam-shot`, + description: "shotgun sprays sticky foam bubbles", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("shotgun") && !tech.isNailShot && !tech.isIncendiary && !tech.isRivets && !tech.isIceShot && !tech.isSporeWorm && !tech.isSporeFlea && !tech.isNeedles + }, + requires: "shotgun, not incendiary, nail-shot, rivet, worm-shot, ice-shot, needle", + effect() { + tech.isFoamShot = true; + }, + remove() { + tech.isFoamShot = false; + } + }, + { + name: "ice-shot", + link: `ice-shot`, + description: "shotgun condenses ice IX crystals
that freeze mobs", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("shotgun") && !tech.isNailShot && !tech.isIncendiary && !tech.isRivets && !tech.isFoamShot && !tech.isSporeWorm && !tech.isSporeFlea && !tech.isNeedles + }, + requires: "shotgun, not incendiary, nail-shot, rivet, foam-shot, worm-shot", + effect() { + tech.isIceShot = true; + }, + remove() { + tech.isIceShot = false; + } + }, + { + name: "freezer burn", + description: "mobs frozen while below 33% durability die", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isIceCrystals || tech.isSporeFreeze || (m.fieldMode === 4 && simulation.molecularMode === 2) || tech.isIceShot || tech.isNeedleIce || (m.coupling && (m.fieldMode === 2 || m.fieldMode === 0)) + }, + requires: "a freeze effect", + effect() { + tech.isIceKill = true + }, + remove() { + tech.isIceKill = false + } + }, + { + name: "flash freeze", + description: "mobs frozen while above 66% durability
have their durability reduced to 66%", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isIceCrystals || tech.isSporeFreeze || (m.fieldMode === 4 && simulation.molecularMode === 2) || tech.isIceShot || tech.isNeedleIce || (m.coupling && (m.fieldMode === 2 || m.fieldMode === 0)) + }, + requires: "a freeze effect", + effect() { + tech.isIceMaxHealthLoss = true + }, + remove() { + tech.isIceMaxHealthLoss = false + } + }, + { + name: "crystallizer", + description: "after frozen mobs die they
shatter into ice IX crystals", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.isIceCrystals || tech.isSporeFreeze || (m.fieldMode === 4 && simulation.molecularMode === 2) || tech.isIceShot || tech.isNeedleIce || (m.coupling && (m.fieldMode === 2 || m.fieldMode === 0))) && !tech.sporesOnDeath && !tech.isExplodeMob && !tech.botSpawner && !tech.isMobBlockFling && !tech.nailsDeathMob + }, + requires: "a localized freeze effect, no other mob death tech", + effect() { + tech.iceIXOnDeath++ + }, + remove() { + tech.iceIXOnDeath = 0 + } + }, + { + name: "thermoelectric effect", + description: "after killing mobs with ice IX
+100 energy", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.fieldMode === 4 && simulation.molecularMode === 2) || tech.isNeedleIce || (m.coupling && (m.fieldMode === 2 || m.fieldMode === 0)) || tech.iceIXOnDeath || tech.isIceShot + }, + requires: "ice IX", + effect() { + tech.iceEnergy++ + }, + remove() { + tech.iceEnergy = 0; + } + }, + { + name: "superfluidity", + description: "freeze effects are applied
to a small area around the target", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isIceCrystals || tech.isSporeFreeze || (m.fieldMode === 4 && simulation.molecularMode === 2) || tech.isNeedleIce || (m.coupling && (m.fieldMode === 2 || m.fieldMode === 0)) || tech.iceIXOnDeath || tech.isIceShot + }, + requires: "a localized freeze effect", + effect() { + tech.isAoESlow = true + }, + remove() { + tech.isAoESlow = false + } + }, + { + name: "triple point", + descriptionFunction() { + return `+5 second freeze duration` + }, + isGunTech: true, + maxCount: 3, + count: 0, + frequency: 1, + frequencyDefault: 1, + // allowed() { + // return (m.fieldMode === 2 && m.coupling > 0) || (tech.haveGunCheck("shotgun") && tech.isIceShot) + // }, + // requires: "perfect diamagnetism", + allowed() { + return (tech.isIceCrystals || tech.isSporeFreeze || (m.fieldMode === 4 && simulation.molecularMode === 2) || tech.isIceShot || tech.isNeedleIce || (m.coupling && (m.fieldMode === 2 || m.fieldMode === 0))) + }, + requires: "a localized freeze effect", + effect() { + tech.iceIXFreezeTime += 5 * 60 + // powerUps.spawnDelay("coupling", 10) + }, + remove() { + tech.iceIXFreezeTime = 150 + // if (this.count) m.couplingChange(-10 * this.count) + } + }, + { + name: "incendiary ammunition", + description: "shotgun, rivets, super balls, and drones
are loaded with explosives", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.haveGunCheck("shotgun") && !tech.isNailShot && !tech.isIceShot && !tech.isRivets && !tech.isFoamShot && !tech.isSporeWorm && !tech.isSporeFlea && !tech.isNeedles) || ((tech.haveGunCheck("super balls") || tech.isSuperMine) && !tech.isSuperBounce && !tech.isFoamBall && !tech.isSuperHarm) || (tech.isRivets && !tech.isNailCrit) || (m.fieldMode === 4 && simulation.molecularMode === 3) || (tech.haveGunCheck("drones") && !tech.isForeverDrones && !tech.isDroneRadioactive && !tech.isDroneTeleport) + }, + requires: "shotgun, super balls, rivets, drones, not irradiated drones, burst drones, polyurethane, Zectron", + effect() { + tech.isIncendiary = true + }, + remove() { + tech.isIncendiary = false; + } + }, + { + name: "rebound", + description: `after they collide with a mob, super balls
gain speed, duration, and 1.3x damage`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("super balls") || tech.isSuperMine) && !tech.isIncendiary && !tech.isFoamBall + }, + requires: "super balls, not incendiary", + effect() { + tech.isSuperBounce = true + }, + remove() { + tech.isSuperBounce = false + } + }, + { + name: "Zectron", + description: `2x super ball damage, but
after you collide with super balls they stop`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("super balls") || tech.isSuperMine) && !tech.isIncendiary && !tech.isBulletTeleport + }, + requires: "super balls not incendiary ammunition, uncertainty principle", + effect() { + tech.isSuperHarm = true + }, + remove() { + tech.isSuperHarm = false + } + }, + { + name: "polyurethane foam", + description: "super balls and harpoons colliding with mobs
catalyzes a reaction that yields foam bubbles", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return ((tech.haveGunCheck("super balls") || tech.isSuperMine) && !tech.isSuperBounce) || (tech.haveGunCheck("harpoon") && !tech.fragments) || tech.isHookDefense + }, + requires: "super balls, harpoon, not fragmentation", + effect() { + tech.isFoamBall = true; + }, + remove() { + tech.isFoamBall = false; + } + }, + { + name: "autocannon", + description: "fire +2 super balls in a line
1.4x super ball velocity and gravity", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("super balls") && !tech.oneSuperBall + }, + requires: "super balls, but not the tech super ball", + effect() { + tech.superBallDelay = true + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "super balls") b.guns[i].chooseFireMethod() + } + }, + remove() { + if (tech.superBallDelay) { + tech.superBallDelay = false; + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "super balls") b.guns[i].chooseFireMethod() + } + } + } + }, + { + name: "super duper", + description: `randomly fire +0, +1, +2, or +3 extra super balls`, + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("super balls") || tech.isSuperMine) && !tech.oneSuperBall + }, + requires: "super balls, not super ball", + effect() { + tech.extraSuperBalls += 4 + }, + remove() { + tech.extraSuperBalls = 0; + } + }, + { + name: "super ball", + description: "fire just 1 large super ball
that stuns mobs for 2 second", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("super balls") || tech.isSuperMine) && !tech.extraSuperBalls && !tech.superBallDelay + }, + requires: "super balls, not super duper or autocannon", + effect() { + tech.oneSuperBall = true; + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "super balls") b.guns[i].chooseFireMethod() + } + }, + remove() { + if (tech.oneSuperBall) { + tech.oneSuperBall = false; + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "super balls") b.guns[i].chooseFireMethod() + } + } + } + }, + { + name: "phase velocity", + description: "wave particles propagate faster as solids
1.5x wave damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("wave") && !tech.isLongitudinal + }, + requires: "wave, not phonon", + effect() { + tech.isPhaseVelocity = true; + }, + remove() { + tech.isPhaseVelocity = false; + } + }, + { + name: "amplitude", + description: "1.4x wave damage
1.4x wave bullet amplitude", + isGunTech: true, + maxCount: 3, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("wave") || tech.isSoundBotUpgrade + }, + requires: "wave", + effect() { + tech.waveFrequency *= 0.66 + tech.wavePacketDamage *= 1.4 + }, + remove() { + tech.waveFrequency = 0.2 //adjust this to make the waves much larger + tech.wavePacketDamage = 1 + } + }, + { + name: "propagation", + description: `0.75x wave propagation speed
1.4x wave damage`, + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("wave") || tech.isSoundBotUpgrade + }, + requires: "wave", + effect() { + tech.waveBeamSpeed *= 0.75; + tech.waveBeamDamage *= 1.4 //this sets base wave damage + }, + remove() { + tech.waveBeamSpeed = 11; + tech.waveBeamDamage = 0.4 //this sets base wave damage + } + }, + { + name: "bound state", + description: "wave packets reflect backwards 2 times
0.7x wave range", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("wave") && !tech.isLongitudinal + }, + requires: "wave, not phonon", + effect() { + tech.waveReflections += 2 + }, + remove() { + tech.waveReflections = 1 + } + }, + { + name: "frequency", + description: `wave has unlimited ammo
0.75x wave damage`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed: () => tech.haveGunCheck("wave"), + requires: "wave", + effect() { + tech.isInfiniteWaveAmmo = true + b.guns[3].savedAmmo = b.guns[3].ammo + b.guns[3].ammo = Infinity + simulation.updateGunHUD(); + }, + remove() { + tech.isInfiniteWaveAmmo = false + if (this.count > 0 && b.guns[3].savedAmmo !== undefined) { + b.guns[3].ammo = b.guns[3].savedAmmo + simulation.updateGunHUD(); + requestAnimationFrame(() => { simulation.updateGunHUD(); }); + } else if (b.guns[3].ammo === Infinity) { + b.guns[3].ammo = 0 + } + } + }, + { + name: "phonon", + description: "waves are low frequency, high damage
expanding arcs that propagate through solids", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return tech.haveGunCheck("wave") && !tech.isPhaseVelocity && tech.waveReflections === 1 + }, + requires: "wave, not phase velocity, bound state", + ammoScale: 6, + effect() { + tech.isLongitudinal = true; + b.guns[3].chooseFireMethod() + b.guns[3].ammoPack /= this.ammoScale + if (tech.isInfiniteWaveAmmo) { + b.guns[3].savedAmmo = Math.ceil(b.guns[3].savedAmmo / this.ammoScale); //used with low frequency + } else { + b.guns[3].ammo = Math.ceil(b.guns[3].ammo / this.ammoScale); + } + simulation.updateGunHUD(); + }, + remove() { + tech.isLongitudinal = false; + if (this.count > 0) { + b.guns[3].chooseFireMethod() + b.guns[3].ammoPack *= this.ammoScale + if (tech.isInfiniteWaveAmmo) { + b.guns[3].savedAmmo = Math.ceil(b.guns[3].savedAmmo * this.ammoScale); //used with low frequency + } else { + b.guns[3].ammo = Math.ceil(b.guns[3].ammo * this.ammoScale); + } + simulation.updateGunHUD(); + } + } + }, + { + name: "isotropic", + description: "waves expand in all directions
0.6x range and 1.5x damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return tech.isLongitudinal && tech.haveGunCheck("wave") && !tech.isBulletTeleport + }, + requires: "wave, phonon, not uncertainty principle", + effect() { + tech.is360Longitudinal = true; + b.guns[3].chooseFireMethod() + }, + remove() { + tech.is360Longitudinal = false; + b.guns[3].chooseFireMethod() + } + }, + { + name: "mechanical resonance", + description: "after a block gets vibrated by a phonon
there is a chance it's flung at nearby mobs", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.isLongitudinal && tech.haveGunCheck("wave")) || tech.isSoundBotUpgrade + }, + requires: "wave, phonon", + effect() { + tech.isPhononBlock = true + }, + remove() { + tech.isPhononBlock = false + } + }, + { + name: "sympathetic resonance", + description: "after a mob gets vibrated by a phonon
a new resonance wave expands", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.isLongitudinal && tech.haveGunCheck("wave")) || tech.isSoundBotUpgrade + }, + requires: "wave, phonon", + effect() { + tech.isPhononWave = true + }, + remove() { + tech.isPhononWave = false + } + }, + { + name: "missile-bot", + link: `missile-bot`, + description: `use ${powerUps.orb.research(1)}to trade your missile ${powerUps.orb.gun()}
for a bot that fires missiles`, + // isGunTech: true, + isRemoveGun: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + isInstant: true, + allowed() { + return tech.haveGunCheck("missiles", false) && tech.missileFireCD === 45 && (build.isExperimentSelection || powerUps.research.count > 0) + }, + requires: "missiles, not launch system", + effect() { + tech.missileBotCount++; + b.missileBot(); + if (tech.haveGunCheck("missiles", false)) b.removeGun("missiles") //remove your last gun + for (let i = 0; i < 1; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + // if (this.count) { + // tech.missileBotCount = 0; + // b.clearPermanentBots(); + // b.respawnBots(); + // if (!tech.haveGunCheck("missiles", false)) b.giveGuns("missiles") + // powerUps.research.changeRerolls(1) + // } + } + }, + { + name: "cruise missile", + description: "2x missile explosive damage, radius
0.5x missile speed", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("missiles") && tech.missileFireCD === 45) || (m.fieldMode === 4 && simulation.molecularMode === 1) || tech.missileBotCount + }, + requires: "missiles, not launch system", + effect() { + tech.isMissileBig = true + }, + remove() { + tech.isMissileBig = false + } + }, + { + name: "ICBM", + description: "1.75x missile explosive damage, radius
0.5x missile speed", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("missiles") || (m.fieldMode === 4 && simulation.molecularMode === 1)) && tech.isMissileBig + }, + requires: "missiles, cruise missile", + effect() { + tech.isMissileBiggest = true + }, + remove() { + tech.isMissileBiggest = false + } + }, + { + name: "launch system", + description: `5x missile fire rate
1.2x missile ammo per ${powerUps.orb.ammo(1)}`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("missiles") && !tech.isMissileBig + }, + requires: "missiles, not cruise missile", + ammoBonus: 1.2, + effect() { + tech.missileFireCD = 10 + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "missiles") { + b.guns[i].ammoPack *= this.ammoBonus; + b.guns[i].ammo = Math.ceil(b.guns[i].ammo * this.ammoBonus); + simulation.updateGunHUD(); + break + } + } + }, + remove() { + tech.missileFireCD = 45; + if (this.count > 0) { + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "missiles") { + b.guns[i].ammoPack /= this.ammoBonus; + b.guns[i].ammo = Math.ceil(b.guns[i].ammo / this.ammoBonus); + simulation.updateGunHUD(); + break + } + } + } + } + }, + { + name: "iridium-192", + description: "explosions release gamma radiation
2x explosion damage over 4 seconds", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isImmuneExplosion && tech.explosiveRadius === 1 && !tech.isSmallExplosion && !tech.isBlockExplode && !tech.fragments && (tech.haveGunCheck("missiles") || tech.missileBotCount || tech.isIncendiary || (tech.haveGunCheck("grenades") && !tech.isNeutronBomb) || tech.isPulseLaser || (m.fieldMode === 4 && simulation.molecularMode === 1) || tech.isBoomBotUpgrade || tech.isTokamak) + }, + requires: "an explosive damage source, not ammonium nitrate, nitroglycerin, chain reaction, fragmentation, electric armor", + effect() { + tech.isExplodeRadio = true; //iridium-192 + }, + remove() { + tech.isExplodeRadio = false; + } + }, + { + name: "fragmentation", + description: "some detonations and collisions eject nails
blocks, grenades, missiles, rivets, harpoon", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return !tech.isExplodeRadio && ((tech.haveGunCheck("harpoon") && !tech.isFoamBall) || (tech.haveGunCheck("grenades") && !tech.isNeutronBomb) || tech.haveGunCheck("missiles") || (m.fieldMode === 4 && simulation.molecularMode === 1) || tech.missileBotCount || tech.isRivets || tech.blockDamage > 0.075 || tech.isHookDefense) + }, + requires: "grenades, missiles, rivets, harpoon, or mass driver, not iridium-192, not polyurethane foam", + effect() { + tech.fragments++ + }, + remove() { + tech.fragments = 0 + } + }, + { + name: "ammonium nitrate", + description: "1.25x explosive damage, radius", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return !tech.isExplodeRadio && tech.hasExplosiveDamageCheck() + }, + requires: "an explosive damage source, not iridium-192", + effect() { + tech.explosiveRadius += 0.25; + }, + remove() { + tech.explosiveRadius = 1; + } + }, + { + name: "nitroglycerin", + description: "1.7x explosive damage
0.7x smaller explosive radius", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return !tech.isExplodeRadio && tech.hasExplosiveDamageCheck() && !tech.isExplosionHarm + }, + requires: "an explosive damage source, not iridium-192, acetone peroxide", + effect() { + tech.isSmallExplosion = true; + }, + remove() { + tech.isSmallExplosion = false; + } + }, + { + name: "acetone peroxide", + description: "1.7x explosive radius
1.4x explosive damage taken", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isBadRandomOption: true, + allowed() { + return tech.hasExplosiveDamageCheck() && !tech.isSmallExplosion + }, + requires: "an explosive damage source, not nitroglycerin", + effect() { + tech.isExplosionHarm = true; + }, + remove() { + tech.isExplosionHarm = false; + } + }, + { + name: "shock wave", + description: "mines and sporangium stun for 3-5 seconds
explosions stun for 0.5 seconds", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.haveGunCheck("spores") || tech.haveGunCheck("mine") || (!tech.isExplodeRadio && tech.hasExplosiveDamageCheck()) + }, + requires: "mine, spores, an explosive damage source, not iridium-192", + effect() { + tech.isStun = true; + }, + remove() { + tech.isStun = false; + } + }, + { + name: "shaped charge", + description: `use ${powerUps.orb.research(2)} to dynamically reduce
all explosions to prevent health loss`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return !tech.isImmuneExplosion && (build.isExperimentSelection || powerUps.research.count > 1) && (tech.haveGunCheck("missiles") || (m.fieldMode === 4 && simulation.molecularMode === 1) || tech.missileBotCount > 0 || tech.isIncendiary || tech.isPulseLaser || tech.isTokamak || (tech.haveGunCheck("grenades") && !tech.isNeutronBomb)) + }, + requires: "an explosive damage source, not rocket propelled grenade", + effect() { + tech.isSmartRadius = true; + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.isSmartRadius = false; + if (this.count > 0) powerUps.research.changeRerolls(3) + } + }, + { + name: "MIRV", + description: "fire +1 missile or grenade per shot
0.88x explosion damage and radius", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("missiles") || tech.missileBotCount || tech.haveGunCheck("grenades") + }, + requires: "missiles, grenades", + effect() { + tech.missileCount++; + }, + remove() { + tech.missileCount = 1; + } + }, + { + name: "rocket-propelled grenade", + description: "grenades explode on map collisions
explosions drain energy, not health", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("grenades") && !tech.isVacuumBomb && !tech.isSmartRadius && !tech.isEnergyHealth + }, + requires: "grenades, not vacuum bomb, shaped charges, mass-energy", + effect() { + tech.isImmuneExplosion = true; + tech.isRPG = true; + b.setGrenadeMode() + }, + remove() { + tech.isImmuneExplosion = false; + tech.isRPG = false; + b.setGrenadeMode() + } + }, + { + name: "vacuum bomb", + description: "grenades fire slower, explode bigger,
and suck everything towards them", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("grenades") && !tech.isNeutronBomb && !tech.isBlockExplode && !tech.isRPG + }, + requires: "grenades, not neutron bomb, chain reaction, RPG", + effect() { + tech.isVacuumBomb = true; + b.setGrenadeMode() + }, + remove() { + tech.isVacuumBomb = false; + b.setGrenadeMode() + } + }, + { + name: "chain reaction", + description: "1.3x grenade radius and damage
blocks caught in explosions also explode", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("grenades") && !tech.isExplodeRadio && !tech.isNeutronBomb && !tech.isVacuumBomb + }, + requires: "grenades, not iridium-192, neutron bomb, vacuum bomb", + effect() { + tech.isBlockExplode = true; //chain reaction + }, + remove() { + tech.isBlockExplode = false; + } + }, + { + name: "flame test", + description: "after grenades detonate they trigger
a colorful cluster of small explosions", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("grenades") && !tech.isNeutronBomb && !tech.isCircleExplode && !tech.isPetalsExplode + }, + requires: "grenades, not neutron bomb, pyrotechnics, fireworks", + effect() { + tech.isClusterExplode = true; + }, + remove() { + tech.isClusterExplode = false; + } + }, + { + name: "pyrotechnics", + description: "after grenades detonate they trigger
a colorful circle of explosions", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("grenades") && !tech.isNeutronBomb && !tech.isClusterExplode && !tech.isPetalsExplode + }, + requires: "grenades, not neutron bomb, flame test, fireworks", + effect() { + tech.isCircleExplode = true; + }, + remove() { + tech.isCircleExplode = false; + } + }, + { + name: "fireworks", + description: "after grenades detonate they trigger
colorful petals of explosions", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("grenades") && !tech.isNeutronBomb && !tech.isClusterExplode && !tech.isCircleExplode + }, + requires: "grenades, not neutron bomb, pyrotechnics, flame test", + effect() { + tech.isPetalsExplode = true; + }, + remove() { + tech.isPetalsExplode = false; + } + }, + { + name: "neutron bomb", + description: "grenades are irradiated with Cf-252
does radioactive damage over time", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("grenades") && !tech.fragments && !tech.isVacuumBomb && !tech.isExplodeRadio && !tech.isBlockExplode && !tech.isClusterExplode && !tech.isPetalsExplode && !tech.isCircleExplode + }, + requires: "grenades, not fragmentation, vacuum bomb, iridium-192, pyrotechnics, fireworks, flame test, chain reaction", + effect() { + tech.isNeutronBomb = true; + b.setGrenadeMode() + }, + remove() { + tech.isNeutronBomb = false; + b.setGrenadeMode() + } + }, + { + name: "vacuum permittivity", + description: "1.2x radioactive range
objects in range of the bomb are slowed", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isNeutronBomb + }, + requires: "grenades, neutron bomb", + effect() { + tech.isNeutronSlow = true + }, + remove() { + tech.isNeutronSlow = false + } + }, + { + name: "radioactive contamination", + description: "after a mob or shield dies,
leftover radiation spreads to a nearby mob", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isNailRadiation || tech.isWormholeDamage || tech.isNeutronBomb || tech.isExplodeRadio || tech.isBlockRadiation + }, + requires: "radiation damage source", + effect() { + tech.isRadioactive = true + }, + remove() { + tech.isRadioactive = false + } + }, + { + name: "nuclear transmutation", + description: "1.5x radiation damage
nail, drone, neutron bomb, iridium, cosmic string, deflect", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isNailRadiation || tech.isWormholeDamage || tech.isNeutronBomb || tech.isExplodeRadio || tech.isBlockRadiation || tech.isDroneRadioactive + }, + requires: "radiation damage source", + effect() { + tech.radioactiveDamage += 1.5 + }, + remove() { + tech.radioactiveDamage = 1 + } + }, + { + name: "water shielding", + link: `water shielding`, + description: "reduce radioactive effects on you by 0.2x
neutron bomb, drones, explosions, slime", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isNeutronBomb || tech.isDroneRadioactive || tech.isExplodeRadio + }, + requires: "neutron bomb, irradiated drones, iridium-192", + effect() { + tech.isRadioactiveResistance = true + }, + remove() { + tech.isRadioactiveResistance = false + } + }, + { + name: "ricochet", + description: "after nails hit a mob they rebound towards
a new mob with 2.8x damage per bounce", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + // return (tech.haveGunCheck("nail gun") && !tech.isRivets && !tech.isNeedles) || (tech.haveGunCheck("mines")) + return tech.isMineDrop || tech.isNailBotUpgrade || tech.hookNails || tech.fragments || tech.nailsDeathMob || (tech.haveGunCheck("mine") && !(tech.isLaserMine || tech.isFoamMine || tech.isSuperMine)) || (tech.haveGunCheck("nail gun") && !tech.isRivets && !tech.isNeedles) || (tech.haveGunCheck("shotgun") && (tech.isNeedles || tech.isNailShot) && !tech.isRivets && !tech.isNeedles) + }, + // + requires: "nail gun, not rotary cannon, rivets, or needles", + effect() { + tech.isRicochet = true + }, + remove() { + tech.isRicochet = false + } + }, + { + name: "booby trap", + description: "50% chance to drop a mine from power ups
+15% JUNK choices", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("mine") && tech.junkChance < 1 + }, + requires: "mines", + effect() { + tech.isMineDrop = true; + if (tech.isMineDrop) b.mine(m.pos, { x: 0, y: 0 }, 0) + this.refundAmount += tech.addJunkTechToPool(0.15) + }, + refundAmount: 0, + remove() { + tech.isMineDrop = false; + if (this.count > 0 && this.refundAmount > 0) { + tech.removeJunkTechFromPool(this.refundAmount) + this.refundAmount = 0 + } + } + }, + { + name: "elephants toothpaste", + description: "instead of nails mines catalyze a reaction
that yields foam bubbles", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("mine") && !tech.isSuperMine && !tech.isRicochet && !tech.isNailRadiation && !tech.isNailCrit + }, + requires: "mines, not blast ball, ricochet, irradiated nails, supercritical fission", + effect() { + tech.isFoamMine = true; + }, + remove() { + tech.isFoamMine = false; + } + }, + { + name: "blast ball", + descriptionFunction() { + return `mines fire bouncy balls instead of nails` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("mine") && !tech.isFoamMine && !tech.isRicochet && !tech.isNailRadiation && !tech.isNailCrit + }, + requires: "mines, not elephants toothpaste, ricochet, irradiated nails, supercritical fission", + effect() { + tech.isSuperMine = true; + }, + remove() { + tech.isSuperMine = false; + } + }, + { + name: "laser-mines", + link: `laser-mines`, + description: "mines laid while you are crouched
use energy to emit 3 unaimed lasers", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("mine") + }, + requires: "mines", + effect() { + tech.isLaserMine = true; + }, + remove() { + tech.isLaserMine = false; + } + }, + { + name: "sentry", + descriptionFunction() { + return `mines fire one ${b.guns[10].nameString()} at a time
mines fire 1.5x more ${b.guns[10].nameString('s')}` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("mine") + }, + requires: "mines, not elephants toothpaste", + effect() { + tech.isMineSentry = true; + }, + remove() { + tech.isMineSentry = false; + } + }, + { + name: "extended magazine", + descriptionFunction() { + return `sentry mines fire 1.5x more ${b.guns[10].nameString('s')}` + }, + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("mine") && tech.isMineSentry + }, + requires: "mines, sentry", + effect() { + tech.sentryAmmo += 17; + }, + remove() { + tech.sentryAmmo = 33; + } + }, + { + name: "mycelial fragmentation", + link: `mycelial fragmentation`, + description: "during their growth phase
1.7x sporangium discharge", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("spores") + }, + requires: "spores", + effect() { + tech.isSporeGrowth = true + }, + remove() { + tech.isSporeGrowth = false + } + }, + { + name: "cordyceps", + // descriptionFunction() { + // return `mobs infected by ${b.guns[6].nameString('s')} have a 5% chance
to resurrect and attack other mobs` + // }, + description: "sporangium infect mobs they attach to
infected mobs resurrect and attack other mobs", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("spores") + }, + requires: "spores", + effect() { + tech.isZombieMobs = true + }, + remove() { + tech.isZombieMobs = false + } + }, + { + name: "colony", + description: "1.6x sporangium discharge
33% chance to discharge something different", + link: `colony`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("spores") + }, + requires: "spores", + effect() { + tech.isSporeColony = true + }, + remove() { + tech.isSporeColony = false + } + }, + { + name: "cryodesiccation", + descriptionFunction() { + return `1.25x sporangium discharge
${b.guns[6].nameString('s')} freeze mobs for 1.5 second` + }, + // description: "+25% sporangium discharge
spores freeze mobs for 1.5 second", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("spores") || tech.sporesOnDeath > 0 || (m.fieldMode === 4 && simulation.molecularMode === 0) || tech.isSporeWorm || tech.isSporeFlea + }, + requires: "spores", + effect() { + tech.isSporeFreeze = true + }, + remove() { + tech.isSporeFreeze = false + } + }, + { + name: "flagella", + descriptionFunction() { + return `2x ${b.guns[6].nameString()} acceleration
if they can't find a target ${b.guns[6].nameString('s')} follow you` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("spores") || tech.sporesOnDeath > 0 || (m.fieldMode === 4 && simulation.molecularMode === 0) || tech.isSporeWorm || tech.isSporeFlea + }, + requires: "spores", + effect() { + tech.isSporeFollow = true + }, + remove() { + tech.isSporeFollow = false + } + }, + { + name: "mutualism", + descriptionFunction() { + return `3x ${b.guns[6].nameString()} damage
${b.guns[6].nameString('s')} borrow 1 health until they die` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("spores") || tech.sporesOnDeath > 0 || (m.fieldMode === 4 && simulation.molecularMode === 0)) || tech.isSporeWorm || tech.isSporeFlea + }, + requires: "spores", + effect() { + tech.isMutualism = true + }, + remove() { + tech.isMutualism = false + } + }, + { + name: "necrophage", + description: "if foam, fleas, or worms kill their target
they grow 3 copies", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("foam") || tech.isFoamBall || tech.isFoamBotUpgrade || tech.isFoamShot || tech.isSporeWorm || tech.isSporeFlea || tech.isFoamMine + }, + requires: "foam, spores, worms, fleas", + effect() { + tech.isSpawnBulletsOnDeath = true + }, + remove() { + tech.isSpawnBulletsOnDeath = false; + } + }, + { + name: "siphonaptera", + description: "spores metamorphose into fleas
shotgun fires fleas", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (tech.haveGunCheck("spores") || tech.sporesOnDeath > 0 || (m.fieldMode === 4 && simulation.molecularMode === 0) || (tech.haveGunCheck("shotgun") && !tech.isIncendiary && !tech.isRivets && !tech.isIceShot && !tech.isFoamShot && !tech.isNeedles && !tech.isNailShot)) && !tech.isSporeWorm + }, + requires: "spores, not worms", + effect() { + tech.isSporeFlea = true + }, + remove() { + tech.isSporeFlea = false + + } + }, + { + name: "nematodes", + description: "spores metamorphose into worms
shotgun fires worms", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (tech.haveGunCheck("spores") || tech.sporesOnDeath > 0 || (m.fieldMode === 4 && simulation.molecularMode === 0) || (tech.haveGunCheck("shotgun") && !tech.isIncendiary && !tech.isRivets && !tech.isIceShot && !tech.isFoamShot && !tech.isNeedles && !tech.isNailShot)) && !tech.isSporeFlea + }, + requires: "spores, not fleas", + effect() { + tech.isSporeWorm = true + }, + remove() { + tech.isSporeWorm = false + } + }, + { + name: "K-selection", + description: "1.37x worm and flea damage", + isGunTech: true, + maxCount: 3, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isSporeWorm || tech.isSporeFlea + }, + requires: "spores, shotgun, worms, fleas", + effect() { + tech.wormSize++ + }, + remove() { + tech.wormSize = 0 + } + }, + { + name: "path integration", + descriptionFunction() { + return `drones and ${b.guns[6].nameString("s")}
travel with you through levels` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.isSporeFollow && (tech.haveGunCheck("spores") || (tech.haveGunCheck("shotgun") && tech.isSporeWorm))) || tech.haveGunCheck("drones") || (m.fieldMode === 4 && (simulation.molecularMode === 0 || simulation.molecularMode === 3)) + }, + requires: "spores, worms, flagella, drones", + effect() { + tech.isDronesTravel = true + }, + remove() { + tech.isDronesTravel = false + } + }, + { + name: "fault tolerance", + description: `use ${powerUps.orb.research(2)}to trade your drone ${powerUps.orb.gun()}
for 5 drones that last forever`, + // isGunTech: true, + isRemoveGun: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isInstant: true, + allowed() { + return tech.haveGunCheck("drones", false) && !tech.isDroneRespawn && tech.bulletsLastLonger === 1 && !tech.isDronesTravel && (build.isExperimentSelection || powerUps.research.count > 1) + }, + requires: "drones, not drone repair, anti-shear topology, autonomous navigation, ", + effect() { + const num = 5 + tech.isForeverDrones += num + if (tech.haveGunCheck("drones", false)) b.removeGun("drones") + //spawn drones + if (tech.isDroneRadioactive) { + for (let i = 0; i < num * 0.25; i++) { + b.droneRadioactive({ + x: m.pos.x + 30 * (Math.random() - 0.5), + y: m.pos.y + 30 * (Math.random() - 0.5) + }, 5) + bullet[bullet.length - 1].endCycle = Infinity + } + } else { + for (let i = 0; i < num; i++) { + b.drone({ + x: m.pos.x + 30 * (Math.random() - 0.5), + y: m.pos.y + 30 * (Math.random() - 0.5) + }, 5) + bullet[bullet.length - 1].endCycle = Infinity + } + } + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.isForeverDrones = 0 + // if (this.count && !tech.haveGunCheck("drones", false)) b.giveGuns("drones") + // if (this.count > 0) powerUps.research.changeRerolls(2) + } + }, + { + name: "ablative drones", + descriptionFunction() { + return `after losing ${tech.isEnergyHealth ? "energy" : "health"} there is a chance
to rebuild your broken parts as drones` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.haveGunCheck("drones") && !tech.isForeverDrones && !tech.isDroneRadioactive) || (m.fieldMode === 4 && simulation.molecularMode === 3) + }, + requires: "drones, not fault tolerance, irradiated drones", + effect() { + tech.isDroneOnDamage = true; + }, + remove() { + tech.isDroneOnDamage = false; + } + }, + { + name: "reduced tolerances", + link: `reduced tolerances`, + description: `2x drones per ${powerUps.orb.ammo()} and energy
0.6x drone duration`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return !tech.isDroneRadioactive && (tech.haveGunCheck("drones") || (m.fieldMode === 4 && simulation.molecularMode === 3)) + }, + requires: "drones, not irradiated drones", + effect() { + tech.droneCycleReduction = 0.6 + tech.droneEnergyReduction = 0.3 + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "drones") b.guns[i].ammoPack *= 2 + } + }, + remove() { + tech.droneCycleReduction = 1 + tech.droneEnergyReduction = 1 + if (this.count > 0) { + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "drones") b.guns[i].ammoPack /= 2 + } + } + } + }, + { + name: "delivery drone", + description: "if a drone picks up a power up,
it becomes larger, faster, and more durable", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("drones") || tech.isForeverDrones || (m.fieldMode === 4 && simulation.molecularMode === 3) + }, + requires: "drones", + effect() { + tech.isDroneGrab = true + }, + remove() { + tech.isDroneGrab = false + } + }, + { + name: "von Neumann probe", //"drone repair", + description: "after a drone expires it will use -4 energy
and a nearby block to replicate itself", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("drones") || (m.fieldMode === 4 && simulation.molecularMode === 3) + }, + requires: "drones", + effect() { + tech.isDroneRespawn = true + }, + remove() { + tech.isDroneRespawn = false + } + }, + { + name: "brushless motor", + description: "drones rapidly rush towards their target
1.33x drone collision damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (tech.haveGunCheck("drones") || tech.isForeverDrones || (m.fieldMode === 4 && simulation.molecularMode === 3)) && !tech.isDroneRadioactive && !tech.isIncendiary + }, + requires: "drones, molecular assembler, not irradiated drones, incendiary", + effect() { + tech.isDroneTeleport = true + }, + remove() { + tech.isDroneTeleport = false + } + }, + { + name: "axial flux motor", + description: "1.66x drones rush frequency
1.44x drone collision damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isDroneTeleport + }, + requires: "drones, brushless motor", + effect() { + tech.isDroneFastLook = true + }, + remove() { + tech.isDroneFastLook = false + } + }, + { + name: "irradiated drones", + link: `irradiated drones`, + description: `the space around drones is irradiated
0.25x drones per ${powerUps.orb.ammo()} and energy`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.droneCycleReduction === 1 && !tech.isDroneOnDamage && !tech.isIncendiary && !tech.isDroneTeleport && (tech.haveGunCheck("drones") || tech.isForeverDrones || (m.fieldMode === 4 && simulation.molecularMode === 3)) + }, + requires: "drones, not reduced tolerances, incendiary, torque bursts, ablative drones", + effect() { + tech.isDroneRadioactive = true + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "drones") { + b.guns[i].ammoPack *= 0.25 + b.guns[i].ammo = Math.ceil(b.guns[i].ammo * 0.25) + simulation.makeGunHUD(); + } + } + }, + remove() { + tech.isDroneRadioactive = false + if (this.count > 0) { + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "drones") { + b.guns[i].ammoPack /= 0.25 + b.guns[i].ammo = b.guns[i].ammo * 4 + simulation.makeGunHUD(); + } + } + } + } + }, + { + name: "beta radiation", //"control rod ejection", + description: "0.5x drone duration
2x drone radiation damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isDroneRadioactive + }, + requires: "drones, irradiated drones", + effect() { + tech.droneRadioDamage = 2 + }, + remove() { + tech.droneRadioDamage = 1 + } + }, + { + name: "orthocyclic winding", + link: `orthocyclic winding`, + description: "1.66x drone acceleration
1.33x radiation damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isDroneRadioactive + }, + requires: "drones, irradiated drones", + effect() { + tech.isFastDrones = true + }, + remove() { + tech.isFastDrones = false + } + }, + { + name: "electrostatic induction", + description: "foam bubbles are electrically charged
causing attraction to nearby mobs", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.haveGunCheck("foam") || tech.isFoamBotUpgrade || tech.isFoamShot || tech.isFoamBall || tech.isFoamMine + }, + requires: "foam", + effect() { + tech.isFoamAttract = true + }, + remove() { + tech.isFoamAttract = false + } + }, + { + name: "uncertainty principle", + description: "foam, wave, and super ball positions are erratic
1.5x foam, wave, and super ball damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.haveGunCheck("foam") || tech.isFoamBotUpgrade || tech.isFoamShot || tech.isFoamBall || tech.isFoamMine) || (tech.haveGunCheck("wave") && !tech.is360Longitudinal) || (tech.haveGunCheck("super balls") && !tech.isSuperHarm) || tech.isSoundBotUpgrade + }, + requires: "foam, wave, super balls, not isotropic, Zectron", + effect() { + tech.isBulletTeleport = true + }, + remove() { + tech.isBulletTeleport = false; + } + }, + { + name: "surfactant", + description: `use ${powerUps.orb.research(2)}to trade your foam ${powerUps.orb.gun()}
for 2 foam-bots and foam-bot upgrade`, + // isGunTech: true, + isRemoveGun: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + isBot: true, + isBotTech: true, + isInstant: true, + requires: "foam gun, not bot upgrades, fractionation, pressure vessel", + allowed() { + return tech.haveGunCheck("foam", false) && !b.hasBotUpgrade() && !tech.isAmmoFoamSize && !tech.isFoamPressure && (build.isExperimentSelection || powerUps.research.count > 1) + }, + effect() { + + requestAnimationFrame(() => { tech.giveTech("foam-bot upgrade") }) + for (let i = 0; i < 2; i++) { + b.foamBot() + tech.foamBotCount++; + } + simulation.inGameConsole(`tech.isFoamBotUpgrade = true`) + if (tech.haveGunCheck("foam", false)) b.removeGun("foam") + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + // if (this.count) { + // b.clearPermanentBots(); + // b.respawnBots(); + // if (!tech.haveGunCheck("foam")) b.giveGuns("foam") + // } + // if (this.count > 0) powerUps.research.changeRerolls(2) + } + }, + { + name: "aerogel", + description: "foam bubbles float with 0.5x foam duration
2.8x foam damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("foam") || tech.isFoamBotUpgrade || tech.isFoamShot || tech.isFoamBall || tech.isFoamMine + }, + requires: "foam", + effect() { + tech.isFastFoam = true + tech.foamGravity = -0.0003 + }, + remove() { + tech.isFastFoam = false; + tech.foamGravity = 0.00008 + } + }, + { + name: "surface tension", + description: "1.4x foam damage", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("foam") || tech.isFoamBotUpgrade || tech.isFoamShot || tech.isFoamBall || tech.isFoamMine + }, + requires: "foam", + effect() { + tech.foamDamage += 0.01 * 0.4 + }, + remove() { + tech.foamDamage = 0.01; + } + }, + { + name: "cavitation", + description: "25% chance to discharge a huge foam bubble
2x foam gun recoil", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("foam") || tech.isFoamBotUpgrade || tech.isFoamShot || tech.isFoamBall || tech.isFoamMine + }, + requires: "foam", + effect() { + tech.isFoamCavitation = true; + b.guns[8].knockBack = 0.001 + }, + remove() { + tech.isFoamCavitation = false; + b.guns[8].knockBack = 0.0005 + } + }, + { + name: "foam fractionation", + description: "if you have below 300 ammo
2x foam bubble size", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("foam") + }, + requires: "foam", + effect() { + tech.isAmmoFoamSize = true + }, + remove() { + tech.isAmmoFoamSize = false; + } + }, + { + name: "ideal gas law", + description: `6x foam ammo per ${powerUps.orb.ammo(1)}`, //remove all current foam ammo
+ isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("foam") && !tech.isEnergyNoAmmo + }, + requires: "foam, not non-renewables", + // ammoLost: 0, + effect() { + b.guns[8].ammoPack *= 6; + // this.ammoLost = b.guns[8].ammo + // b.guns[8].ammo = 0 + simulation.updateGunHUD() + }, + remove() { + if (this.count) { + b.guns[8].ammoPack /= 8 + // b.guns[8].ammo += this.ammoLost + simulation.updateGunHUD() + } + } + }, + { + name: "pressure vessel", + description: "build up charge while firing foam
after firing discharge foam bubbles", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("foam") + }, + requires: "foam", + effect() { + tech.isFoamPressure = true; + b.guns[8].chooseFireMethod() + }, + remove() { + tech.isFoamPressure = false; + b.guns[8].chooseFireMethod() + } + }, + { + name: "capacitor bank", + // description: "charge effects build up almost instantly
throwing blocks, foam, railgun, pulse, tokamak", + descriptionFunction() { + return `charge effects build up almost instantly
blocks, ${tech.haveGunCheck("foam", false) ? "foam" : "foam"}, ${tech.isPlasmaBall ? "plasma ball" : "plasma ball"}, ${tech.isRailGun ? "railgun" : "railgun"}, ${tech.isPulseLaser ? "pulse" : "pulse"}, ${tech.isTokamak ? "tokamak" : "tokamak"}` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.blockDamage > 0.075 || tech.isRailGun || (tech.haveGunCheck("foam") && tech.isFoamPressure) || tech.isTokamak || tech.isPulseLaser || tech.isPlasmaBall + }, + requires: "mass driver, railgun, foam, pressure vessel, pulse, tokamak, plasma ball", + effect() { + tech.isCapacitor = true; + }, + remove() { + tech.isCapacitor = false; + } + }, + { + name: "Bitter electromagnet", + descriptionFunction() { + return `0.66x railgun charge rate
2x harpoon density and damage` + }, + isGunTech: true, + maxCount: 3, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("harpoon") && tech.isRailGun + }, + requires: "harpoon, railgun", + effect() { + tech.railChargeRate *= 1.06 + tech.harpoonDensity += 0.007 + }, + remove() { + tech.railChargeRate = 0.97; + tech.harpoonDensity = tech.isRailGun ? 0.007 : 0.004 + } + }, + { + name: "railgun", + description: `hold and release fire to launch harpoons
but, harpoons can't retract`, + // description: `+900% harpoon ammo, but it can't retract
+50% harpoon density and damage`, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("harpoon") && !tech.isFilament && !tech.isHarpoonPowerUp && !tech.isBoostReplaceAmmo + }, + requires: "harpoon, not UHMWPE, induction furnace, quasiparticles", + ammoBonus: 9, + effect() { + tech.isRailGun = true; + tech.harpoonDensity = tech.isRailGun ? 0.007 : 0.004 + b.guns[9].chooseFireMethod() + b.guns[9].ammoPack *= 3; + b.guns[9].ammo = b.guns[9].ammo * 6; + simulation.updateGunHUD(); + }, + remove() { + tech.isRailGun = false; + if (this.count > 0) { + tech.harpoonDensity = tech.isRailGun ? 0.007 : 0.004 + b.guns[9].chooseFireMethod() + b.guns[9].ammoPack /= 3; + b.guns[9].ammo = Math.ceil(b.guns[9].ammo / 6); + simulation.updateGunHUD(); + } + } + }, + { + name: "alternator", + description: "0.05x harpoon energy cost", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("harpoon") + }, + requires: "harpoon", + effect() { + tech.isRailEnergy = true; + }, + remove() { + tech.isRailEnergy = false; + } + }, + { + name: "autonomous defense", + description: "if you collide with a mob
fire harpoons at nearby mobs", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("harpoon") + }, + requires: "harpoon", + effect() { + tech.isHarpoonDefense = true + }, + remove() { + tech.isHarpoonDefense = false + } + }, + { + name: "Bessemer process", + descriptionFunction() { + return `${(1 + 0.1 * Math.sqrt(b.guns[9].ammo)).toFixed(2)}x harpoon size and damage
(effect scales by 1/10 √ harpoon ammo)` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("harpoon") && !tech.isShieldPierce + }, + requires: "harpoon, not ceramics", + effect() { + tech.isLargeHarpoon = true; + }, + remove() { + tech.isLargeHarpoon = false; + } + }, + { + name: "smelting", + descriptionFunction() { + return `forge ${this.removeAmmo()} ammo into a new harpoon
fire +1 harpoon with each shot` + }, + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + ammoRemoved: 0, + removeAmmo() { + return (tech.isRailGun ? 5 : 1) * (2 + 2 * this.count) + }, + allowed() { + return tech.haveGunCheck("harpoon") && b.guns[9].ammo >= this.removeAmmo() + }, + requires: "harpoon", + effect() { + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "harpoon") { + const removeAmmo = this.removeAmmo() + this.ammoRemoved += removeAmmo + b.guns[i].ammo -= removeAmmo + if (b.guns[i].ammo < 0) b.guns[i].ammo = 0 + simulation.updateGunHUD(); + tech.extraHarpoons++; + break + } + } + }, + remove() { + if (tech.extraHarpoons) { + for (i = 0, len = b.guns.length; i < len; i++) { //find which gun + if (b.guns[i].name === "harpoon") { + b.guns[i].ammo += this.ammoRemoved + simulation.updateGunHUD(); + break + } + } + } + this.ammoRemoved = 0 + tech.extraHarpoons = 0; + } + }, + { + name: "UHMWPE", + descriptionFunction() { + return `${(1 + b.guns[9].ammo * 0.0125).toFixed(2)}x harpoon rope length
(effect scales by 1/80 of harpoon ammo)` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("harpoon") && !tech.isRailGun + }, + requires: "harpoon, not railgun", + effect() { + tech.isFilament = true; + }, + remove() { + tech.isFilament = false; + } + }, + { + name: "induction furnace", + description: "after using harpoon/grapple to collect power ups
1.8x harpoon or grapple damage for 8 seconds", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return ((tech.haveGunCheck("harpoon") && !tech.isRailGun) || m.fieldMode === 10) && !tech.isHarpoonFullHealth + }, + requires: "harpoon, grappling hook, not railgun, brittle", + effect() { + tech.isHarpoonPowerUp = true + }, + remove() { + tech.isHarpoonPowerUp = false + tech.harpoonPowerUpCycle = 0 + } + }, + { + name: "brittle", + description: "2.2x harpoon/grapple damage
to mobs at maximum durability", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("harpoon") || m.fieldMode === 10) && !tech.isHarpoonPowerUp + }, + requires: "harpoon, grappling hook, not induction furnace", + effect() { + tech.isHarpoonFullHealth = true + }, + remove() { + tech.isHarpoonFullHealth = false + } + }, + { + name: "quasiparticles", + descriptionFunction() { + return `convert current and future ${powerUps.orb.ammo(1)} into ${powerUps.orb.boost(1)}
that give ${(1 + powerUps.boost.damage).toFixed(2)}x damage for ${(powerUps.boost.duration / 60).toFixed(0)} seconds` + }, + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return ((tech.haveGunCheck("wave") && tech.isInfiniteWaveAmmo) || tech.haveGunCheck("laser") || (tech.haveGunCheck("harpoon") && !tech.isRailGun)) + }, + requires: "harpoon, laser, wave, frequency, not railgun, non-renewables", + effect() { + tech.isBoostReplaceAmmo = true + for (let i = powerUp.length - 1; i > -1; i--) { + if (powerUp[i].name === "ammo") { + powerUps.spawn(powerUp[i].position.x + 50 * (Math.random() - 0.5), powerUp[i].position.y + 50 * (Math.random() - 0.5), "boost"); + Matter.Composite.remove(engine.world, powerUp[i]); + powerUp.splice(i, 1); + } + } + + }, + remove() { + tech.isBoostReplaceAmmo = false + } + }, + { + name: "optical amplifier", + description: `gain 3 random laser ${powerUps.orb.tech()}
laser only turns off if you have no energy`, + // isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isInstant: true, + allowed() { + return tech.haveGunCheck("laser") && !tech.isPulseLaser + }, + requires: "laser gun, not pulse", + effect() { + requestAnimationFrame(() => { + let techGiven = 0 + for (let j = 0; j < 3; j++) { + const names = ["quasiparticles", "lens", "compound lens", "arc length", "infrared diode", "free-electron laser", "dye laser", "relativistic momentum", "specular reflection", "diffraction grating", "diffuse beam", "output coupler", "slow light", "laser-bot", "laser-bot upgrade"] + //convert names into indexes + const options = [] + for (let i = 0; i < names.length; i++) { + for (let k = 0; k < tech.tech.length; k++) { + if (tech.tech[k].name === names[i]) { + options.push(k) + break + } + } + } + //remove options that don't meet requirements + for (let i = options.length - 1; i > -1; i--) { + const index = options[i] + if (!(tech.tech[index].count < tech.tech[index].maxCount) || !tech.tech[index].allowed()) { + options.splice(i, 1); + } + } + //pick one option + if (options.length) { + const index = options[Math.floor(Math.random() * options.length)] + simulation.inGameConsole(`tech.giveTech("${tech.tech[index].name}") //optical amplifier`, 360); + tech.giveTech(index) + techGiven++ + } + } + if (techGiven > 0) { + tech.isStuckOn = true + } else { //eject if none found + simulation.inGameConsole(`0 tech found //optical amplifier`); + const loop = () => { + if (!simulation.paused && m.alive) { + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].name === this.name) powerUps.ejectTech(i) + } + return + } + requestAnimationFrame(loop); + } + requestAnimationFrame(loop); + } + }); + }, + remove() { + tech.isStuckOn = false + } + }, + { + name: "relativistic momentum", + description: "lasers push mobs and blocks", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("laser") && !tech.isPulseLaser) || tech.isLaserBotUpgrade || tech.isLaserField + }, + requires: "laser, not pulse", + effect() { + tech.isLaserPush = true; + }, + remove() { + tech.isLaserPush = false; + } + }, + { + name: "iridescence", + description: "if laser beams hit mobs near their center
2x laser damage", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.haveGunCheck("laser") && !tech.isPulseLaser) || tech.isLaserBotUpgrade || tech.isLaserMine + }, + requires: "laser, not pulse", + effect() { + tech.laserCrit += 1; + }, + remove() { + tech.laserCrit = 0; + } + }, + { + name: "lens", + description: "2.5x laser damage if it passes
through a revolving 90° arc circular lens", //π / 2
+ isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("laser") + }, + requires: "laser", + effect() { + tech.isLaserLens = true + b.guns[11].chooseFireMethod() + // if (this.count > 0) b.guns[11].lensDamageOn += 20 * Math.PI / 180 + // b.guns[11].arcRange = 0.78 + }, + remove() { + tech.isLaserLens = false + b.guns[11].chooseFireMethod() + // b.guns[11].lensDamageOn = 2.5 // 100% + 150% + // b.guns[11].arcRange = 0 + } + }, + { + name: "compound lens", + description: "1.4x laser lens damage
+30° lens arc", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("laser") && tech.isLaserLens + }, + requires: "lens", + effect() { + b.guns[11].arcRange += 30 * Math.PI / 180 / 2 + b.guns[11].lensDamageOn += 0.4 + }, + remove() { + b.guns[11].arcRange = 90 * Math.PI / 180 / 2 //0.78 divded by 2 because of how it's drawn + b.guns[11].lensDamageOn = 2.5 + } + }, + { + name: "specular reflection", + description: "+2 laser beam reflections", + isGunTech: true, + maxCount: 3, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.haveGunCheck("laser") || tech.isLaserMine || tech.isLaserBotUpgrade || tech.isLaserField) && !tech.isWideLaser && !tech.isPulseLaser && !tech.historyLaser + }, + requires: "laser, not diffuse beam, pulse, or slow light", + effect() { + tech.laserReflections += 2; + }, + remove() { + tech.laserReflections = 2; + } + }, + { + name: "diffraction grating", + description: `+1 diverging laser beam`, + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.haveGunCheck("laser") && !tech.isWideLaser && !tech.historyLaser + }, + requires: "laser gun, diffuse beam, or slow light", + effect() { + tech.beamSplitter++ + b.guns[11].chooseFireMethod() + }, + remove() { + if (tech.beamSplitter !== 0) { + tech.beamSplitter = 0 + b.guns[11].chooseFireMethod() + } + } + }, + { + name: "diffuse beam", + link: `diffuse beam`, + description: "your laser beam is wider, but it doesn't reflect
3.2x laser damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("laser") && tech.laserReflections < 3 && !tech.beamSplitter && !tech.isPulseLaser && !tech.historyLaser + }, + requires: "laser gun, not specular reflection, diffraction grating, slow light, pulse", + effect() { + if (tech.wideLaser === 0) tech.wideLaser = 3 + tech.isWideLaser = true; + b.guns[11].chooseFireMethod() + }, + remove() { + if (tech.isWideLaser) { + // tech.wideLaser = 0 + tech.isWideLaser = false; + b.guns[11].chooseFireMethod() + } + } + }, + { + name: "output coupler", + description: "1.3x laser beam width
1.3x laser damage", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("laser") && tech.isWideLaser + }, + requires: "laser gun, diffuse beam", + effect() { + tech.wideLaser += 2 + b.guns[11].chooseFireMethod() + }, + remove() { + if (tech.isWideLaser) { + tech.wideLaser = 3 + } else { + tech.wideLaser = 0 + } + b.guns[11].chooseFireMethod() + } + }, + { + name: "delayed-choice", + description: "your laser fires a 0.4 second delayed beam
that does 0.7x damage", + isGunTech: true, + maxCount: 9, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return tech.haveGunCheck("laser") && !tech.beamSplitter && !tech.isWideLaser + }, + requires: "laser gun, diffraction grating, diffuse beam", + effect() { + tech.historyLaser++ + b.guns[11].chooseFireMethod() + }, + remove() { + if (tech.historyLaser) { + tech.historyLaser = 0 + b.guns[11].chooseFireMethod() + } + } + }, + { + name: "infrared diode", + description: "0.4x laser energy cost
infrared light is outside visual perception", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.haveGunCheck("laser") || tech.isLaserBotUpgrade || tech.isLaserMine || tech.isLaserField) && !tech.isPulseLaser && tech.laserDrain === 0.003 + }, + requires: "laser, not free-electron, pulse", + effect() { + tech.laserDrain *= 0.4; //100%-50% + tech.laserColor = "transparent" //"rgb(255,0,20,0.02)" + // tech.laserColorAlpha = "rgba(255,0,20,0.05)" + }, + remove() { + tech.laserDrain = 0.003; + tech.laserColor = "#f02" + tech.laserColorAlpha = "rgba(255, 0, 0, 0.5)" + } + }, + { + name: "dye laser", + description: "0.75x laser energy cost
1.25x laser damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.haveGunCheck("laser") || tech.isLaserMine || tech.isLaserBotUpgrade || tech.isLaserField) && !tech.isPulseLaser && tech.laserDrain === 0.003 + }, + requires: "laser, not pulse, infrared diode", + effect() { + tech.laserDrain *= 0.75 + tech.laserDamage *= 1.25 + tech.laserColor = "rgb(0, 11, 255)" + tech.laserColorAlpha = "rgba(0, 11, 255,0.5)" + }, + remove() { + tech.laserDrain = 0.003; + tech.laserDamage = 0.18; //used in check on pulse and diode: tech.laserDamage === 0.18 + tech.laserColor = "#f00" + tech.laserColorAlpha = "rgba(255, 0, 0, 0.5)" + } + }, + { + name: "free-electron laser", + description: "3x laser energy cost
3x laser damage", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (tech.haveGunCheck("laser") || tech.isLaserMine || tech.isLaserBotUpgrade || tech.isLaserField) && !tech.isPulseLaser && tech.laserDrain === 0.003 + }, + requires: "laser, not pulse, infrared diode", + effect() { + tech.laserDrain *= 3 + tech.laserDamage *= 3 + tech.laserColor = "#83f" + tech.laserColorAlpha = "rgba(136, 51, 255,0.5)" + }, + remove() { + tech.laserDrain = 0.003; + tech.laserDamage = 0.18; //used in check on pulse and diode: tech.laserDamage === 0.18 + tech.laserColor = "#f00" + tech.laserColorAlpha = "rgba(255, 0, 0, 0.5)" + } + }, + { + name: "pulse", + description: "charge your energy and release it as a
laser pulse that initiates an explosion cluster", + isGunTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.haveGunCheck("laser") && tech.laserReflections < 3 && !tech.isWideLaser && tech.laserDrain === 0.003 && !tech.isStuckOn + }, + requires: "laser gun, not specular reflection, diffuse, free-electron laser, optical amplifier", + effect() { + tech.isPulseLaser = true; + b.guns[11].chooseFireMethod() + }, + remove() { + if (tech.isPulseLaser) { + tech.isPulseLaser = false; + b.guns[11].chooseFireMethod() + } + } + }, + //************************************************** + //************************************************** field + //************************************************** tech + //************************************************** + { + name: "spherical harmonics", + description: "1.5x standing wave deflection energy efficiency
shield deflection radius is stable", //standing wave oscillates in a 3rd dimension
+ isFieldTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 1 && !tech.isLaserField + }, + requires: "standing wave, not surface plasmons", + effect() { + tech.harmonics++ + m.fieldShieldingScale = 1.6 * Math.pow(0.5, (tech.harmonics - 2)) + m.harmonicShield = m.harmonicAtomic + }, + remove() { + tech.harmonics = 2 + m.fieldShieldingScale = 1.6 * Math.pow(0.5, (tech.harmonics - 2)) + m.harmonicShield = m.harmonic3Phase + } + }, + { + name: "surface plasmons", + description: "if deflecting drains all your energy
emit laser beams that scale with max energy", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 1 && tech.harmonics === 2 + }, + requires: "standing wave", + effect() { + tech.isLaserField = true + }, + remove() { + tech.isLaserField = false + } + }, + { + name: "zero point energy", + description: `use ${powerUps.orb.research(2)}
+166 maximum energy`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (m.fieldMode === 1 || m.fieldMode === 8 || m.fieldMode === 6) && (build.isExperimentSelection || powerUps.research.count > 1) + }, + requires: "standing wave, pilot wave, time dilation", + effect() { + tech.harmonicEnergy = 1.66 + m.setMaxEnergy() + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.harmonicEnergy = 0; + m.setMaxEnergy() + if (this.count > 0) powerUps.research.changeRerolls(2) + } + }, + { + name: "expansion", + description: "using standing wave expands its radius
+77 maximum energy", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 1 + }, + requires: "standing wave", + effect() { + tech.isStandingWaveExpand = true + m.setMaxEnergy() + // m.fieldShieldingScale = (tech.isStandingWaveExpand ? 0.9 : 1.6) * Math.pow(0.6, (tech.harmonics - 2)) + }, + remove() { + tech.isStandingWaveExpand = false + m.setMaxEnergy() + // m.fieldShieldingScale = (tech.isStandingWaveExpand ? 0.9 : 1.6) * Math.pow(0.6, (tech.harmonics - 2)) + m.harmonicRadius = 1 + } + }, + { + + // descriptionFunction() { + // return `use ${powerUps.orb.research(2)}
1.01x damage per energy below maximum (${(1 + Math.max(0, m.maxEnergy - m.energy)).toFixed(2)}x)` + // }, + name: "electronegativity", + descriptionFunction() { + return `1.0023x damage per energy
(${(1 + 0.23 * m.energy).toFixed(2)}x, ${(1 + 0.23 * m.maxEnergy).toFixed(2)}x at max energy)` + }, + // description: "+1% damage per 8 stored energy", + isFieldTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 1 || m.fieldMode === 9 || m.fieldMode === 8 + }, + requires: "standing wave, wormhole, pilot wave", + effect() { + tech.energyDamage++ + }, + remove() { + tech.energyDamage = 0; + } + }, + { + name: "bremsstrahlung", + description: "deflecting and thrown blocks
do braking damage to mobs", + isFieldTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 1 || m.fieldMode === 2 || m.fieldMode === 8 + }, + requires: "standing wave, perfect diamagnetism, pilot wave", + effect() { + tech.blockDmg += 5 //if you change this value also update the for loop in the electricity graphics in m.pushMass + }, + remove() { + tech.blockDmg = 0; + } + }, + { + name: "cherenkov radiation", //deflecting and blocks + description: "bremsstrahlung's effects are radioactive
3.5x damage over 3 seconds", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.fieldMode === 1 || m.fieldMode === 2 || m.fieldMode === 8) && tech.blockDmg + }, + requires: "bremsstrahlung", + effect() { + tech.isBlockRadiation = true + }, + remove() { + tech.isBlockRadiation = false; + } + }, + { + name: "flux pinning", + description: `mobs deflected by your ${powerUps.orb.field()}
are stunned for 4 seconds`, + isFieldTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 2 || m.fieldMode === 1 || m.fieldMode === 4 + }, + requires: "a field that can block", + effect() { + tech.isStunField += 240; + }, + remove() { + tech.isStunField = 0; + } + }, + { + name: "eddy current brake", + description: "perfect diamagnetism slows nearby mobs
effect radius scales with stored energy", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 2 && !tech.isHealBrake + }, + requires: "perfect diamagnetism, not induction brake", + effect() { + tech.isPerfectBrake = true; + }, + remove() { + tech.isPerfectBrake = false; + } + }, + { + name: "Meissner effect", + description: "1.55x perfect diamagnetism radius
+22° perfect diamagnetism circular arc", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 2 + }, + requires: "perfect diamagnetism", + effect() { + tech.isBigField = true; + }, + remove() { + tech.isBigField = false; + } + }, + { + name: "radiative equilibrium", + descriptionFunction() { + return `after losing ${tech.isEnergyHealth ? "energy" : "health"}
3x damage for 8 seconds` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 8 || m.fieldMode === 3 + }, + requires: "negative mass, pilot wave", + effect() { + tech.isHarmDamage = true; + }, + remove() { + tech.isHarmDamage = false; + } + }, + { + name: "dynamic equilibrium", + descriptionFunction() { + return `increase damage by your most recent ${tech.isEnergyHealth ? "energy" : "health"} loss
(${(1 + (tech.lastHitDamage === 0 ? 6 : tech.lastHitDamage) * m.lastHit).toFixed(2)}x)` + }, + isFieldTech: true, + maxCount: 3, + count: 0, + frequency: 2, + frequencyDefault: 200, + allowed() { + return m.fieldMode === 8 || m.fieldMode === 3 + }, + requires: "negative mass, pilot wave", + effect() { + tech.lastHitDamage += 6; + }, + remove() { + tech.lastHitDamage = 0; + } + }, + { + name: "neutronium", + description: `0.8x move and jump, but
while your ${powerUps.orb.field()} is active 0.05x damage taken`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 3 + }, + requires: "negative mass", + effect() { + tech.isNeutronium = true + tech.baseFx *= 0.86 + tech.baseJumpForce *= 0.87 + m.setMovement() + }, + //also removed in m.setHoldDefaults() if player switches into a bad field + remove() { + tech.isNeutronium = false + if (!tech.isFreeWormHole) { + tech.baseFx = 0.08 + tech.baseJumpForce = 10.5 + m.setMovement() + } + } + }, + { + name: "aerostat", + descriptionFunction() { + return `2x damage while off the ground
0.9x damage while on the ground(${(m.onGround ? 0.9 : 2).toFixed(1)}x)` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 3 || m.fieldMode === 10 + }, + requires: "negative mass, grappling hook", + effect() { + tech.isNoGroundDamage = true + }, + remove() { + tech.isNoGroundDamage = false + } + }, + { + name: "annihilation", + description: "after colliding with non-boss mobs
they are annihilated and –10 energy", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 3 && !tech.isEnergyHealth + }, + requires: "negative mass, not mass-energy", + effect() { + tech.isAnnihilation = true + }, + remove() { + tech.isAnnihilation = false; + } + }, + { + name: "inertial mass", + description: "negative mass is larger and faster", //
blocks also move horizontally with the field + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 3 + }, + requires: "negative mass", + effect() { + tech.isFlyFaster = true + }, + remove() { + tech.isFlyFaster = false; + } + }, { + name: "Newtons 1st law", + descriptionFunction() { + return `damage taken reduces as your speed increases
up to 0.05x damage taken at 60 speed (${(1 - Math.min((tech.speedAdded + player.speed) * 0.01583, 0.95)).toFixed(2)}x)` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.fieldMode === 3 || m.fieldMode === 10 + }, + requires: "negative mass, grappling hook", + effect() { + tech.isSpeedHarm = true //max at speed = 40 + }, + remove() { + tech.isSpeedHarm = false + } + }, + { + name: "Newtons 2nd law", + descriptionFunction() { + return `damage increases proportional to your speed
up to 3x damage at 60 speed (${(1 + Math.min(2, ((tech.speedAdded + player.speed) * 0.033))).toFixed(2)}x)` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.fieldMode === 3 || m.fieldMode === 10 + }, + requires: "negative mass, grappling hook", + effect() { + tech.isSpeedDamage = true //max at speed = 40 + }, + remove() { + tech.isSpeedDamage = false + } + }, + { + name: "MOND", + descriptionFunction() { + return `your speed counts as +20 higher
(for Newton's 1st and 2nd laws)` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return tech.isSpeedDamage || tech.isSpeedHarm + }, + requires: "Newtons 1st or 2nd law", + effect() { + tech.speedAdded = 20 + }, + remove() { + tech.speedAdded = 0 + } + }, + { + name: "additive manufacturing", + description: `hold crouch and use ${powerUps.orb.field()} to print a block
with 1.8x density, damage, and launch speed`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.fieldMode === 4 || m.fieldMode === 8) && !tech.isTokamak + }, + requires: "molecular assembler, pilot wave, not tokamak", + effect() { + tech.isPrinter = true; + }, + remove() { + if (this.count > 0) m.holdingTarget = null; + tech.isPrinter = false; + } + }, + { + name: "working mass", + // description: "molecular assembler prints one block
to jump off while midair", + descriptionFunction() { + const fieldName = m.fieldMode === 8 ? "pilot wave" : "molecular assembler" + return `pressing jump in midair
will print a block to jump off` + // return `${fieldName} prints a block
to jump off while midair` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.fieldMode === 4 || m.fieldMode === 8) + }, + requires: "molecular assembler, pilot wave", + effect() { + simulation.ephemera.push({ + name: "blockJump", + blockJumpPhase: 0, + do() { + if (m.onGround && m.buttonCD_jump + 10 < m.cycle && !(m.lastOnGroundCycle + m.coyoteCycles > m.cycle)) this.blockJumpPhase = 0 //reset after touching ground or block + if (this.blockJumpPhase === 0 && !m.onGround && !input.up && m.buttonCD_jump + 10 < m.cycle) { //not pressing jump + this.blockJumpPhase = 1 + } else if (this.blockJumpPhase === 1 && input.up && m.buttonCD_jump + 10 < m.cycle) { //2nd jump + this.blockJumpPhase = 2 + let horizontalVelocity = 8 * (- input.left + input.right) //ive player and block horizontal momentum + + const radius = 25 + Math.floor(15 * Math.random()) + body[body.length] = Matter.Bodies.polygon(m.pos.x, m.pos.y + 60 + radius, 4, radius, { + friction: 0.05, + frictionAir: 0.001, + collisionFilter: { + category: cat.body, + mask: cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + }, + classType: "body", + }); + const block = body[body.length - 1] + //mess with the block shape (this code is horrible) + Composite.add(engine.world, block); //add to world + const r1 = radius * (1 + 0.4 * Math.random()) + const r2 = radius * (1 + 0.4 * Math.random()) + let angle = Math.PI / 4 + const vertices = [] + for (let i = 0, len = block.vertices.length; i < len; i++) { + angle += 2 * Math.PI / len + vertices.push({ x: block.position.x + r1 * Math.cos(angle), y: block.position.y + r2 * Math.sin(angle) }) + } + Matter.Body.setVertices(block, vertices) + // Matter.Body.setAngle(block, Math.PI / 4) + Matter.Body.setVelocity(block, { x: 0.9 * player.velocity.x - horizontalVelocity, y: 10 }); + Matter.Body.applyForce(block, m.pos, { x: 0, y: m.jumpForce * 0.12 * Math.min(m.standingOn.mass, 5) }); + if (tech.isBlockRestitution) { + block.restitution = 0.999 //extra bouncy + block.friction = block.frictionStatic = block.frictionAir = 0.001 + } + if (tech.isAddBlockMass) { + const expand = function (that, massLimit) { + if (that.mass < massLimit) { + const scale = 1.04; + Matter.Body.scale(that, scale, scale); + setTimeout(expand, 20, that, massLimit); + } + }; + expand(block, Math.min(20, block.mass * 3)) + } + //jump + m.buttonCD_jump = m.cycle; //can't jump again until 20 cycles pass + Matter.Body.setVelocity(player, { x: player.velocity.x + horizontalVelocity, y: -7.5 + 0.25 * player.velocity.y }); + player.force.y = -m.jumpForce; //player jump force + } + }, + }) + }, + remove() { + if (this.count) simulation.removeEphemera("blockJump") + } + }, + { + name: "pair production", + description: "after picking up a power up
+200 energy", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 4 || m.fieldMode === 1 || m.fieldMode === 8 + }, + requires: "molecular assembler, pilot wave, standing wave", + effect() { + tech.isMassEnergy = true // used in m.grabPowerUp + m.energy += 2 * level.isReducedRegen + }, + remove() { + tech.isMassEnergy = false; + } + }, + { + name: "electric generator", + description: "after deflecting mobs
molecular assembler generates +50 energy", + isFieldTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 4 + }, + requires: "molecular assembler", + effect() { + tech.deflectEnergy += 0.5; + }, + remove() { + tech.deflectEnergy = 0; + } + }, + { + name: "combinatorial optimization", + description: "1.4x damage
0.7x fire rate", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 6 || m.fieldMode === 7 || m.fieldMode === 8 + }, + requires: "time dilation, cloaking, pilot wave", + damage: 1.4, + effect() { + tech.damage *= this.damage + tech.aimDamage = 1.42 + b.setFireCD(); + }, + remove() { + if (this.count && m.alive) tech.damage /= this.damage + tech.aimDamage = 1 + b.setFireCD(); + } + }, + { + name: "tokamak", + description: "tokamak converts thrown blocks into energy
and a pulsed fusion explosion", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.fieldMode === 5 || m.fieldMode === 4 || m.fieldMode === 10) && !tech.isPrinter && !tech.isReel && !tech.hookNails + }, + requires: "plasma torch, molecular assembler, grappling hook, not printer, reel, swarf", + effect() { + tech.isTokamak = true; + }, + remove() { + tech.isTokamak = false; + } + }, + { + name: "stellarator", + descriptionFunction() { + return `the first 5 blocks detonated by tokamak
spawn ${powerUps.orb.heal(1)} proportional to block size` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return tech.isTokamak && (m.fieldMode === 5 || m.fieldMode === 4 || m.fieldMode === 10) + }, + requires: "tokamak", + effect() { + tech.isTokamakHeal = true; + tech.tokamakHealCount = 0 + }, + remove() { + tech.isTokamakHeal = false; + } + }, + { + name: "inertial confinement", + description: "while holding a block charged with tokamak
you can use energy to fly", //and invulnerable? + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return tech.isTokamak && (m.fieldMode === 5 || m.fieldMode === 4 || m.fieldMode === 10) + }, + requires: "tokamak", + effect() { + tech.isTokamakFly = true; + }, + remove() { + tech.isTokamakFly = false; + } + }, + { + name: "degenerate matter", + description: `if your ${powerUps.orb.field()} is active
0.1x damage taken`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.fieldMode === 10 || m.fieldMode === 5 || m.fieldMode === 8) + }, + requires: "plasma torch, grappling hook, pilot wave", + effect() { + tech.isHarmReduce = true + }, + remove() { + tech.isHarmReduce = false; + } + }, + { + name: "plasma-bot", + link: `plasma-bot`, + description: `use ${powerUps.orb.research(2)}to trade your ${powerUps.orb.field()}
for a bot that uses energy to emit plasma`, + // isFieldTech: true, + isInstant: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + isBot: true, + isBotTech: true, + allowed() { + return m.fieldMode === 5 && !tech.isPlasmaBall && !tech.isExtruder && (build.isExperimentSelection || powerUps.research.count > 1) + }, + requires: "plasma torch, not extruder, plasma ball", + effect() { + tech.plasmaBotCount++; + b.plasmaBot(); + if (build.isExperimentSelection) { + document.getElementById("field-" + m.fieldMode).classList.remove("build-field-selected"); + document.getElementById("field-0").classList.add("build-field-selected"); + } + m.setField("field emitter") + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + if (this.count > 0) { + tech.plasmaBotCount = 0; + b.clearPermanentBots(); + b.respawnBots(); + if (m.fieldMode === 0) { + m.setField("plasma torch") + if (build.isExperimentSelection) { + document.getElementById("field-0").classList.remove("build-field-selected"); + document.getElementById("field-" + m.fieldMode).classList.add("build-field-selected"); + } + } + powerUps.research.changeRerolls(2) + } + } + }, + { + name: "plasma jet", + link: `plasma jet`, + description: `use ${powerUps.orb.research(1)}
1.5x plasma torch range`, + isFieldTech: true, + maxCount: 3, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (tech.plasmaBotCount || m.fieldMode === 5) && (build.isExperimentSelection || powerUps.research.count > 0) && !tech.isPlasmaBall + }, + requires: "plasma torch, not plasma ball", + effect() { + tech.isPlasmaRange += 0.5; + for (let i = 0; i < 1; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.isPlasmaRange = 1; + if (this.count > 0) powerUps.research.changeRerolls(this.count) + } + }, + { + name: "extruder", + description: "extrude a thin hot wire of plasma
increases damage and energy cost", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 5 && !tech.isPlasmaBall + }, + requires: "plasma torch, not plasma ball", + effect() { + tech.isExtruder = true; + m.fieldUpgrades[m.fieldMode].set() + }, + remove() { + tech.isExtruder = false; + if (this.count && m.fieldMode === 5) m.fieldUpgrades[m.fieldMode].set() + } + }, + { + name: "refractory metal", + description: "extrude metals at a higher temperature
increases effective radius and damage", + isFieldTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 5 && tech.isExtruder + }, + requires: "extruder", + effect() { + tech.extruderRange += 55 + }, + remove() { + tech.extruderRange = 15 + } + }, + { + name: "plasma ball", + description: "grow an expanding ball of plasma
increases damage and energy cost", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 5 && !tech.isExtruder && tech.isPlasmaRange === 1 + }, + requires: "plasma torch, not extruder, plasma jet", + effect() { + tech.isPlasmaBall = true; + m.fieldUpgrades[m.fieldMode].set() + }, + remove() { + tech.isPlasmaBall = false; + if (this.count && m.fieldMode === 5) m.fieldUpgrades[m.fieldMode].set() + } + }, + { + name: "corona discharge", + description: "increase the range and frequency
of plasma ball's electric arc ", + isFieldTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 5 && tech.isPlasmaBall + }, + requires: "plasma ball", + effect() { + tech.plasmaDischarge += 0.03 + }, + remove() { + tech.plasmaDischarge = 0.01 //default chance per cycle of a discharge + } + }, + { + name: "retrocausality", + description: "time dilation uses energy to rewind your
health, velocity, and position up to 10 seconds", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.fieldMode === 6 && !m.isShipMode && !tech.isRewindAvoidDeath && !tech.isTimeSkip + }, + requires: "time dilation, not CPT symmetry", + effect() { + tech.isRewindField = true; + m.fieldUpgrades[6].set() + m.wakeCheck(); + }, + remove() { + tech.isRewindField = false; + if (this.count) m.fieldUpgrades[6].set() + } + }, + { + name: "frame-dragging", //"non-inertial frame", + description: "when not moving time dilation stops time
0.6x damage taken", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.fieldMode === 6 + }, + requires: "time dilation", + effect() { + tech.isTimeStop = true; + m.fieldHarmReduction = 0.66; //33% reduction + }, + remove() { + tech.isTimeStop = false; + if (m.fieldMode === 6) m.fieldHarmReduction = 1; + } + }, + { + name: "Lorentz transformation", + description: `use ${powerUps.orb.research(3)}
1.5x movement, jumping, and fire rate`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (m.fieldMode === 6 || m.fieldMode === 8) && (build.isExperimentSelection || powerUps.research.count > 2) + }, + requires: "time dilation or pilot wave", + effect() { + tech.isFastTime = true + m.setMovement(); + b.setFireCD(); + for (let i = 0; i < 3; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.isFastTime = false + m.setMovement(); + b.setFireCD(); + if (this.count > 0) powerUps.research.changeRerolls(3) + } + }, + { + name: "time crystals", + descriptionFunction() { + return `2.5x passive energy generation
(+${(150 * m.fieldRegen * 60).toFixed(1)} energy per second)` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return !tech.isGroundState && (m.fieldMode === 6 || m.fieldMode === 8) + }, + requires: "time dilation or pilot wave, not ground state", + effect() { + tech.isTimeCrystals = true + m.setFieldRegen() + this.descriptionFunction = function () { + return `2.5x passive energy generation
(+${(60 * m.fieldRegen * 60).toFixed(1)} energy per second)` + } + }, + remove() { + tech.isTimeCrystals = false + m.setFieldRegen() + this.descriptionFunction = function () { + return `2.5x passive energy generation
(+${(150 * m.fieldRegen * 60).toFixed(1)} energy per second)` + } + } + }, + { + name: "no-cloning theorem", + description: `+40% chance to duplicate spawned power ups
after a mob dies –1% duplication`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.fieldMode === 6 || m.fieldMode === 7) + }, + requires: "cloaking, time dilation", + effect() { + tech.cloakDuplication = 0.4 + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.4); + }, + remove() { + tech.cloakDuplication = 0 + if (this.count) powerUps.setPowerUpMode(); //needed after adjusting duplication chance + } + }, + { + name: "metamaterial absorber", //quantum eraser + descriptionFunction() { + return `for each mob left alive after you exit a level
there is a 30% chance to spawn a random power up` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return (m.fieldMode === 7) && !tech.cloakDuplication + }, + requires: "cloaking", + effect() { + tech.isQuantumEraser = true + }, + remove() { + tech.isQuantumEraser = false + } + }, + { + name: "symbiosis", + descriptionFunction() { + return `after a boss dies spawn ${powerUps.orb.research(4)}${powerUps.orb.heal(3)}${powerUps.orb.tech()}
after a mob dies –0.25 maximum ${tech.isEnergyHealth ? "energy" : "health"}` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 7 //|| m.fieldMode === 6 + }, + requires: "cloaking", + effect() { + tech.isAddRemoveMaxHealth = true + }, + remove() { + tech.isAddRemoveMaxHealth = false + } + }, + { + name: "boson composite", + link: `boson composite`, + description: "while cloaked you are intangible
to blocks and mobs, but mobs drain energy", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 7 + }, + requires: "metamaterial cloaking", + effect() { + tech.isIntangible = true; + }, + remove() { + if (tech.isIntangible) { + tech.isIntangible = false; + player.collisionFilter.mask = cat.body | cat.map | cat.mob | cat.mobBullet | cat.mobShield //normal collisions + } + } + }, + { + name: "patch", + link: `patch`, + description: "after cloaking recover 0.75x
of your last health lost", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 7 && !tech.isEnergyHealth + }, + requires: "metamaterial cloaking, not mass-energy", + effect() { + tech.isCloakHealLastHit = true; + }, + remove() { + tech.isCloakHealLastHit = false; + } + }, + { + name: "dazzler", + link: `dazzler`, + description: "after decloaking
stun nearby mobs for 2 seconds", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 7 + }, + requires: "metamaterial cloaking", + effect() { + tech.isCloakStun = true; + }, + remove() { + tech.isCloakStun = false; + } + }, + { + name: "topological defect", + description: "2.1x damage
to mobs at maximum durability", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return (m.fieldMode === 8 || m.fieldMode === 7) && tech.mobSpawnWithHealth === 0 + }, + requires: "cloaking, pilot wave, not reaction inhibitor", + effect() { + tech.isMobFullHealthCloak = true + }, + remove() { + tech.isMobFullHealthCloak = false + } + }, + { + name: "hidden-variable theory", + description: `1.15x damage each time you choose ${powerUps.orb.fieldTech()}`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.fieldMode === 8 + }, + requires: "pilot wave", + effect() { + tech.isDamageFieldTech = true + }, + remove() { + tech.isDamageFieldTech = false + } + }, + { + name: "WIMPs", + description: `at each level's exit, spawn ${powerUps.orb.research(4)}
and a dangerous particle that slowly chases you`, + isFieldTech: true, + maxCount: 9, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 9 || m.fieldMode === 8 + }, + requires: "wormhole, pilot wave", + effect() { + tech.wimpCount++ + spawn.WIMP() + for (let j = 0, len = 4; j < len; j++) powerUps.spawn(level.exit.x + 100 * (Math.random() - 0.5), level.exit.y - 100 + 100 * (Math.random() - 0.5), "research", false) + }, + remove() { + tech.wimpCount = 0 + } + }, + { + name: "vacuum fluctuation", + description: `use ${powerUps.orb.research(2)}
+11% chance to duplicate spawned power ups`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 3, + frequencyDefault: 3, + allowed() { + return (m.fieldMode === 8 || m.fieldMode === 6 || m.fieldMode === 9) && (build.isExperimentSelection || powerUps.research.count > 2) + }, + requires: "wormhole, time dilation, negative mass, pilot wave", + effect() { + tech.fieldDuplicate = 0.11 + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.11); + for (let i = 0; i < 2; i++) { + if (powerUps.research.count > 0) powerUps.research.changeRerolls(-1) + } + }, + remove() { + tech.fieldDuplicate = 0 + if (this.count) { + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + powerUps.research.changeRerolls(2) + } + } + }, + { + name: "transdimensional worms", + link: `transdimensional worms`, + description: "after a block falls into a wormhole
spawn a worm", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 9 + }, + requires: "wormhole", + effect() { + tech.isWormholeWorms = true + }, + remove() { + tech.isWormholeWorms = false + } + }, + { + name: "anyon", + descriptionFunction() { + return `2x energy after duplicating a power up
+6% chance to duplicate spawned power ups` + }, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.fieldMode === 9 || m.fieldMode === 1 + }, + requires: "wormhole, standing wave", + effect() { + tech.isDupEnergy = true; + powerUps.setPowerUpMode(); //needed after adjusting duplication chance + if (!build.isExperimentSelection && !simulation.isTextLogOpen) simulation.circleFlare(0.06); + }, + remove() { + tech.isDupEnergy = false; + if (this.count) powerUps.setPowerUpMode(); //needed after adjusting duplication chance } + } + }, + { + name: "geodesics", + description: `your bullets can traverse wormholes
1.5x damage`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 9 + }, + requires: "wormhole", + damage: 1.5, + effect() { + tech.damage *= this.damage + tech.isWormHoleBullets = true + // for (let i = 0; i < 2; i++) powerUps.spawn(m.pos.x + 200 * (Math.random() - 0.5), m.pos.y + 200 * (Math.random() - 0.5), "gun"); + // for (let i = 0; i < 4; i++) powerUps.spawn(m.pos.x + 200 * (Math.random() - 0.5), m.pos.y + 200 * (Math.random() - 0.5), "ammo"); + }, + remove() { + // if (tech.isWormHoleBullets) { + // for (let i = 0; i < 2; i++) { + // if (b.inventory.length) b.removeGun(b.guns[b.inventory[b.inventory.length - 1]].name) //remove your last gun + // } + // } + if (this.count && m.alive) tech.damage /= this.damage + tech.isWormHoleBullets = false; + } + }, + { + name: "cosmic string", + description: "after tunneling through mobs with a wormhole
stun them and do radioactive damage", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 9 + }, + requires: "wormhole", + effect() { + tech.isWormholeDamage = true + }, + remove() { + tech.isWormholeDamage = false + } + }, + { + name: "invariant", + description: "while placing your wormhole
use energy to pause time", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 9 && !tech.isNoDraftPause + }, + requires: "wormhole, not eternalism", + effect() { + tech.isWormHolePause = true + }, + remove() { + if (tech.isWormHolePause && m.isTimeDilated) m.wakeCheck(); + tech.isWormHolePause = false + } + }, + { + name: "holographic principle", + description: `0.8x movement and jumping
wormholes cost zero energy`, + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 9 && !tech.isWormholeMapIgnore + }, + requires: "wormhole, not affine connection", + effect() { + tech.isFreeWormHole = true + tech.baseFx *= 0.8 + tech.baseJumpForce *= 0.8 + m.setMovement() + }, + //also removed in m.setHoldDefaults() if player switches into a bad field + remove() { + tech.isFreeWormHole = false + if (!tech.isNeutronium) { + tech.baseFx = 0.08 + tech.baseJumpForce = 10.5 + m.setMovement() + } + } + }, + { + name: "affine connection", + description: "wormholes can tunnel through anything
for 2x energy cost", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 9 && !tech.isFreeWormHole + }, + requires: "wormhole, not charmed baryons", + effect() { + tech.isWormholeMapIgnore = true + }, + remove() { + tech.isWormholeMapIgnore = false + } + }, + { + name: "CIWS", + description: "grappling hook uses 10 energy
to fire harpoons at nearby mobs", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 10 + }, + requires: "grappling hook", + effect() { + tech.isHookDefense = true + }, + remove() { + tech.isHookDefense = false + } + }, + { + name: "swarf", + // description: "after grappling hook impacts solid objects generate an explosion and become briefly invulnerable", + description: "after grappling hook impacts something
eject nails splinters towards nearby mobs", + isFieldTech: true, + maxCount: 3, + count: 0, + frequency: 2, + frequencyDefault: 2, + allowed() { + return m.fieldMode === 10 && !tech.isReel && !tech.isTokamak + }, + requires: "grappling hook, not reel, tokamak", + effect() { + tech.hookNails += 4 + }, + remove() { + tech.hookNails = 0 + } + }, + { + name: "reel", + description: "5x block collision damage
up to +100 energy after reeling in blocks", + isFieldTech: true, + maxCount: 1, + count: 0, + frequency: 1, + frequencyDefault: 1, + allowed() { + return m.fieldMode === 10 && !tech.isTokamak && tech.blockDamage === 0.075 && !tech.hookNails + }, + requires: "grappling hook, not mass driver, swarf, tokamak", + effect() { + tech.blockDamage = 0.375 + tech.isReel = true + }, + remove() { + tech.blockDamage = 0.075 + tech.isReel = false + } + }, + // { + // name: "CIWS", + // description: "if you collide with a mob
fire harpoons at nearby mobs", + // isFieldTech: true, + // maxCount: 1, + // count: 0, + // frequency: 2, + // frequencyDefault: 2, + // allowed() { + // return m.fieldMode === 10 && !tech.isHookDefense + // }, + // requires: "grappling hook, not automatic offense", + // effect() { + // tech.isHookDefense = true + // }, + // remove() { + // tech.isHookDefense = false + // } + // }, + // { + // name: "wire", + // description: "", + // isFieldTech: true, + // maxCount: 1, + // count: 0, + // frequency: 2, + // frequencyDefault: 2, + // allowed() { + // return m.fieldMode === 10 + // }, + // requires: "grappling hook", + // effect() { + // tech.isHookWire = true + // }, + // remove() { + // tech.isHookWire = false + // } + // }, + //************************************************** + //************************************************** experimental + //************************************************** modes + //************************************************** + // { + // name: "-ship-", + // description: "experiment: fly around with no legs
aim with the keyboard", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isInstant: true, + // isBadRandomOption: true, + // isExperimentalMode: true, + // allowed() { + // return build.isExperimentSelection && !m.isShipMode && m.fieldUpgrades[m.fieldMode].name !== "negative mass" + // }, + // requires: "", + // effect() { + // m.shipMode() + // }, + // remove() {} + // }, + // { + // name: "-quantum leap-", + // description: "experiment: every 20 seconds
become an alternate version of yourself", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isBadRandomOption: true, + // isExperimentalMode: true, + // allowed() { + // return build.isExperimentSelection + // }, + // requires: "", + // interval: undefined, + // effect() { + // this.interval = setInterval(() => { + // if (!build.isExperimentSelection) { + // m.switchWorlds() + // simulation.trails() + // } + // }, 20000); //every 20 seconds + + // }, + // remove() { + // if (this.count > 0) clearTimeout(this.interval); + // } + // }, + // { + // name: "-shields-", + // description: "experiment: every 5 seconds
all mobs gain a shield", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isBadRandomOption: true, + // isExperimentalMode: true, + // allowed() { + // return build.isExperimentSelection + // }, + // requires: "", + // effect() { + // this.interval = setInterval(() => { + // if (!build.isExperimentSelection) { + // for (let i = 0; i < mob.length; i++) { + // if (!mob[i].isShielded && !mob[i].shield && mob[i].isDropPowerUp) spawn.shield(mob[i], mob[i].position.x, mob[i].position.y, 1, true); + // } + // } + // }, 5000); //every 5 seconds + // }, + // interval: undefined, + // remove() { + // if (this.count > 0) clearTimeout(this.interval); + // } + // }, + // { + // name: "-Fourier analysis-", + // description: "experiment: your aiming is random", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isBadRandomOption: true, + // isExperimentalMode: true, + // allowed() { + // return build.isExperimentSelection && !m.isShipMode + // }, + // requires: "not ship", + // effect() { + // m.look = () => { + // m.angle = 2 * Math.sin(m.cycle * 0.0133) + Math.sin(m.cycle * 0.013) + 0.5 * Math.sin(m.cycle * 0.031) + 0.33 * Math.sin(m.cycle * 0.03) + // const scale = 0.8; + // m.transSmoothX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale; + // m.transSmoothY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale; + // m.transX += (m.transSmoothX - m.transX) * 0.07; + // m.transY += (m.transSmoothY - m.transY) * 0.07; + // } + // }, + // remove() { + // if (this.count > 0) m.look = m.lookDefault() + // } + // }, + // { + // name: "-panopticon-", + // description: "experiment: mobs can always see you", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isBadRandomOption: true, + // isExperimentalMode: true, + // allowed() { + // return build.isExperimentSelection + // }, + // requires: "", + // effect() { + // this.interval = setInterval(() => { + // if (!build.isExperimentSelection) { + // for (let i = 0; i < mob.length; i++) { + // if (!mob[i].shield && mob[i].isDropPowerUp) { + // mob[i].locatePlayer() + // mob[i].seePlayer.yes = true; + // } + // } + // } + // }, 1000); //every 1 seconds + // }, + // interval: undefined, + // remove() { + // if (this.count > 0) clearTimeout(this.interval); + // } + // }, + // { + // name: "-decomposers-", + // description: "experiment: after they die
mobs leave behind spawns", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isBadRandomOption: true, + // isExperimentalMode: true, + // allowed() { + // return build.isExperimentSelection + // }, + // requires: "", + // effect() { + // tech.deathSpawns = 0.2 + // }, + // remove() { + // tech.deathSpawns = 0 + // } + // }, + + + + //************************************************** + //************************************************** JUNK + //************************************************** tech + //************************************************** + // { + // name: "junk", + // description: "", + // maxCount: 9, + // count: 0, + // frequency: 0, + // isInstant: true, + // isJunk: true, + // allowed() { + // return true + // }, + // requires: "", + // effect() { + + // }, + // remove() {} + // }, + { + name: "swap meet", + description: `normal ${powerUps.orb.tech()} become JUNK
and JUNK become normal`, + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed() { + return true + }, + requires: "", + effect() { + for (let i = 0, len = tech.tech.length; i < len; i++) { + tech.tech[i].isJunk = !tech.tech[i].isJunk + if (tech.tech[i].isJunk) { } else { } + + if (tech.tech[i].frequency > 0) { + tech.tech[i].frequency = 0 + } else { + tech.tech[i].frequency = 2 + } + } + }, + remove() { } + }, + // { + // name: "pocket dimension", + // description: "rotate tech descriptions into a higher spacial dimension", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isJunk: true, + // isInstant: true, + // allowed() { + // return true + // }, + // requires: "", + // effect() { + // document.getElementById("choose-grid").classList.add("flipX"); + // }, + // remove() {} + // }, + { + name: "random", + link: `random`, + delay: 333, + descriptionFunction() { + const delay = 333 + const loop = () => { + if ((simulation.isChoosing) && m.alive && !build.isExperimentSelection) { + const dmg = Math.floor(27 * Math.random()) * 0.01 + this.text = `+${(1 + dmg).toFixed(2).padStart(2, '0')}x damage` + this.damage = 1 + dmg + if (document.getElementById(`damage-JUNK-id${this.id}`)) document.getElementById(`damage-JUNK-id${this.id}`).innerHTML = this.text + setTimeout(() => { + loop() + }, delay); + } + } + setTimeout(() => { + loop() + }, delay); + this.id++ + return `${this.text}` + }, + maxCount: 3, + count: 0, + frequency: 1, + isJunk: true, + allowed() { + return !build.isExperimentSelection + }, + requires: "NOT EXPERIMENT MODE", + damage: 0, + effect() { + tech.damage *= this.damage + }, + remove() { + if (this.count && m.alive) tech.damage /= this.damage + } + }, + { + name: "boost", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed() { + return !build.isExperimentSelection + }, + requires: "NOT EXPERIMENT MODE", + effect() { + powerUps.spawnDelay("boost", this.spawnCount) + }, + remove() { }, + id: 0, + text: "", + delay: 100, + spawnCount: 0, + descriptionFunction() { + let count = 9999 * Math.random() + const loop = () => { + if ((simulation.isChoosing) && m.alive && !build.isExperimentSelection) { //&& (!simulation.isChoosing || this.count === 0) //simulation.paused || + count += 4.5 + const waves = 2 * Math.sin(count * 0.0133) + Math.sin(count * 0.013) + 0.5 * Math.sin(count * 0.031) + 0.33 * Math.sin(count * 0.03) + this.spawnCount = Math.floor(100 * Math.abs(waves)) + this.text = `spawn ${this.spawnCount.toLocaleString(undefined, { minimumIntegerDigits: 3 })} ${powerUps.orb.boost(1)}
that give ${(1 + powerUps.boost.damage).toFixed(2)}x damage for ${(powerUps.boost.duration / 60).toFixed(0)} seconds` + if (document.getElementById(`boost-JUNK-id${this.id}`)) document.getElementById(`boost-JUNK-id${this.id}`).innerHTML = this.text + setTimeout(() => { + loop() + }, this.delay); + } + } + setTimeout(() => { + loop() + }, this.delay); + this.id++ + return `${this.text}` + }, + }, + { + name: "placebo", + description: "7.77x damage", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed: () => true, + requires: "", + effect() { + if (Math.random() < 0.07) tech.damage *= 7.77 + }, + remove() { } + }, + { + name: "universal healthcare", + description: "make your damage negative", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed: () => true, + requires: "", + effect() { + tech.damage *= -1 + }, + remove() { } + }, + { + name: "defunct", + description: "build 100 scrap bots
bots might last for 30 seconds", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed: () => true, + requires: "", + effect() { + for (let i = 0; i < 100; i++) { + b.randomBot(m.pos, false) + bullet[bullet.length - 1].endCycle = simulation.cycle + 800 + 1000 * Math.random() //15 seconds + } + }, + remove() { } + }, + // { + // name: "synchrotron", + // descriptionFunction() { + // return `power ups change into a different flavor after a boss dies` + // }, + // maxCount: 3, + // count: 0, + // frequency: 1, + // frequencyDefault: 1, + // allowed: () => true, + // requires: "", + // effect() { + // }, + // remove() { + // } + // }, + { + name: "return", + description: "return to the start of the game", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + level.onLevel = 0 + simulation.clearNow = true //end current level + }, + remove() { } + }, + { + name: "panpsychism", + description: "awaken all blocks
blocks have a chance to spawn power ups", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + setInterval(() => { + for (let i = body.length - 1; i > -1; i--) { + if (!body[i].isNotHoldable) { + Matter.Composite.remove(engine.world, body[i]); + spawn.blockMob(body[i].position.x, body[i].position.y, body[i], 0); + if (!body[i].isAboutToBeRemoved) mob[mob.length - 1].isDropPowerUp = true + body.splice(i, 1); + } + } + }, 6000); + }, + remove() { } + }, + { + name: "meteor shower", + description: "take a shower, but meteors instead of water", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + setInterval(() => { + + fireBlock = function (xPos, yPos) { + const index = body.length + spawn.bodyRect(xPos, yPos, 20 + 50 * Math.random(), 20 + 50 * Math.random()); + const bodyBullet = body[index] + Matter.Body.setVelocity(bodyBullet, { + x: 5 * (Math.random() - 0.5), + y: 10 * (Math.random() - 0.5) + }); + bodyBullet.isAboutToBeRemoved = true + setTimeout(() => { //remove block + for (let i = 0; i < body.length; i++) { + if (body[i] === bodyBullet) { + Matter.Composite.remove(engine.world, body[i]); + body.splice(i, 1); + } + } + }, 4000 + Math.floor(9000 * Math.random())); + } + fireBlock(player.position.x + 600 * (Math.random() - 0.5), player.position.y - 500 - 500 * Math.random()); + // for (let i = 0, len = Math.random(); i < len; i++) { + // } + + }, 1000); + }, + remove() { } + }, + { + name: "reinforcement learning", + description: `10x frequency for current ${powerUps.orb.tech()}`, + maxCount: 1, + count: 0, + frequency: 1, + isJunk: true, + allowed() { + return tech.totalCount > 9 + }, + requires: "at least 10 tech", + effect() { + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].count > 0) tech.tech[i].frequency *= 10 + } + }, + remove() { + if (this.count) { + for (let i = 0, len = tech.tech.length; i < len; i++) { + if (tech.tech[i].count > 0 && tech.tech[i].frequency > 1) tech.tech[i].frequency /= 10 + } + } + } + }, + { + name: "startle response", + description: `if a threat is nearby, activate a ${powerUps.orb.boost(1)}
and lock your mouse until you press escape`, + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + // tech.damage *= 1.33 + setInterval(() => { + if (powerUps.boost.endCycle < simulation.cycle && !simulation.paused && m.alive) { + for (let i = 0; i < mob.length; i++) { + if (mob[i].distanceToPlayer2() < 400000) { //650 + canvas.requestPointerLock(); + powerUps.boost.effect(); + break + } + } + } + }, 2000); + }, + remove() { } + }, + { + name: "closed timelike curve", + description: `spawn ${powerUps.orb.field()}${powerUps.orb.field()}${powerUps.orb.field()}${powerUps.orb.field()}${powerUps.orb.field()}, but every 12 seconds
teleport a second into your future or past`, + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + for (let i = 0; i < 5; i++) powerUps.spawn(m.pos.x + 10 * Math.random(), m.pos.y + 10 * Math.random(), "field"); + + function loop() { + if (!simulation.paused && m.alive) { + if (!(simulation.cycle % 720)) { + requestAnimationFrame(() => { + if ((simulation.cycle % 1440) > 720) { //kinda alternate between each option + m.rewind(60) + m.energy += 0.4 * level.isReducedRegen//to make up for lost energy + } else { + simulation.timePlayerSkip(60) + } + }); //wrapping in animation frame prevents errors, probably + } + } + requestAnimationFrame(loop); + } + requestAnimationFrame(loop); + }, + remove() { } + }, + // { + // name: "translate", + // description: "translate n-gon into a random language", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isJunk: true, + // isInstant: true, + // allowed() { + // return true + // }, + // requires: "", + // effect() { + // // generate a container + // const gtElem = document.createElement('div') + // gtElem.id = "gtElem" + // gtElem.style.visibility = 'hidden' // make it invisible + // document.body.append(gtElem) + + // // generate a script to run after creation + // function initGT() { + // // create a new translate element + // new google.translate.TranslateElement({ pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL }, 'gtElem') + // // ok now since it's loaded perform a funny hack to make it work + // const langSelect = document.getElementsByClassName("goog-te-combo")[0] + // // select a random language. It takes a second for all langauges to load, so wait a second. + // setTimeout(() => { + // langSelect.selectedIndex = Math.round(langSelect.options.length * Math.random()) + // // simulate a click + // langSelect.dispatchEvent(new Event('change')) + // // now make it go away + // const bar = document.getElementById(':1.container') + // bar.style.display = 'none' + // bar.style.visibility = 'hidden' + // }, 1000) + + // } + + // // add the google translate script + // const translateScript = document.createElement('script') + // translateScript.src = '//translate.google.com/translate_a/element.js?cb=initGT' + // document.body.append(translateScript) + // }, + // remove() {} + // }, + { + name: "discount", + description: `get 3 random JUNK${powerUps.orb.tech()} for the price of 1!`, + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + for (let i = 0; i < 3; i++) { + const list = [] + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].isJunk) list.push(tech.tech[i].name) + } + let name = list[Math.floor(Math.random() * list.length)] + simulation.inGameConsole(`tech.giveTech("${name}")`); + tech.giveTech(name) + } + }, + remove() { } + }, + // { + // name: "hi", + // description: `spawn to seed 616 `, + // maxCount: 1, + // count: 0, + // frequency: 0, + // isInstant: true, + // isJunk: true, + // allowed() { + // return true + // }, + // requires: "", + // effect() { + // document.getElementById("seed").placeholder = Math.initialSeed = String(616) + // Math.seed = Math.abs(Math.hash(Math.initialSeed)) //update randomizer seed in case the player changed it + // }, + // remove() {} + // }, + { + name: "Higgs phase transition", + description: `instantly spawn ${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}, but add a chance to
remove everything with a 5 minute half-life`, + maxCount: 1, + count: 0, + frequency: 0, + frequencyDefault: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + powerUps.spawn(m.pos.x, m.pos.y, "tech"); + powerUps.spawn(m.pos.x + 30, m.pos.y, "tech"); + powerUps.spawn(m.pos.x + 60, m.pos.y, "tech"); + powerUps.spawn(m.pos.x, m.pos.y - 30, "tech"); + powerUps.spawn(m.pos.x + 30, m.pos.y - 60, "tech"); + + function loop() { + // (1-X)^cycles = chance to be removed //Math.random() < 0.000019 10 min + if (!simulation.paused && m.alive) { + if (Math.random() < 0.000038) { + // m.death(); + simulation.clearMap(); + simulation.draw.setPaths(); + return + } + } + requestAnimationFrame(loop); + } + requestAnimationFrame(loop); + }, + remove() { } + }, + { + name: "harvest", + description: "convert all the mobs on this level into ammo", + maxCount: 1, + count: 0, + frequency: 0, + frequencyDefault: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].isDropPowerUp) { + powerUps.spawn(mob[i].position.x, mob[i].position.y, "ammo"); + mob[i].death(); + } + } + }, + remove() { } + }, + { + name: "brainstorm", + description: `${powerUps.orb.tech()} choices randomize
every 0.5 seconds for 10 seconds`, + maxCount: 1, + count: 0, + frequency: 0, + frequencyDefault: 0, + isJunk: true, + allowed: () => true, + requires: "", + effect() { + tech.isBrainstorm = true + tech.isBrainstormActive = false + tech.brainStormDelay = 500 //show each option for 0.5 seconds + }, + remove() { + tech.isBrainstorm = false + tech.isBrainstormActive = false + } + }, + { + name: "catabolysis", + description: `set your maximum health to 1
double your current ammo 10 times`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return !tech.isFallingDamage && !tech.isOverHeal && !tech.isEnergyHealth + }, + requires: "not quenching, tungsten carbide, mass-energy", + effect() { + m.baseHealth = 0.01 + m.setMaxHealth(); + for (let i = 0; i < b.guns.length; i++) b.guns[i].ammo = b.guns[i].ammo * Math.pow(2, 10) + simulation.updateGunHUD(); + }, + remove() { } + }, + { + name: "palantír", + description: `see far away lands`, + maxCount: 1, + count: 0, + frequency: 0, + // isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + m.look = () => { + //always on mouse look + m.angle = Math.atan2( + simulation.mouseInGame.y - m.pos.y, + simulation.mouseInGame.x - m.pos.x + ); + //smoothed mouse look translations + const scale = 2; + m.transSmoothX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale; + m.transSmoothY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale; + m.transX += (m.transSmoothX - m.transX) * m.lookSmoothing; + m.transY += (m.transSmoothY - m.transY) * m.lookSmoothing; + } + }, + remove() { + if (this.count) m.look = m.lookDefault + } + }, + { + name: "motion sickness", + description: `disable camera smoothing`, + maxCount: 1, + count: 0, + frequency: 0, + // isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + m.look = () => { + //always on mouse look + m.angle = Math.atan2( + simulation.mouseInGame.y - m.pos.y, + simulation.mouseInGame.x - m.pos.x + ); + //smoothed mouse look translations + const scale = 1.2; + m.transSmoothX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale; + m.transSmoothY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale; + m.transX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale; + m.transY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale; + // m.transX += (m.transSmoothX - m.transX) * m.lookSmoothing; + // m.transY += (m.transSmoothY - m.transY) * m.lookSmoothing; + } + }, + remove() { + if (this.count) m.look = m.lookDefault + } + }, + { + name: "facsimile", + description: `inserts a copy of your current level into the level list`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + const index = Math.min(level.levels.length - 1, level.onLevel) + level.levels.splice(index, 0, level.levels[index]); + }, + remove() { } + }, + { + name: "negative friction", + description: "when you touch walls you speed up instead of slowing down. It's kinda fun.", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + player.friction = -0.4 + }, + remove() { + if (this.count) player.friction = 0.002 + } + }, + { + name: "bounce", + description: "you bounce off things. It's annoying, but not that bad.", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + player.restitution = 0.9 + }, + remove() { + if (this.count) player.restitution = 0 + } + }, + { + name: "mouth", + description: "mobs have a non functional mouth", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + mobs.draw = () => { + ctx.lineWidth = 2; + let i = mob.length; + while (i--) { + ctx.beginPath(); + const vertices = mob[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) ctx.lineTo(vertices[j].x, vertices[j].y); + ctx.quadraticCurveTo(mob[i].position.x, mob[i].position.y, vertices[0].x, vertices[0].y); + ctx.fillStyle = mob[i].fill; + ctx.strokeStyle = mob[i].stroke; + ctx.fill(); + ctx.stroke(); + } + } + }, + remove() { + mobs.draw = mobs.drawDefault + } + }, + { + name: "all-stars", + description: "make all mobs look like stars", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + mobs.draw = () => { + ctx.lineWidth = 2; + let i = mob.length; + while (i--) { + ctx.beginPath(); + const vertices = mob[i].vertices; + ctx.moveTo(vertices[0].x, vertices[0].y); + for (let j = 1, len = vertices.length; j < len; ++j) ctx.quadraticCurveTo(mob[i].position.x, mob[i].position.y, vertices[j].x, vertices[j].y); + ctx.quadraticCurveTo(mob[i].position.x, mob[i].position.y, vertices[0].x, vertices[0].y); + ctx.fillStyle = mob[i].fill; + ctx.strokeStyle = mob[i].stroke; + ctx.fill(); + ctx.stroke(); + } + } + }, + remove() { + mobs.draw = mobs.drawDefault + } + }, + // draw() { + // ctx.lineWidth = 2; + // let i = mob.length; + // while (i--) { + // ctx.beginPath(); + // const vertices = mob[i].vertices; + // ctx.moveTo(vertices[0].x, vertices[0].y); + // for (let j = 1, len = vertices.length; j < len; ++j) ctx.lineTo(vertices[j].x, vertices[j].y); + // ctx.lineTo(vertices[0].x, vertices[0].y); + // ctx.fillStyle = mob[i].fill; + // ctx.strokeStyle = mob[i].stroke; + // ctx.fill(); + // ctx.stroke(); + // } + // }, + { + name: "true colors", + description: `set all power ups to their real world colors`, + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed() { + return true + }, + requires: "", + effect() { + // const colors = shuffle(["#f7b", "#0eb", "#467", "#0cf", "hsl(246,100%,77%)", "#26a"]) + const colors = shuffle([powerUps.research.color, powerUps.heal.color, powerUps.ammo.color, powerUps.ammo.color, powerUps.field.color, powerUps.gun.color]) + powerUps.research.color = colors[0] + powerUps.heal.color = colors[1] + powerUps.ammo.color = colors[2] + powerUps.field.color = colors[3] + powerUps.tech.color = colors[4] + powerUps.gun.color = colors[5] + for (let i = 0; i < powerUp.length; i++) { + switch (powerUp[i].name) { + case "research": + powerUp[i].color = colors[0] + break; + case "heal": + powerUp[i].color = colors[1] + break; + case "ammo": + powerUp[i].color = colors[2] + break; + case "field": + powerUp[i].color = colors[3] + break; + case "tech": + powerUp[i].color = colors[4] + break; + case "gun": + powerUp[i].color = colors[5] + break; + } + } + }, + remove() { + // const colors = ["#f7b", "#0eb", "#467", "#0cf", "hsl(246,100%,77%)", "#26a"] //no shuffle + // powerUps.research.color = colors[0] + // powerUps.heal.color = colors[1] + // powerUps.ammo.color = colors[2] + // powerUps.field.color = colors[3] + // powerUps.tech.color = colors[4] + // powerUps.gun.color = colors[5] + // for (let i = 0; i < powerUp.length; i++) { + // switch (powerUp[i].name) { + // case "research": + // powerUp[i].color = colors[0] + // break; + // case "heal": + // powerUp[i].color = colors[1] + // break; + // case "ammo": + // powerUp[i].color = colors[2] + // break; + // case "field": + // powerUp[i].color = colors[3] + // break; + // case "tech": + // powerUp[i].color = colors[4] + // break; + // case "gun": + // powerUp[i].color = colors[5] + // break; + // } + // } + } + }, + { + name: "emergency broadcasting", + description: "emit 2 sine waveforms at 853 Hz and 960 Hz
lower your volume", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed() { + return true + }, + requires: "", + effect: () => { + //setup audio context + function tone(frequency) { + const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); + const oscillator1 = audioCtx.createOscillator(); + const gainNode1 = audioCtx.createGain(); + gainNode1.gain.value = 0.5; //controls volume + oscillator1.connect(gainNode1); + gainNode1.connect(audioCtx.destination); + oscillator1.type = "sine"; // 'sine' 'square', 'sawtooth', 'triangle' and 'custom' + oscillator1.frequency.value = frequency; // value in hertz + oscillator1.start(); + return audioCtx + } + // let sound = tone(1050) + + function EBS() { + const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); + + const oscillator1 = audioCtx.createOscillator(); + const gainNode1 = audioCtx.createGain(); + gainNode1.gain.value = 0.3; //controls volume + oscillator1.connect(gainNode1); + gainNode1.connect(audioCtx.destination); + oscillator1.type = "sine"; // 'sine' 'square', 'sawtooth', 'triangle' and 'custom' + oscillator1.frequency.value = 850; // value in hertz + oscillator1.start(); + + const oscillator2 = audioCtx.createOscillator(); + const gainNode2 = audioCtx.createGain(); + gainNode2.gain.value = 0.3; //controls volume + oscillator2.connect(gainNode2); + gainNode2.connect(audioCtx.destination); + oscillator2.type = "sine"; // 'sine' 'square', 'sawtooth', 'triangle' and 'custom' + oscillator2.frequency.value = 957; // value in hertz + oscillator2.start(); + return audioCtx + } + let sound = EBS() + + delay = 1000 + setTimeout(() => { + sound.suspend() + powerUps.spawn(m.pos.x + 160 * (Math.random() - 0.5), m.pos.y + 160 * (Math.random() - 0.5), "heal"); + setTimeout(() => { + sound.resume() + setTimeout(() => { + sound.suspend() + powerUps.spawn(m.pos.x + 160 * (Math.random() - 0.5), m.pos.y + 160 * (Math.random() - 0.5), "heal"); + setTimeout(() => { + sound.resume() + setTimeout(() => { + sound.suspend() + powerUps.spawn(m.pos.x + 160 * (Math.random() - 0.5), m.pos.y + 160 * (Math.random() - 0.5), "heal"); + setTimeout(() => { + sound.resume() + setTimeout(() => { + sound.suspend() + powerUps.spawn(m.pos.x + 160 * (Math.random() - 0.5), m.pos.y + 160 * (Math.random() - 0.5), "heal"); + setTimeout(() => { + sound.resume() + setTimeout(() => { + sound.suspend() + powerUps.spawn(m.pos.x + 160 * (Math.random() - 0.5), m.pos.y + 160 * (Math.random() - 0.5), "heal"); + setTimeout(() => { + sound.resume() + setTimeout(() => { + sound.suspend() + sound.close() + powerUps.spawn(m.pos.x + 160 * (Math.random() - 0.5), m.pos.y + 160 * (Math.random() - 0.5), "heal"); + }, delay); + }, delay); + }, delay); + }, delay); + }, delay); + }, delay); + }, delay); + }, delay); + }, delay); + }, delay); + }, delay); + }, + remove() { } + }, + { + name: "automatic", + description: "you can't fire when moving
always fire when at rest", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return !tech.isFireMoveLock + }, + requires: "not Higgs mechanism", + effect() { + tech.isAlwaysFire = true; + b.setFireMethod(); + }, + remove() { + if (tech.isAlwaysFire) { + tech.isAlwaysFire = false + b.setFireMethod(); + } + } + }, + { + name: "hidden variable", + descriptionFunction() { + return `spawn ${powerUps.orb.heal(20)}
but hide your health bar` + }, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + document.getElementById("health").style.display = "none" + document.getElementById("health-bg").style.display = "none" + document.getElementById("defense-bar").style.display = "none" + for (let i = 0; i < 20; i++) powerUps.spawn(m.pos.x + 160 * (Math.random() - 0.5), m.pos.y + 160 * (Math.random() - 0.5), "heal"); + }, + remove() { } + }, + { + name: "not a bug", + description: "initiate a totally safe game crash for 10 seconds", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + const savedfunction = simulation.drawCircle + simulation.drawCircle = () => { + const a = mob[Infinity].position //crashed the game in a visually interesting way, because of the ctx.translate command is never reverted in the main game loop + } + setTimeout(() => { + simulation.drawCircle = savedfunction + canvas.width = canvas.width //clears the canvas // works on chrome at least + powerUps.spawn(m.pos.x, m.pos.y, "tech"); + }, 10000); + + // for (;;) {} //freezes the tab + }, + remove() { } + }, + { + name: "what the block?", + description: "throwing a block throws you instead", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return m.fieldMode !== 8 && m.fieldMode !== 9 && !tech.isTokamak + }, + requires: "not pilot wave, tokamak, wormhole", + effect() { + m.throwBlock = m.throwSelf + }, + remove() { + m.throwBlock = m.throwBlockDefault + } + }, + { + name: "stationary", + description: "thrown blocks can't move,
but somehow they still have momentum...", + maxCount: 1, + count: 0, + frequency: 0, + // isInstant: true, + isJunk: true, + allowed() { + return m.fieldMode !== 8 && m.fieldMode !== 9 && !tech.isTokamak + }, + requires: "not pilot wave, tokamak, wormhole", + effect() { + tech.isStaticBlock = true + }, + remove() { + tech.isStaticBlock = false + } + }, + { + name: "spinor", + description: "the direction you aim is determined by your position", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return !m.isShipMode + }, + requires: "", + effect() { + m.look = function () { + //always on mouse look + m.angle = (((m.pos.x + m.pos.y) / 100 + Math.PI) % Math.PI * 2) - Math.PI + //smoothed mouse look translations + const scale = 0.8; + m.transSmoothX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale; + m.transSmoothY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale; + + m.transX += (m.transSmoothX - m.transX) * 0.07; + m.transY += (m.transSmoothY - m.transY) * 0.07; + } + }, + remove() { + if (this.count) m.look = m.lookDefault + } + }, + { + name: "p-zombie", + description: "set your health to 1
all mobs, not bosses, die and resurrect as zombies", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { return true }, + requires: "", + effect() { + m.health = 0.01 //set health to 1 + m.displayHealth(); + for (let i = mob.length - 1; i > -1; i--) { //replace mobs with zombies + if (mob[i].isDropPowerUp && !mob[i].isBoss && mob[i].alive) { + mob[i].isSoonZombie = true + mob[i].death() + } + } + }, + remove() { } + }, + { + name: "decomposers", + description: "after they die mobs leave behind spawns", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return tech.deathSpawns === 0 + }, + requires: "", + effect() { + tech.deathSpawns = 0.2 + }, + remove() { + tech.deathSpawns = 0 + } + }, + { + name: "panopticon", + description: "mobs can always see you", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + for (let i = 0; i < mob.length; i++) { + if (!mob[i].shield && mob[i].isDropPowerUp) { + mob[i].locatePlayer() + mob[i].seePlayer.yes = true; + } + } + }, 1000); //every 1 seconds + }, + remove() { } + }, + // { + // name: "inverted mouse", + // description: "your mouse is scrambled
it's fine, just rotate it 90 degrees", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isExperimentHide: true, + // isInstant: true, + // isJunk: true, + // allowed() { + // return !m.isShipMode + // }, + // requires: "not ship", + // effect() { + // document.body.addEventListener("mousemove", (e) => { + // const ratio = window.innerWidth / window.innerHeight + // simulation.mouse.x = e.clientY * ratio + // simulation.mouse.y = e.clientX / ratio; + // }); + // }, + // remove() { + // // m.look = m.lookDefault + // } + // }, + { + name: "Fourier analysis", + description: "your aiming is now controlled by this equation:
2sin(0.0133t) + sin(0.013t) + 0.5sin(0.031t)+ 0.33sin(0.03t)", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return !m.isShipMode + }, + requires: "not ship", + effect() { + m.look = () => { + m.angle = 2 * Math.sin(m.cycle * 0.0133) + Math.sin(m.cycle * 0.013) + 0.5 * Math.sin(m.cycle * 0.031) + 0.33 * Math.sin(m.cycle * 0.03) + const scale = 0.8; + simulation.mouse.y + m.transSmoothX = canvas.width2 - m.pos.x - (simulation.mouse.x - canvas.width2) * scale; + m.transSmoothY = canvas.height2 - m.pos.y - (simulation.mouse.y - canvas.height2) * scale; + m.transX += (m.transSmoothX - m.transX) * 0.07; + m.transY += (m.transSmoothY - m.transY) * 0.07; + } + }, + remove() { + if (this.count) m.look = m.lookDefault + } + }, + { + name: "disintegrated armament", + description: `spawn ${powerUps.orb.gun()}
remove your active ${powerUps.orb.gun()}`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return b.inventory.length > 0 + }, + requires: "at least 1 gun", + effect() { + if (b.inventory.length > 0) b.removeGun(b.guns[b.activeGun].name) + simulation.makeGunHUD() + powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "gun"); + }, + remove() { } + }, + { + name: "probability", + description: `100x frequency for
a random ${powerUps.orb.tech()}`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + let options = []; //find what tech I could get + for (let i = 0, len = tech.tech.length; i < len; i++) { + if ( + tech.tech[i].count < tech.tech[i].maxCount && + tech.tech[i].allowed() && + !tech.tech[i].isJunk && + !tech.tech.isLore + ) { + options.push(i); + } + } + if (options.length) { + const index = options[Math.floor(Math.random() * options.length)] + tech.tech[index].frequency = 100 + } + }, + remove() { } + }, + { + name: "encryption", + description: `secure information`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + String.prototype.shuffle = function () { + var a = this.split(""), + n = a.length; + + for (var i = n - 1; i > 0; i--) { + var j = Math.floor(Math.random() * (i + 1)); + var tmp = a[i]; + a[i] = a[j]; + a[j] = tmp; + } + return a.join(""); + } + + for (let i = 0, len = tech.tech.length; i < len; i++) tech.tech[i].name = tech.tech[i].name.shuffle() + }, + remove() { } + }, + { + name: "quantum leap", + description: "become an alternate version of yourself
every 20 seconds", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + m.switchWorlds() + simulation.trails() + }, 20000); //every 30 seconds + }, + remove() { } + }, + { + name: "score", + description: "Add a score to n-gon!", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + let score = Math.ceil(1000 * Math.random() * Math.random() * Math.random() * Math.random() * Math.random()) + simulation.inGameConsole(`simulation.score = ${score.toFixed(0)}`); + }, 10000); //every 10 seconds + }, + remove() { } + }, + { + name: "pop-ups", + description: "sign up to learn endless easy ways to win n-gon
that Landgreen doesn't want you to know!!!1!!", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + alert(`The best combo is ${tech.tech[Math.floor(Math.random() * tech.tech.length)].name} with ${tech.tech[Math.floor(Math.random() * tech.tech.length)].name}!`); + }, 30000); //every 30 seconds + }, + remove() { } + }, + { + name: "music", + description: "add music to n-gon", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + window.open('https://www.youtube.com/watch?v=lEbHeSdmS-k&list=PL9Z5wjoBiPKEDhwCW2RN-VZoCpmhIojdn', '_blank') + }, + remove() { } + }, + { + name: "performance", + description: "display performance stats to n-gon", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + (function () { + var script = document.createElement('script'); + script.onload = function () { + var stats = new Stats(); + document.body.appendChild(stats.dom); + requestAnimationFrame(function loop() { + stats.update(); + requestAnimationFrame(loop) + }); + }; + script.src = 'https://unpkg.com/stats.js@0.17.0/build/stats.min.js'; + document.head.appendChild(script); + })() + //move health to the right + document.getElementById("health").style.left = "86px" + document.getElementById("health-bg").style.left = "86px" + document.getElementById("defense-bar").style.left = "86px" + document.getElementById("damage-bar").style.left = "86px" + }, + remove() { } + }, + { + name: "repartitioning", + description: `set the JUNK chance to 100%
spawn ${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}${powerUps.orb.tech()}`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.addJunkTechToPool(1) + for (let i = 0; i < 5; i++) powerUps.spawn(m.pos.x, m.pos.y, "tech"); + }, + remove() { } + }, + { + name: "defragment", + description: "set the frequency of finding JUNK to zero", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.junkChance = 0; + }, + remove() { } + }, + // { + // name: "lubrication", + // description: "reduce block density and friction for this level", + // maxCount: 9, + // count: 0, + // frequency: 0, + // isInstant: true, + // isExperimentHide: true, + // isJunk: true, + // allowed() { + // return true + // }, + // requires: "", + // effect() { + // for (let i = 0; i < body.length; i++) { + // Matter.Body.setDensity(body[i], 0.0001) // 0.001 is normal + // body[i].friction = 0.01 + // } + // }, + // remove() {} + // }, + { + name: "pitch", + description: "oscillate the pitch of your world", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + if (!simulation.paused) ctx.rotate(0.001 * Math.sin(simulation.cycle * 0.01)) + }, 16); + }, + remove() { } + }, + // { + // name: "flatland", + // description: "map blocks line of sight", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isInstant: true, + // isJunk: true, + // allowed() { return true }, + // requires: "", + // effect() { + // simulation.draw.lineOfSightPrecalculation() //required precalculation for line of sight + // simulation.draw.drawMapPath = simulation.draw.drawMapSight + + // simulation.ephemera.push({ + // name: "LoS", count: 0, do() { + // const pos = m.pos + // const radius = 3000 + // if (!simulation.isTimeSkipping) { + // const vertices = simulation.sight.circleLoS(pos, radius); + // if (vertices.length) { + // ctx.beginPath(); + // ctx.moveTo(vertices[0].x, vertices[0].y); + // for (var i = 1; i < vertices.length; i++) { + // var currentDistance = Math.sqrt((vertices[i - 1].x - pos.x) ** 2 + (vertices[i - 1].y - pos.y) ** 2); + // var newDistance = Math.sqrt((vertices[i].x - pos.x) ** 2 + (vertices[i].y - pos.y) ** 2); + // if (Math.abs(currentDistance - radius) < 1 && Math.abs(newDistance - radius) < 1) { + // const currentAngle = Math.atan2(vertices[i - 1].y - pos.y, vertices[i - 1].x - pos.x); + // const newAngle = Math.atan2(vertices[i].y - pos.y, vertices[i].x - pos.x); + // ctx.arc(pos.x, pos.y, radius, currentAngle, newAngle); + // } else { + // ctx.lineTo(vertices[i].x, vertices[i].y) + // } + // } + // newDistance = Math.sqrt((vertices[0].x - pos.x) ** 2 + (vertices[0].y - pos.y) ** 2); + // currentDistance = Math.sqrt((vertices[vertices.length - 1].x - pos.x) ** 2 + (vertices[vertices.length - 1].y - pos.y) ** 2); + // if (Math.abs(currentDistance - radius) < 1 && Math.abs(newDistance - radius) < 1) { + // const currentAngle = Math.atan2(vertices[vertices.length - 1].y - pos.y, vertices[vertices.length - 1].x - pos.x); + // const newAngle = Math.atan2(vertices[0].y - pos.y, vertices[0].x - pos.x); + // ctx.arc(pos.x, pos.y, radius, currentAngle, newAngle); + // } else { + // ctx.lineTo(vertices[0].x, vertices[0].y) + // } + + // //stroke the map, so it looks different form the line of sight + // ctx.strokeStyle = "#234"; + // ctx.lineWidth = 9; + // ctx.stroke(simulation.draw.mapPath); //this has a pretty large impact on performance, maybe 5% worse performance + + // ctx.globalCompositeOperation = "destination-in"; + // ctx.fillStyle = "#000"; + // ctx.fill(); + // ctx.globalCompositeOperation = "source-over"; + // // also see the map + // // ctx.fill(simulation.draw.mapPath); + // // ctx.fillStyle = "#000"; + // ctx.clip(); + // } + // } + // }, + // }) + // }, + // remove() { } + // }, + { + name: "umbra", + description: "produce a blue glow around everything
and probably some simulation lag", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + ctx.shadowColor = '#06f'; + ctx.shadowBlur = 25; + }, + remove() { } + }, + { + name: "lighter", + description: `ctx.globalCompositeOperation = "lighter"`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + ctx.globalCompositeOperation = "lighter"; + }, + remove() { } + }, + { + name: "the upside down", + description: `Flip the universe until the end of the level.
I'll give you 1.1x damage as well.`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + simulation.flipCameraVertical(900) + tech.damage *= 1.1 + }, + remove() { } + }, + { + name: "rewind", + description: "every 10 seconds rewind 2 seconds", + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + m.rewind(120) + m.energy += 0.4 * level.isReducedRegen + }, 10000); + // for (let i = 0; i < 24; i++) { + // setTimeout(() => { m.rewind(120) }, i * 5000); + // } + }, + remove() { } + }, + { + name: "undo", + description: "every 4 seconds rewind 1/2 a second", + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + m.rewind(30) + m.energy += 0.2 * level.isReducedRegen + }, 4000); + }, + remove() { } + }, + { + name: "energy to mass conversion", + description: "convert your energy into blocks", + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + for (let i = 0, len = 40; i < len; i++) { + setTimeout(() => { + m.energy -= 1 / len + where = Vector.add(m.pos, { x: 400 * (Math.random() - 0.5), y: 400 * (Math.random() - 0.5) }) + spawn.bodyRect(where.x, where.y, Math.floor(15 + 100 * Math.random()), Math.floor(15 + 100 * Math.random())); + }, i * 100); + } + + }, + remove() { } + }, + { + name: "level.nextLevel()", + description: "advance to the next level", + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + level.nextLevel(); + }, + remove() { } + }, + { + name: "reincarnation", + description: "kill all mobs and spawn new ones
(also spawn a few extra mobs for fun)", + maxCount: 3, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + spawn.setSpawnList(); + spawn.setSpawnList(); + for (let i = 0, len = mob.length; i < len; i++) { + if (mob[i].alive && !mob[i].shield && !mob[i].isBadTarget) { + const pick = spawn.pickList[Math.floor(Math.random() * spawn.pickList.length)]; + spawn[pick](mob[i].position.x, mob[i].position.y); + if (Math.random() < 0.5) spawn[pick](mob[i].position.x, mob[i].position.y); + mob[i].death(); + } + } + }, + remove() { } + }, + { + name: "expert system", + description: `spawn ${powerUps.orb.tech()}
+50% JUNK choices`, + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return tech.junkChance < 1 + }, + requires: "", + effect() { + powerUps.spawn(m.pos.x, m.pos.y, "tech"); + tech.addJunkTechToPool(0.5) + }, + remove() { } + }, + { + name: "energy investment", + description: "every 10 seconds drain your energy
return it doubled 5 seconds later", + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + if (!simulation.paused) { + const energy = m.energy + m.energy = 0 + setTimeout(() => { //return energy + m.energy += 2 * energy + }, 5000); + } + }, 10000); + }, + remove() { } + }, + { + name: "missile launching system", + description: "fire missiles for the next 120 seconds", + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + for (let i = 0; i < 120; i++) { + setTimeout(() => { + const where = { + x: m.pos.x, + y: m.pos.y - 40 + } + b.missile(where, -Math.PI / 2 + 0.2 * (Math.random() - 0.5) * Math.sqrt(tech.missileCount), -2) + }, i * 1000); + } + }, + remove() { } + }, + { + name: "grenade production", + description: "drop a grenade every 2 seconds", + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + setInterval(() => { + if (!simulation.paused && document.visibilityState !== "hidden") { + b.grenade(Vector.add(m.pos, { + x: 10 * (Math.random() - 0.5), + y: 10 * (Math.random() - 0.5) + }), -Math.PI / 2) //fire different angles for each grenade + const who = bullet[bullet.length - 1] + Matter.Body.setVelocity(who, { + x: who.velocity.x * 0.1, + y: who.velocity.y * 0.1 + }); + } + }, 2000); + }, + remove() { } + }, + { + name: "wall jump", + description: "no knees or toes are drawn on the player
you can wall climb though", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed() { + return !m.isShipMode + }, + requires: "", + effect() { + m.skin.stubs() + jumpSensor.vertices[0].x += -22 + jumpSensor.vertices[3].x += -22 + jumpSensor.vertices[1].x += 22 + jumpSensor.vertices[2].x += 22 + }, + remove() { } + }, + { + name: "Sleipnir", + description: "grow more legs", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return !m.isShipMode + }, + requires: "", + effect() { + m.skin.Sleipnir() + }, + remove() { + if (this.count) m.resetSkin(); + } + }, + { + name: "diegesis", + description: "indicate fire cooldown

through a rotation of your head", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return !m.isShipMode + }, + requires: "", + effect() { + m.skin.diegesis() + }, + remove() { + if (this.count) m.resetSkin(); + } + }, + { + name: "🐱", + description: "🐈", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return !m.isShipMode + }, + requires: "", + effect() { + m.skin.cat(); + }, + remove() { + if (this.count) m.resetSkin(); + } + }, + { + name: "n-gone", + description: "become invisible to yourself
mobs can still see you", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + m.draw = () => { } + }, + remove() { + if (this.count) m.resetSkin(); + } + }, + { + name: "pareidolia", + description: "don't", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return !m.isShipMode + }, + requires: "", + effect() { + m.skin.pareidolia() + }, + remove() { + if (this.count) m.resetSkin(); + } + }, + { + name: "posture", + description: "stand a bit taller", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return !m.isShipMode + }, + requires: "", + effect() { + m.yOffWhen.stand = 70 + }, + remove() { + m.yOffWhen.stand = 49 + } + }, + { + name: "rhythm", + description: "you oscillate up and down
also you look like an egg", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed() { + return !m.isShipMode + }, + requires: "", + effect() { + m.skin.egg(); + setInterval(() => { + m.yOffWhen.stand = 53 + 28 * Math.sin(simulation.cycle * 0.2) + if (m.onGround && !m.crouch) m.yOffGoal = m.yOffWhen.stand + }, 100); + }, + remove() { } + }, + { + name: "prism", + description: "you cycle through different colors", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + m.color = { + hue: 0, + sat: 100, + light: 50 + } + setInterval(function () { + m.color.hue++ + m.setFillColors() + }, 10); + }, + remove() { } + }, + { + name: "ship", + description: "fly around with no legs", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return !m.isShipMode && !m.isAltSkin && m.fieldUpgrades[m.fieldMode].name !== "negative mass" + }, + requires: "", + effect() { + m.isAltSkin = true + m.shipMode() + //unlock relativistic rotation + for (let i = 0; i < tech.tech.length; i++) { + if (tech.tech[i].name === "relativistic rotation") tech.tech[i].frequency = 10 + } + }, + remove() { } + }, + { + name: "circular symmetry", + description: "turning the ship rotates the universe instead
2x damage", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return m.isShipMode + }, + requires: "", + effect() { + tech.damage *= 3 + + m.look = () => { + // const scale = 0; + m.transSmoothX = canvas.width2 - m.pos.x // - (simulation.mouse.x - canvas.width2) * scale; + m.transSmoothY = canvas.height2 - m.pos.y // - (simulation.mouse.y - canvas.height2) * scale; + m.transX += (m.transSmoothX - m.transX) * m.lookSmoothing; + m.transY += (m.transSmoothY - m.transY) * m.lookSmoothing; + ctx.restore(); + ctx.save(); + ctx.translate(canvas.width2, canvas.height2); //center + ctx.rotate(-m.angle) + ctx.translate(-canvas.width2, -canvas.height2); //center + } + }, + remove() { } + }, + { + name: "pet bots", + description: "pet your bots", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed() { + return b.totalBots() + }, + requires: "", + effect() { + simulation.ephemera.push({ + name: "pet", + count: 0, + do() { + this.count++ + if (!(this.count % 420)) { + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType && Math.random() < 0.3) { + simulation.inGameConsole(`${bullet[i].botType}-bot.pet()`) + if (m.onGround && !m.crouch) { + m.yOffGoal = m.yOffWhen.crouch; + setTimeout(() => { + if (!m.crouch) m.yOffGoal = m.yOffWhen.stand; + }, 1000); + if (m.immuneCycle < m.cycle + 90) m.immuneCycle = m.cycle + 90 + } + if (Math.random() < 0.3) break + } + } + + } + } + }) + }, + remove() { + } + }, + { + name: "assimilation", + description: "all your bots are converted to the same random model", + maxCount: 1, + count: 0, + frequency: 0, + isBotTech: true, + isInstant: true, + isJunk: true, + allowed() { + return b.totalBots() > 2 + }, + requires: "at least 3 bots", + effect() { + const total = b.totalBots(); + tech.dynamoBotCount = 0; + tech.nailBotCount = 0; + tech.laserBotCount = 0; + tech.orbitBotCount = 0; + tech.foamBotCount = 0; + tech.soundBotCount = 0; + tech.boomBotCount = 0; + tech.plasmaBotCount = 0; + tech.missileBotCount = 0; + for (let i = 0; i < bullet.length; i++) { + if (bullet[i].botType) bullet[i].endCycle = 0 + } + + const bots = [ + () => { + b.nailBot(); + tech.nailBotCount++; + }, + () => { + b.foamBot(); + tech.foamBotCount++; + }, + () => { + b.soundBot(); + tech.soundBotCount++; + }, + () => { + b.boomBot(); + tech.boomBotCount++; + }, + () => { + b.laserBot(); + tech.laserBotCount++; + }, + () => { + b.orbitBot(); + tech.orbitBotCount++ + }, + () => { + b.dynamoBot(); + tech.dynamoBotCount++ + } + ] + const index = Math.floor(Math.random() * bots.length) + for (let i = 0; i < total; i++) bots[index]() + }, + remove() { } + }, + { + name: "stun", + description: "stun all mobs for up to 8 seconds", + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + for (let i = 0; i < mob.length; i++) mobs.statusStun(mob[i], 480) + }, + remove() { } + }, + { + name: "translucent", + description: `spawn ${powerUps.orb.gun()}${powerUps.orb.gun()}${powerUps.orb.gun()}
your bullets and bots are transparent`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + for (let i = 0; i < 3; i++) powerUps.spawn(m.pos.x + 60 * (Math.random() - 0.5), m.pos.y + 60 * (Math.random() - 0.5), "gun"); + + // //removes guns and ammo + // b.inventory = []; + // b.activeGun = null; + // b.inventoryGun = 0; + // for (let i = 0, len = b.guns.length; i < len; ++i) { + // b.guns[i].have = false; + // if (b.guns[i].ammo !== Infinity) b.guns[i].ammo = 0; + // } + // simulation.makeGunHUD(); //update gun HUD + b.bulletDraw = () => { }; //make bullets invisible + }, + remove() { } + }, + { + name: "difficulty", + description: "spawn a power up that lets you
adjust the simulation difficulty parameters", + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return (level.levelsCleared < 5) + }, + requires: "before level 5", + effect() { + powerUps.spawn(m.pos.x, m.pos.y, "difficulty"); + }, + remove() { } + }, + { + name: "re-research", + description: `eject all your ${powerUps.orb.research(1)}`, + maxCount: 9, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return powerUps.research.count > 3 + }, + requires: "at least 4 research", + effect() { + powerUps.spawnDelay("research", powerUps.research.count); + powerUps.research.count = 0 + }, + remove() { } + }, + { + name: "black hole", + description: `use your energy and ${powerUps.orb.research(4)} to spawn
inside the event horizon of a huge black hole`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return powerUps.research.count > 3 + }, + requires: "at least 4 research", + effect() { + m.energy = 0 + spawn.suckerBoss(m.pos.x, m.pos.y - 700) + powerUps.research.changeRerolls(-4) + simulation.inGameConsole(`m.research --
${powerUps.research.count}`) + }, + remove() { } + }, + { + name: "apomixis", + description: `spawn 11 bosses`, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isInstant: true, + isJunk: true, + allowed() { + return tech.duplicationChance() > 0.99 + }, + requires: "duplication chance above 99%", + effect() { + const range = 1300 + for (let i = 0, len = 9; i < len; i++) { + const angle = 2 * Math.PI * i / len + spawn.randomLevelBoss(m.pos.x + range * Math.cos(angle), m.pos.y + range * Math.sin(angle), spawn.nonCollideBossList); + } + spawn.historyBoss(0, 0) + spawn.pulsarBoss(level.exit.x, level.exit.y, 70, true) + spawn.blockBoss(level.enter.x, level.enter.y) + }, + remove() { } + }, + { + name: "mobs!", + descriptionFunction() { + if (this.mobType === "") this.mobType = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)] + return `spawn 20 ${this.mobType} mobs` + }, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { return true }, + requires: "", + mobType: "", + effect() { + if (this.mobType === "") this.mobType = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)] + for (let i = 0; i < 20; i++) { + spawn[this.mobType](m.pos.x, m.pos.y - 700) + } + simulation.inGameConsole(`spawn.${this.mobType}(x,y)`) + + }, + remove() { } + }, + { + name: "black hole cluster", + description: `spawn 30 nearby black holes`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + const unit = { + x: 1, + y: 0 + } + for (let i = 0; i < 30; i++) { + const where = Vector.add(m.pos, Vector.mult(Vector.rotate(unit, Math.random() * 2 * Math.PI), 2000 + 1200 * Math.random())) + spawn.sucker(where.x, where.y, 140) + const who = mob[mob.length - 1] + who.locatePlayer() + // who.damageReduction = 0.2 + } + }, + remove() { } + }, + { + name: "rule 30", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return !build.isExperimentSelection + }, + requires: "NOT EXPERIMENT MODE", + effect() { }, + remove() { }, + state: [ + [false, false, false, Math.random() > 0.8, false, false, false, Math.random() > 0.8, false, false, false, false, false, false, false, false, false, true, false, false, false, Math.random() > 0.8, false, false, false, Math.random() > 0.8, false, false, false, false, Math.random() > 0.8, false, Math.random() > 0.8, false, false, false, Math.random() > 0.8, false, false, false, false, false, false, false, false, false] + ], + rule(state, a, b, c) { + //30 + if (state[a] && state[b] && state[c]) return false; // TTT => F + if (state[a] && state[b] && !state[c]) return false; // TTF => F + if (state[a] && !state[b] && state[c]) return false; //TFT => F + if (state[a] && !state[b] && !state[c]) return true; //TFF => T + if (!state[a] && state[b] && state[c]) return true; //FTT => T + if (!state[a] && state[b] && !state[c]) return true; //FTF => T + if (!state[a] && !state[b] && state[c]) return true; //FFT => T + if (!state[a] && !state[b] && !state[c]) return false; //FFF => F + }, + id: 0, + researchSpawned: 0, + descriptionFunction() { + const loop = () => { + if ((simulation.paused || simulation.isChoosing) && m.alive && !build.isExperimentSelection) { //&& (!simulation.isChoosing || this.count === 0) + let b = []; //produce next row + b.push(this.rule(this.state[this.state.length - 1], this.state[this.state.length - 1].length - 1, 0, 1)); //left edge wrap around + for (let i = 1; i < this.state[this.state.length - 1].length - 1; i++) { //apply rule to the rest of the array + b.push(this.rule(this.state[this.state.length - 1], i - 1, i, i + 1)); + } + b.push(this.rule(this.state[this.state.length - 1], this.state[this.state.length - 1].length - 2, this.state[this.state.length - 1].length - 1, 0)); //right edge wrap around + this.state.push(b) + if (document.getElementById(`cellular-rule-id${this.id}`)) document.getElementById(`cellular-rule-id${this.id}`).innerHTML = this.outputText() //convert to squares and send HTML + if (this.count && this.researchSpawned < 12 && !(this.state.length % 10)) { + this.researchSpawned++ + powerUps.spawn(m.pos.x - 50 + 100 * (Math.random() - 0.5), m.pos.y + 100 * (Math.random() - 0.5), "research"); + } + setTimeout(() => { + loop() + }, 300 + 5 * this.state.length); + } + } + setTimeout(() => { + loop() + }, 300); + this.id++ + return `${this.outputText()}` + }, + outputText() { + let text = "
"
+            for (let j = 0; j < this.state.length; j++) {
+                // text += "

" + text += "

" + for (let i = 0; i < this.state[j].length; i++) { + if (this.state[j][i]) { + text += "■" //"☻" //"⬛" //"█" //"■" + } else { + text += " " //"□" //"☺" //"⬜" //"    " //"□" + } + } + text += "

" + } + text += "
" + return text + }, + }, + { + name: "rule 90", + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return !build.isExperimentSelection + }, + requires: "NOT EXPERIMENT MODE", + effect() { }, + remove() { }, + state: [ + [false, false, false, Math.random() > 0.8, false, false, false, Math.random() > 0.8, false, false, false, false, false, false, false, false, false, true, true, false, false, false, Math.random() > 0.8, false, false, false, Math.random() > 0.8, false, false, false, false, Math.random() > 0.8, false, Math.random() > 0.8, false, false, false, Math.random() > 0.8, false, false, false, false, false, false, false, false] + ], + rule(state, a, b, c) { //90 + if (state[a] && state[b] && state[c]) return false; // TTT => F + if (state[a] && state[b] && !state[c]) return true; // TTF => T + if (state[a] && !state[b] && state[c]) return false; //TFT => F + if (state[a] && !state[b] && !state[c]) return true; //TFF => T + if (!state[a] && state[b] && state[c]) return true; //FTT => T + if (!state[a] && state[b] && !state[c]) return false; //FTF => F + if (!state[a] && !state[b] && state[c]) return true; //FFT => T + if (!state[a] && !state[b] && !state[c]) return false; //FFF => F + }, + id: 90, + researchSpawned: 0, + descriptionFunction() { + const loop = () => { + if ((simulation.paused || simulation.isChoosing) && m.alive && !build.isExperimentSelection) { //&& (!simulation.isChoosing || this.count === 0) + let b = []; //produce next row + b.push(this.rule(this.state[this.state.length - 1], this.state[this.state.length - 1].length - 1, 0, 1)); //left edge wrap around + for (let i = 1; i < this.state[this.state.length - 1].length - 1; i++) { //apply rule to the rest of the array + b.push(this.rule(this.state[this.state.length - 1], i - 1, i, i + 1)); + } + b.push(this.rule(this.state[this.state.length - 1], this.state[this.state.length - 1].length - 2, this.state[this.state.length - 1].length - 1, 0)); //right edge wrap around + this.state.push(b) + if (document.getElementById(`cellular-rule-id${this.id}`)) document.getElementById(`cellular-rule-id${this.id}`).innerHTML = this.outputText() //convert to squares and send HTML + if (this.count && this.researchSpawned < 12 && !(this.state.length % 10)) { + this.researchSpawned++ + powerUps.spawn(m.pos.x - 50 + 100 * (Math.random() - 0.5), m.pos.y + 100 * (Math.random() - 0.5), "research"); + } + setTimeout(() => { + loop() + }, 300 + 5 * this.state.length); + } + } + setTimeout(() => { + loop() + }, 300); + this.id++ + return `${this.outputText()}` + }, + outputText() { + let text = "
"
+            for (let j = 0; j < this.state.length; j++) {
+                // text += "

" + text += "

" + for (let i = 0; i < this.state[j].length; i++) { + if (this.state[j][i]) { + text += "■" //"☻" //"⬛" //"█" //"■" + } else { + text += " " //"□" //"☺" //"⬜" //"    " //"□" + } + } + text += "

" + } + text += "
" + return text + }, + }, + { + name: "wikipedia", + description: `After you get ${powerUps.orb.tech()} you have 7 seconds to study for a quiz. If you ace the quiz you get ${powerUps.orb.research(4)}`, + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + tech.isWiki = true; + }, + remove() { + tech.isWiki = false; + } + }, + { + name: "cosmogonic myth", + description: `open a portal to a primordial version of reality
in 5 minutes close the portal, spawn 1 of each power up
`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + const urls = ["https://scratch.mit.edu/projects/14005697/fullscreen/", "https://scratch.mit.edu/projects/22573757/fullscreen/", "https://scratch.mit.edu/projects/41429974/fullscreen/", "https://scratch.mit.edu/projects/43690666/fullscreen/", "https://codepen.io/lilgreenland/full/ozXNWZ", "https://codepen.io/lilgreenland/full/wzARJY", "classic/7-1-2017/", "classic/4-15-2018/", "classic/7-11-2019/", "classic/9-8-2019/", "classic/7-15-2020/", "classic/6-1-2021/"] + const choose = urls[Math.floor(Math.random() * urls.length)] + console.log(`opening new tab" ${choose}`) + let tab = window.open(choose, "_blank"); + setTimeout(() => { + tab.close(); + powerUps.spawn(m.pos.x, m.pos.y, "gun"); + setTimeout(() => { + powerUps.spawn(m.pos.x, m.pos.y - 50, "ammo") + }, 250); + setTimeout(() => { + powerUps.spawn(m.pos.x + 50, m.pos.y, "field"); + }, 500); + setTimeout(() => { + powerUps.spawn(m.pos.x + 50, m.pos.y - 50, "heal"); + }, 750); + setTimeout(() => { + powerUps.spawn(m.pos.x - 50, m.pos.y, "tech"); + }, 1000); + setTimeout(() => { + powerUps.spawn(m.pos.x - 50, m.pos.y - 50, "research"); + }, 1250); + }, 1000 * 5 * 60); + }, + remove() { } + }, + { + name: "beforeunload", + description: "75% of the time when you attempt to exit n-gon
you are prompted to cancel or continue.
Each time you cancel gain 1.25x damage.", + maxCount: 1, + count: 0, + frequency: 1, + isJunk: true, + allowed() { + return tech.totalCount > 9 + }, + requires: "at least 10 tech", + effect() { + tech.isExitPrompt = true + addEventListener('beforeunload', beforeUnloadEventListener); + }, + remove() { + tech.isExitPrompt = false + if (this.count > 0) removeEventListener('beforeunload', beforeUnloadEventListener); + } + }, + { + name: "planetesimals", + description: `play planetesimals (an asteroids-like game)
clear levels in planetesimals to spawn ${powerUps.orb.tech()}
if you die in planetesimals you die in n-gon`, + maxCount: 1, + count: 0, + frequency: 0, + isInstant: true, + isJunk: true, + allowed() { + return true + }, + requires: "", + effect() { + window.open('../../planetesimals/index.html', '_blank') + // powerUps.spawn(m.pos.x, m.pos.y, "tech"); + + // for communicating to other tabs, like planetesimals + // Connection to a broadcast channel + const bc = new BroadcastChannel('planetesimals'); + bc.activated = false + + bc.onmessage = function (ev) { + if (ev.data === 'tech') powerUps.spawn(m.pos.x, m.pos.y, "tech"); + if (ev.data === 'death') { + m.death() + bc.close(); //end session + } + if (ev.data === 'ready' && !bc.activated) { + bc.activated = true //prevents n-gon from activating multiple copies of planetesimals + bc.postMessage("activate"); + } + } + }, + remove() { } + }, + { + name: "tinker", + description: `permanently unlock JUNK${powerUps.orb.tech()} in experiment mode
this effect is stored for future visits`, + maxCount: 1, + count: 0, + frequency: 0, + frequencyDefault: 0, + isJunk: true, + isInstant: true, + allowed() { + return !localSettings.isJunkExperiment + }, + requires: "", + effect() { + localSettings.isJunkExperiment = true + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + }, + remove() { } + }, + { + name: "NFT", + descriptionFunction() { + return `buy your current game seed: ${Math.initialSeed}
no one is allowed to use your seeds
if they use them they are gonna get in trouble

your seeds: ${localSettings.personalSeeds.join(", ")}` + }, + maxCount: 1, + count: 0, + frequency: 0, + isJunk: true, + isInstant: true, + allowed: () => true, + requires: "", + effect() { + localSettings.personalSeeds.push(Math.initialSeed) + if (localSettings.isAllowed) localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + }, + remove() { } + }, + // { + // name: "rule 90", + // maxCount: 1, + // count: 0, + // frequency: 0, + // isJunk: true, + // allowed() { + // return true + // }, + // requires: "", + // effect() {}, + // remove() {}, + // state: [ + // [false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false] + // ], + // rule(state, a, b, c) { + // if (state[a] && state[b] && state[c]) return false; // TTT => F + // if (state[a] && state[b] && !state[c]) return true; // TTF => T + // if (state[a] && !state[b] && state[c]) return false; //TFT => F + // if (state[a] && !state[b] && !state[c]) return true; //TFF => T + // if (!state[a] && state[b] && state[c]) return true; //FTT => T + // if (!state[a] && state[b] && !state[c]) return false; //FTF => F + // if (!state[a] && !state[b] && state[c]) return true; //FFT => T + // if (!state[a] && !state[b] && !state[c]) return false; //FFF => F + // }, + // id: 0, + // descriptionFunction() { + // const loop = () => { + // if ((simulation.paused || simulation.isChoosing) && m.alive && !build.isExperimentSelection) { //&& (!simulation.isChoosing || this.count === 0) + // let b = []; //produce next row + // b.push(this.rule(this.state[this.state.length - 1], this.state[this.state.length - 1].length - 1, 0, 1)); //left edge wrap around + // for (let i = 1; i < this.state[this.state.length - 1].length - 1; i++) { //apply rule to the rest of the array + // b.push(this.rule(this.state[this.state.length - 1], i - 1, i, i + 1)); + // } + // b.push(this.rule(this.state[this.state.length - 1], this.state[this.state.length - 1].length - 2, this.state[this.state.length - 1].length - 1, 0)); //right edge wrap around + // this.state.push(b) + // if (document.getElementById(`cellular-rule-id${this.id}`)) document.getElementById(`cellular-rule-id${this.id}`).innerHTML = this.outputText() //convert to squares and send HTML + // if (this.count && this.state.length < 120 && !(this.state.length % 10)) powerUps.spawn(m.pos.x - 50 + 100 * (Math.random() - 0.5), m.pos.y + 100 * (Math.random() - 0.5), "research"); + // setTimeout(() => { loop() }, 400); + // } + // } + // setTimeout(() => { loop() }, 400); + // // if (this.id === 0) { + // // for (let i = 0; i < 29; i++) this.state[0][i] = Math.random() < 0.5 //randomize seed + // // } + // this.id++ + // return `${this.outputText()}` + // }, + // outputText() { + // let text = "" + // for (let j = 0; j < this.state.length; j++) { + // text += "

" + // for (let i = 0; i < this.state[j].length; i++) { + // if (this.state[j][i]) { + // text += "⬛" //"█" //"■" + // } else { + // text += "⬜" //"    " //"□" + // } + // } + // text += "

" + // } + // return text + // }, + // }, + + //************************************************** + //************************************************** undefined / lore + //************************************************** tech + //************************************************** + { + name: `undefined`, + description: `this
 `, + maxCount: 1, + count: 0, + frequency: 2, + frequencyDefault: 2, + isLore: true, + // isExperimentHide: true, + allowed() { return !build.isExperimentSelection }, + requires: "NOT EXPERIMENT MODE", + effect() { + if (localSettings.loreCount > lore.conversation.length - 1) { //reward for people done with lore chapters (or on the final chapter) + for (let i = mob.length - 1; i > -1; i--) { //replace mobs with starters + if (!mob[i].isBoss && mob[i].isDropPowerUp && mob[i].alive) { + spawn.starter(mob[i].position.x, mob[i].position.y) + mob[i].leaveBody = false + mob[i].isDropPowerUp = false + mob[i].death() + + //spawn a random power up + // if (Math.random() < 1 / 5) { + // powerUps.spawn(mob[i].position.x, mob[i].position.y, "research") + // } else + if (Math.random() < 1 / 4) { + powerUps.spawn(mob[i].position.x, mob[i].position.y, "ammo") + } else if (Math.random() < 1 / 3) { + powerUps.spawn(mob[i].position.x, mob[i].position.y, "heal") + } else if (Math.random() < 1 / 2) { + powerUps.spawn(mob[i].position.x, mob[i].position.y, "boost") + } else { + powerUps.spawn(mob[i].position.x, mob[i].position.y, "coupling") + } + } + } + } + + setTimeout(() => { //a short delay, I can't remember why + lore.techCount++ + if (lore.techCount === lore.techGoal) { + // tech.removeLoreTechFromPool(); + this.frequency = 0; + this.description = `null is open at level.final()
 ` + } else { + this.frequency += lore.techGoal * 2 + this.description = `uncaught error:
${Math.max(0, lore.techGoal - lore.techCount)} more required for access to null` + } + }, 1); + }, + remove() { + lore.techCount = 0; + this.maxCount = lore.techGoal; + this.description = `this
 ` + } + } + ], + //variables use for gun tech upgrades + fireRate: 1, //initializes to 1 + bulletSize: null, + energySiphon: null, + healSpawn: null, + crouchAmmoCount: null, + bulletsLastLonger: null, + isImmortal: null, + sporesOnDeath: null, + isImmuneExplosion: null, + isExplodeMob: null, + isDroneOnDamage: null, + isAcidDmg: null, + isAnnihilation: null, + largerHeals: null, + isCrit: null, + isLowHealthDmg: null, + isLowHealthDefense: null, + isLowHealthFireRate: null, + isFarAwayDmg: null, + isFirstDer: null, + isMassEnergy: null, + extraChoices: null, + laserBotCount: null, + dynamoBotCount: null, + nailBotCount: null, + foamBotCount: null, + soundBotCount: null, + boomBotCount: null, + plasmaBotCount: null, + missileBotCount: null, + orbitBotCount: null, + blockDmg: null, + isBlockRadiation: null, + isPiezo: null, + isFastDrones: null, + oneSuperBall: null, + laserReflections: null, + laserDamage: null, + isAmmoFromHealth: null, + mobSpawnWithHealth: null, + isEnergyRecovery: null, + isHealthRecovery: null, + isEnergyLoss: null, + isDeathAvoid: null, + isDeathAvoidedThisLevel: null, + isPlasmaRange: null, + isFreezeMobs: null, + isIceCrystals: null, + blockDamage: null, + isBlockStun: null, + isStunField: null, + isHarmDamage: null, + isVacuumBomb: null, + renormalization: null, + fragments: null, + energyDamage: null, + botSpawner: null, + isBotSpawnerReset: null, + isSporeFollow: null, + isNailRadiation: null, + isEnergyHealth: null, + isStun: null, + restDamage: null, + isRPG: null, + missileCount: null, + isDeterminism: null, + isSuperDeterminism: null, + isHarmReduce: null, + nailsDeathMob: null, + isSlowFPS: null, + isNeutronStun: null, + isAnsatz: null, + isDamageFromBulletCount: null, + laserDrain: null, + isNailShot: null, + slowFire: null, + fastTime: null, + isFastRadiation: null, + isAmmoForGun: null, + isRapidPulse: null, + isSporeFreeze: null, + isShotgunRecoil: null, + isHealLowHealth: null, + isAoESlow: null, + isHarmArmor: null, + isTurret: null, + isRerollDamage: null, + isHarmFreeze: null, + isBotArmor: null, + isRerollHaste: null, + researchHaste: null, + isMineDrop: null, + isRerollBots: null, + isNailBotUpgrade: null, + isFoamBotUpgrade: null, + isSoundBotUpgrade: null, + isLaserBotUpgrade: null, + isBoomBotUpgrade: null, + isOrbitBotUpgrade: null, + isDroneGrab: null, + isOneGun: null, + isDamageForGuns: null, + isGunCycle: null, + isFastFoam: null, + isSporeGrowth: null, + isStimulatedEmission: null, + // nailGun: null, + nailInstantFireRate: null, + isCapacitor: null, + isEnergyNoAmmo: null, + // isFreezeHarmImmune: null, + isSmallExplosion: null, + isExplosionHarm: null, + extraMaxHealth: null, + // bonusHealth: null, + isIntangible: null, + isCloakStun: null, + bonusEnergy: null, + // healGiveMaxEnergy: null, + healMaxEnergyBonus: 0, //not null + aimDamage: null, + isNoFireDefense: null, + isNoFireDamage: null, + duplicateChance: null, + beamSplitter: null, + iceEnergy: null, + isPerfectBrake: null, + explosiveRadius: null, + // isWormholeEnergy: null, + isWormholeDamage: null, + isNailCrit: null, + isFlechetteExplode: null, + isWormholeWorms: null, + isWormHoleBullets: null, + isWideLaser: null, + wideLaser: null, + isPulseLaser: null, + isRadioactive: null, + radioactiveDamage: null, + isRailEnergy: null, + isMineSentry: null, + isIncendiary: null, + overfillDrain: null, + isNeutronSlow: null, + // isRailAreaDamage: null, + historyLaser: null, + isSpeedHarm: null, + isSpeedDamage: null, + speedAdded: null, + isTimeSkip: null, + isCancelDuplication: null, + duplication: null, + isCancelRerolls: null, + isCancelTech: null, + cancelTechCount: null, + isBotDamage: null, + isBanish: null, + isRetain: null, + isMaxEnergyTech: null, + isLowEnergyDamage: null, + isRewindBot: null, + isRewindGrenade: null, + isExtruder: null, + isEndLevelPowerUp: null, + isMissileBig: null, + isMissileBiggest: null, + isLaserMine: null, + isFoamMine: null, + isAmmoFoamSize: null, + isIceIX: null, + isDupDamage: null, + isDupEnergy: null, + isFireRateForGuns: null, + cyclicImmunity: null, + isTechDamage: null, + isRestHarm: null, + isFireMoveLock: null, + isRivets: null, + isNeedles: null, + isExplodeRadio: null, + isPauseSwitchField: null, + isPauseEjectTech: null, + pauseEjectTech: null, + isShieldPierce: null, + isDuplicateMobs: null, + isDynamoBotUpgrade: null, + isBlockPowerUps: null, + isDamageAfterKillNoRegen: null, + isHarmReduceNoKill: null, + isSwitchReality: null, + isResearchReality: null, + isAnthropicDamage: null, + isMetaAnalysis: null, + isFoamAttract: null, + droneCycleReduction: null, + droneEnergyReduction: null, + isHalfHeals: null, + isAlwaysFire: null, + isDroneRespawn: null, + deathSpawns: null, + isMobBlockFling: null, + isPhaseVelocity: null, + waveBeamSpeed: null, + wavePacketAmplitude: null, + isCollisionRealitySwitch: null, + iceIXOnDeath: null, + wimpCount: null, + isAddBlockMass: null, + isDarkMatter: null, + isHarmDarkMatter: null, + isMoveDarkMatter: null, + isNotDarkMatter: null, + isSneakAttack: null, + isFallingDamage: null, + harmonics: null, + isStandingWaveExpand: null, + isTokamak: null, + isTokamakHeal: null, + tokamakHealCount: null, + isTokamakFly: null, + deflectEnergy: null, + superBallDelay: null, + isBlockExplode: null, + isOverHeal: null, + isDroneRadioactive: null, + droneRadioDamage: null, + isDroneTeleport: null, + isDroneFastLook: null, + isBulletTeleport: null, + isJunkResearch: null, + laserColor: null, + laserColorAlpha: null, + isLongitudinal: null, + is360Longitudinal: null, + isShotgunReversed: null, + fieldDuplicate: null, + isCloakingDamage: null, + harmonicEnergy: null, + isFieldHarmReduction: null, + isFastTime: null, + isAnthropicTech: null, + isSporeWorm: null, + isSporeFlea: null, + isFoamShot: null, + isIceShot: null, + isBlockRestitution: null, + isZeno: null, + isFieldFree: null, + isExtraGunField: null, + isBigField: null, + isSmartRadius: null, + isFilament: null, + isLargeHarpoon: null, + extraHarpoons: null, + ammoCap: null, + isHarpoonPowerUp: null, + harpoonDensity: null, + isAddRemoveMaxHealth: null, + cloakDuplication: null, + extruderRange: null, + isForeverDrones: null, + nailRecoil: null, + baseJumpForce: null, + baseFx: null, + isNeutronium: null, + isFreeWormHole: null, + isRewindField: null, + isCrouchRegen: null, + isAxion: null, + isDarkEnergy: null, + isDarkStar: null, + isWormholeMapIgnore: null, + isLessDamageReduction: null, + needleTunnel: null, + isBrainstorm: null, + isBrainstormActive: null, + brainStormDelay: null, + wormSize: null, + extraSuperBalls: null, + isTimeCrystals: null, + isGroundState: null, + isRailGun: null, + isDronesTravel: null, + isTechDebt: null, + isPlasmaBall: null, + plasmaDischarge: null, + missileFireCD: null, + isBotField: null, + isFoamBall: null, + isNoDraftPause: null, + isFoamPressure: null, + foamDamage: null, + isClusterExplode: null, + isCircleExplode: null, + isPetalsExplode: null, + isVerlet: null, + isIceMaxHealthLoss: null, + isIceKill: null, + isCritKill: null, + isQuantumEraser: null, + isPhononBlock: null, + isPhononWave: null, + isLaserLens: null, + laserCrit: null, + isSporeColony: null, + isExtraBotOption: null, + isLastHitDamage: null, + isCloakHealLastHit: null, + isRicochet: null, + isCancelCouple: null, + isCouplingPowerUps: null, + isBoostPowerUps: null, + isBoostReplaceAmmo: null, + isInfiniteWaveAmmo: null, + isJunkDNA: null, + buffedGun: 0, + isGunChoice: null, + railChargeRate: null, + isSuperHarm: null, + isZombieMobs: null, + isSuperMine: null, + sentryAmmo: null, + collidePowerUps: null, + isDilate: null, + isDiaphragm: null, + isNoGroundDamage: null, + isSuperBounce: null, + isDivisor: null, + isFoamCavitation: null, + isHealAttract: null, + isLaserField: null, + isHealBrake: null, + isMassProduction: null, + isPrinter: null, + isHookDefense: null, + hookNails: null, + isHarpoonDefense: null, + isReel: null, + harpoonPowerUpCycle: null, + isHarpoonFullHealth: null, + isMobFullHealthCloak: null, + isMobLowHealth: null, + isDamageCooldown: null, + isDamageCooldownTime: null, + isPowerUpDamage: null, + isExitPrompt: null, + isResearchDamage: null, + interestRate: null, + isImmunityDamage: null, + isMobDeathImmunity: null, + isMaxHealthDefense: null, + noDefenseSettingDamage: null, + isMaxHealthDamage: null, + isEjectOld: null, + isWiki: null, + isStaticBlock: null, + isDamageFieldTech: null, +} \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/lib/matter.min.js b/WebGames-master/WebGames-master/n-gon-master/lib/matter.min.js new file mode 100644 index 00000000..d93e50fe --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/lib/matter.min.js @@ -0,0 +1,714 @@ +/*! + * matter-js 0.18.0-alpha+0eeceb5 by @liabru + * Experimental pre-release build. + * http://brm.io/matter-js/ + * License MIT + */ +! function(e, t) { "object" == typeof exports && "object" == typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define("Matter", [], t) : "object" == typeof exports ? exports.Matter = t() : e.Matter = t() }(this, (function() { return function(e) { var t = {}; + + function n(i) { if (t[i]) return t[i].exports; var o = t[i] = { i: i, l: !1, exports: {} }; return e[i].call(o.exports, o, o.exports, n), o.l = !0, o.exports } return n.m = e, n.c = t, n.d = function(e, t, i) { n.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: i }) }, n.r = function(e) { "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 }) }, n.t = function(e, t) { if (1 & t && (e = n(e)), 8 & t) return e; if (4 & t && "object" == typeof e && e && e.__esModule) return e; var i = Object.create(null); if (n.r(i), Object.defineProperty(i, "default", { enumerable: !0, value: e }), 2 & t && "string" != typeof e) + for (var o in e) n.d(i, o, function(t) { return e[t] }.bind(null, o)); return i }, n.n = function(e) { var t = e && e.__esModule ? function() { return e.default } : function() { return e }; return n.d(t, "a", t), t }, n.o = function(e, t) { return Object.prototype.hasOwnProperty.call(e, t) }, n.p = "", n(n.s = 21) }([function(e, t) { var n = {}; + e.exports = n, + function() { n._nextId = 0, n._seed = 0, n._nowStartTime = +new Date, n._warnedOnce = {}, n._decomp = null, n.extend = function(e, t) { var i, o; "boolean" == typeof t ? (i = 2, o = t) : (i = 1, o = !0); for (var r = i; r < arguments.length; r++) { var a = arguments[r]; if (a) + for (var s in a) o && a[s] && a[s].constructor === Object ? e[s] && e[s].constructor !== Object ? e[s] = a[s] : (e[s] = e[s] || {}, n.extend(e[s], o, a[s])) : e[s] = a[s] } return e }, n.clone = function(e, t) { return n.extend({}, t, e) }, n.keys = function(e) { if (Object.keys) return Object.keys(e); var t = []; for (var n in e) t.push(n); return t }, n.values = function(e) { var t = []; if (Object.keys) { for (var n = Object.keys(e), i = 0; i < n.length; i++) t.push(e[n[i]]); return t } for (var o in e) t.push(e[o]); return t }, n.get = function(e, t, n, i) { t = t.split(".").slice(n, i); for (var o = 0; o < t.length; o += 1) e = e[t[o]]; return e }, n.set = function(e, t, i, o, r) { var a = t.split(".").slice(o, r); return n.get(e, t, 0, -1)[a[a.length - 1]] = i, i }, n.shuffle = function(e) { for (var t = e.length - 1; t > 0; t--) { var i = Math.floor(n.random() * (t + 1)), + o = e[t]; + e[t] = e[i], e[i] = o } return e }, n.choose = function(e) { return e[Math.floor(n.random() * e.length)] }, n.isElement = function(e) { return "undefined" != typeof HTMLElement ? e instanceof HTMLElement : !!(e && e.nodeType && e.nodeName) }, n.isArray = function(e) { return "[object Array]" === Object.prototype.toString.call(e) }, n.isFunction = function(e) { return "function" == typeof e }, n.isPlainObject = function(e) { return "object" == typeof e && e.constructor === Object }, n.isString = function(e) { return "[object String]" === toString.call(e) }, n.clamp = function(e, t, n) { return e < t ? t : e > n ? n : e }, n.sign = function(e) { return e < 0 ? -1 : 1 }, n.now = function() { if ("undefined" != typeof window && window.performance) { if (window.performance.now) return window.performance.now(); if (window.performance.webkitNow) return window.performance.webkitNow() } return Date.now ? Date.now() : new Date - n._nowStartTime }, n.random = function(t, n) { return n = void 0 !== n ? n : 1, (t = void 0 !== t ? t : 0) + e() * (n - t) }; var e = function() { return n._seed = (9301 * n._seed + 49297) % 233280, n._seed / 233280 }; + n.colorToNumber = function(e) { return 3 == (e = e.replace("#", "")).length && (e = e.charAt(0) + e.charAt(0) + e.charAt(1) + e.charAt(1) + e.charAt(2) + e.charAt(2)), parseInt(e, 16) }, n.logLevel = 1, n.log = function() { console && n.logLevel > 0 && n.logLevel <= 3 && console.log.apply(console, ["matter-js:"].concat(Array.prototype.slice.call(arguments))) }, n.info = function() { console && n.logLevel > 0 && n.logLevel <= 2 && console.info.apply(console, ["matter-js:"].concat(Array.prototype.slice.call(arguments))) }, n.warn = function() { console && n.logLevel > 0 && n.logLevel <= 3 && console.warn.apply(console, ["matter-js:"].concat(Array.prototype.slice.call(arguments))) }, n.warnOnce = function() { var e = Array.prototype.slice.call(arguments).join(" "); + n._warnedOnce[e] || (n.warn(e), n._warnedOnce[e] = !0) }, n.deprecated = function(e, t, i) { e[t] = n.chain((function() { n.warnOnce("🔅 deprecated 🔅", i) }), e[t]) }, n.nextId = function() { return n._nextId++ }, n.indexOf = function(e, t) { if (e.indexOf) return e.indexOf(t); for (var n = 0; n < e.length; n++) + if (e[n] === t) return n; return -1 }, n.map = function(e, t) { if (e.map) return e.map(t); for (var n = [], i = 0; i < e.length; i += 1) n.push(t(e[i])); return n }, n.topologicalSort = function(e) { var t = [], + i = [], + o = []; for (var r in e) i[r] || o[r] || n._topologicalSort(r, i, o, e, t); return t }, n._topologicalSort = function(e, t, i, o, r) { var a = o[e] || []; + i[e] = !0; for (var s = 0; s < a.length; s += 1) { var l = a[s]; + i[l] || (t[l] || n._topologicalSort(l, t, i, o, r)) } i[e] = !1, t[e] = !0, r.push(e) }, n.chain = function() { for (var e = [], t = 0; t < arguments.length; t += 1) { var n = arguments[t]; + n._chained ? e.push.apply(e, n._chained) : e.push(n) } var i = function() { for (var t, n = new Array(arguments.length), i = 0, o = arguments.length; i < o; i++) n[i] = arguments[i]; for (i = 0; i < e.length; i += 1) { var r = e[i].apply(t, n); + void 0 !== r && (t = r) } return t }; return i._chained = e, i }, n.chainPathBefore = function(e, t, i) { return n.set(e, t, n.chain(i, n.get(e, t))) }, n.chainPathAfter = function(e, t, i) { return n.set(e, t, n.chain(n.get(e, t), i)) }, n.setDecomp = function(e) { n._decomp = e }, n.getDecomp = function() { var e = n._decomp; try { e || "undefined" == typeof window || (e = window.decomp), e || "undefined" == typeof global || (e = global.decomp) } catch (t) { e = null } return e } }() }, function(e, t) { var n = {}; + e.exports = n, n.create = function(e) { var t = { min: { x: 0, y: 0 }, max: { x: 0, y: 0 } }; return e && n.update(t, e), t }, n.update = function(e, t, n) { e.min.x = 1 / 0, e.max.x = -1 / 0, e.min.y = 1 / 0, e.max.y = -1 / 0; for (var i = 0; i < t.length; i++) { var o = t[i]; + o.x > e.max.x && (e.max.x = o.x), o.x < e.min.x && (e.min.x = o.x), o.y > e.max.y && (e.max.y = o.y), o.y < e.min.y && (e.min.y = o.y) } n && (n.x > 0 ? e.max.x += n.x : e.min.x += n.x, n.y > 0 ? e.max.y += n.y : e.min.y += n.y) }, n.contains = function(e, t) { return t.x >= e.min.x && t.x <= e.max.x && t.y >= e.min.y && t.y <= e.max.y }, n.overlaps = function(e, t) { return e.min.x <= t.max.x && e.max.x >= t.min.x && e.max.y >= t.min.y && e.min.y <= t.max.y }, n.translate = function(e, t) { e.min.x += t.x, e.max.x += t.x, e.min.y += t.y, e.max.y += t.y }, n.shift = function(e, t) { var n = e.max.x - e.min.x, + i = e.max.y - e.min.y; + e.min.x = t.x, e.max.x = t.x + n, e.min.y = t.y, e.max.y = t.y + i } }, function(e, t) { var n = {}; + e.exports = n, n.create = function(e, t) { return { x: e || 0, y: t || 0 } }, n.clone = function(e) { return { x: e.x, y: e.y } }, n.magnitude = function(e) { return Math.sqrt(e.x * e.x + e.y * e.y) }, n.magnitudeSquared = function(e) { return e.x * e.x + e.y * e.y }, n.rotate = function(e, t, n) { var i = Math.cos(t), + o = Math.sin(t); + n || (n = {}); var r = e.x * i - e.y * o; return n.y = e.x * o + e.y * i, n.x = r, n }, n.rotateAbout = function(e, t, n, i) { var o = Math.cos(t), + r = Math.sin(t); + i || (i = {}); var a = n.x + ((e.x - n.x) * o - (e.y - n.y) * r); return i.y = n.y + ((e.x - n.x) * r + (e.y - n.y) * o), i.x = a, i }, n.normalise = function(e) { var t = n.magnitude(e); return 0 === t ? { x: 0, y: 0 } : { x: e.x / t, y: e.y / t } }, n.dot = function(e, t) { return e.x * t.x + e.y * t.y }, n.cross = function(e, t) { return e.x * t.y - e.y * t.x }, n.cross3 = function(e, t, n) { return (t.x - e.x) * (n.y - e.y) - (t.y - e.y) * (n.x - e.x) }, n.add = function(e, t, n) { return n || (n = {}), n.x = e.x + t.x, n.y = e.y + t.y, n }, n.sub = function(e, t, n) { return n || (n = {}), n.x = e.x - t.x, n.y = e.y - t.y, n }, n.mult = function(e, t) { return { x: e.x * t, y: e.y * t } }, n.div = function(e, t) { return { x: e.x / t, y: e.y / t } }, n.perp = function(e, t) { return { x: (t = !0 === t ? -1 : 1) * -e.y, y: t * e.x } }, n.neg = function(e) { return { x: -e.x, y: -e.y } }, n.angle = function(e, t) { return Math.atan2(t.y - e.y, t.x - e.x) }, n._temp = [n.create(), n.create(), n.create(), n.create(), n.create(), n.create()] }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(2), + r = n(0); + i.create = function(e, t) { for (var n = [], i = 0; i < e.length; i++) { var o = e[i], + r = { x: o.x, y: o.y, index: i, body: t, isInternal: !1 }; + n.push(r) } return n }, i.fromPath = function(e, t) { var n = []; return e.replace(/L?\s*([-\d.e]+)[\s,]*([-\d.e]+)*/gi, (function(e, t, i) { n.push({ x: parseFloat(t), y: parseFloat(i) }) })), i.create(n, t) }, i.centre = function(e) { for (var t, n, r, a = i.area(e, !0), s = { x: 0, y: 0 }, l = 0; l < e.length; l++) r = (l + 1) % e.length, t = o.cross(e[l], e[r]), n = o.mult(o.add(e[l], e[r]), t), s = o.add(s, n); return o.div(s, 6 * a) }, i.mean = function(e) { for (var t = { x: 0, y: 0 }, n = 0; n < e.length; n++) t.x += e[n].x, t.y += e[n].y; return o.div(t, e.length) }, i.area = function(e, t) { for (var n = 0, i = e.length - 1, o = 0; o < e.length; o++) n += (e[i].x - e[o].x) * (e[i].y + e[o].y), i = o; return t ? n / 2 : Math.abs(n) / 2 }, i.inertia = function(e, t) { for (var n, i, r = 0, a = 0, s = e, l = 0; l < s.length; l++) i = (l + 1) % s.length, r += (n = Math.abs(o.cross(s[i], s[l]))) * (o.dot(s[i], s[i]) + o.dot(s[i], s[l]) + o.dot(s[l], s[l])), a += n; return t / 6 * (r / a) }, i.translate = function(e, t, n) { n = void 0 !== n ? n : 1; var i, o = e.length, + r = t.x * n, + a = t.y * n; for (i = 0; i < o; i++) e[i].x += r, e[i].y += a; return e }, i.rotate = function(e, t, n) { if (0 !== t) { var i, o, r, a, s = Math.cos(t), + l = Math.sin(t), + c = n.x, + u = n.y, + d = e.length; for (a = 0; a < d; a++) o = (i = e[a]).x - c, r = i.y - u, i.x = c + (o * s - r * l), i.y = u + (o * l + r * s); return e } }, i.contains = function(e, t) { for (var n, i = t.x, o = t.y, r = e.length, a = e[r - 1], s = 0; s < r; s++) { if (n = e[s], (i - a.x) * (n.y - a.y) + (o - a.y) * (a.x - n.x) > 0) return !1; + a = n } return !0 }, i.scale = function(e, t, n, r) { if (1 === t && 1 === n) return e; var a, s; + r = r || i.centre(e); for (var l = 0; l < e.length; l++) a = e[l], s = o.sub(a, r), e[l].x = r.x + s.x * t, e[l].y = r.y + s.y * n; return e }, i.chamfer = function(e, t, n, i, a) { t = "number" == typeof t ? [t] : t || [8], n = void 0 !== n ? n : -1, i = i || 2, a = a || 14; for (var s = [], l = 0; l < e.length; l++) { var c = e[l - 1 >= 0 ? l - 1 : e.length - 1], + u = e[l], + d = e[(l + 1) % e.length], + p = t[l < t.length ? l : t.length - 1]; if (0 !== p) { var f = o.normalise({ x: u.y - c.y, y: c.x - u.x }), + v = o.normalise({ x: d.y - u.y, y: u.x - d.x }), + y = Math.sqrt(2 * Math.pow(p, 2)), + m = o.mult(r.clone(f), p), + g = o.normalise(o.mult(o.add(f, v), .5)), + x = o.sub(u, o.mult(g, y)), + h = n; - 1 === n && (h = 1.75 * Math.pow(p, .32)), (h = r.clamp(h, i, a)) % 2 == 1 && (h += 1); for (var b = Math.acos(o.dot(f, v)) / h, S = 0; S < h; S++) s.push(o.add(o.rotate(m, b * S), x)) } else s.push(u) } return s }, i.clockwiseSort = function(e) { var t = i.mean(e); return e.sort((function(e, n) { return o.angle(t, e) - o.angle(t, n) })), e }, i.isConvex = function(e) { var t, n, i, o, r = 0, + a = e.length; if (a < 3) return null; for (t = 0; t < a; t++) + if (i = (t + 2) % a, o = (e[n = (t + 1) % a].x - e[t].x) * (e[i].y - e[n].y), (o -= (e[n].y - e[t].y) * (e[i].x - e[n].x)) < 0 ? r |= 1 : o > 0 && (r |= 2), 3 === r) return !1; return 0 !== r || null }, i.hull = function(e) { var t, n, i = [], + r = []; for ((e = e.slice(0)).sort((function(e, t) { var n = e.x - t.x; return 0 !== n ? n : e.y - t.y })), n = 0; n < e.length; n += 1) { for (t = e[n]; r.length >= 2 && o.cross3(r[r.length - 2], r[r.length - 1], t) <= 0;) r.pop(); + r.push(t) } for (n = e.length - 1; n >= 0; n -= 1) { for (t = e[n]; i.length >= 2 && o.cross3(i[i.length - 2], i[i.length - 1], t) <= 0;) i.pop(); + i.push(t) } return i.pop(), r.pop(), i.concat(r) } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(0); + i.on = function(e, t, n) { for (var i, o = t.split(" "), r = 0; r < o.length; r++) i = o[r], e.events = e.events || {}, e.events[i] = e.events[i] || [], e.events[i].push(n); return n }, i.off = function(e, t, n) { if (t) { "function" == typeof t && (n = t, t = o.keys(e.events).join(" ")); for (var i = t.split(" "), r = 0; r < i.length; r++) { var a = e.events[i[r]], + s = []; if (n && a) + for (var l = 0; l < a.length; l++) a[l] !== n && s.push(a[l]); + e.events[i[r]] = s } } else e.events = {} }, i.trigger = function(e, t, n) { var i, r, a, s, l = e.events; if (l && o.keys(l).length > 0) { n || (n = {}), i = t.split(" "); for (var c = 0; c < i.length; c++) + if (a = l[r = i[c]]) { + (s = o.clone(n, !1)).name = r, s.source = e; for (var u = 0; u < a.length; u++) a[u].apply(e, [s]) } } } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(4), + r = n(0), + a = n(1), + s = n(6); + i.create = function(e) { return r.extend({ id: r.nextId(), type: "composite", parent: null, isModified: !1, bodies: [], constraints: [], composites: [], label: "Composite", plugin: {}, cache: { allBodies: null, allConstraints: null, allComposites: null } }, e) }, i.setModified = function(e, t, n, o) { if (e.isModified = t, t && e.cache && (e.cache.allBodies = null, e.cache.allConstraints = null, e.cache.allComposites = null), n && e.parent && i.setModified(e.parent, t, n, o), o) + for (var r = 0; r < e.composites.length; r++) { var a = e.composites[r]; + i.setModified(a, t, n, o) } }, i.add = function(e, t) { var n = [].concat(t); + o.trigger(e, "beforeAdd", { object: t }); for (var a = 0; a < n.length; a++) { var s = n[a]; switch (s.type) { + case "body": + if (s.parent !== s) { r.warn("Composite.add: skipped adding a compound body part (you must add its parent instead)"); break } i.addBody(e, s); break; + case "constraint": + i.addConstraint(e, s); break; + case "composite": + i.addComposite(e, s); break; + case "mouseConstraint": + i.addConstraint(e, s.constraint) } } return o.trigger(e, "afterAdd", { object: t }), e }, i.remove = function(e, t, n) { var r = [].concat(t); + o.trigger(e, "beforeRemove", { object: t }); for (var a = 0; a < r.length; a++) { var s = r[a]; switch (s.type) { + case "body": + i.removeBody(e, s, n); break; + case "constraint": + i.removeConstraint(e, s, n); break; + case "composite": + i.removeComposite(e, s, n); break; + case "mouseConstraint": + i.removeConstraint(e, s.constraint) } } return o.trigger(e, "afterRemove", { object: t }), e }, i.addComposite = function(e, t) { return e.composites.push(t), t.parent = e, i.setModified(e, !0, !0, !1), e }, i.removeComposite = function(e, t, n) { var o = r.indexOf(e.composites, t); if (-1 !== o && i.removeCompositeAt(e, o), n) + for (var a = 0; a < e.composites.length; a++) i.removeComposite(e.composites[a], t, !0); return e }, i.removeCompositeAt = function(e, t) { return e.composites.splice(t, 1), i.setModified(e, !0, !0, !1), e }, i.addBody = function(e, t) { return e.bodies.push(t), i.setModified(e, !0, !0, !1), e }, i.removeBody = function(e, t, n) { var o = r.indexOf(e.bodies, t); if (-1 !== o && (i.removeBodyAt(e, o), t.isSleeping = !1, t.sleepCounter = 0), n) + for (var a = 0; a < e.composites.length; a++) i.removeBody(e.composites[a], t, !0); return e }, i.removeBodyAt = function(e, t) { return e.bodies.splice(t, 1), i.setModified(e, !0, !0, !1), e }, i.addConstraint = function(e, t) { return e.constraints.push(t), i.setModified(e, !0, !0, !1), e }, i.removeConstraint = function(e, t, n) { var o = r.indexOf(e.constraints, t); if (-1 !== o && i.removeConstraintAt(e, o), n) + for (var a = 0; a < e.composites.length; a++) i.removeConstraint(e.composites[a], t, !0); return e }, i.removeConstraintAt = function(e, t) { return e.constraints.splice(t, 1), i.setModified(e, !0, !0, !1), e }, i.clear = function(e, t, n) { if (n) + for (var o = 0; o < e.composites.length; o++) i.clear(e.composites[o], t, !0); return t ? e.bodies = e.bodies.filter((function(e) { return e.isStatic })) : e.bodies.length = 0, e.constraints.length = 0, e.composites.length = 0, i.setModified(e, !0, !0, !1), e }, i.allBodies = function(e) { if (e.cache && e.cache.allBodies) return e.cache.allBodies; for (var t = [].concat(e.bodies), n = 0; n < e.composites.length; n++) t = t.concat(i.allBodies(e.composites[n])); return e.cache && (e.cache.allBodies = t), t }, i.allConstraints = function(e) { if (e.cache && e.cache.allConstraints) return e.cache.allConstraints; for (var t = [].concat(e.constraints), n = 0; n < e.composites.length; n++) t = t.concat(i.allConstraints(e.composites[n])); return e.cache && (e.cache.allConstraints = t), t }, i.allComposites = function(e) { if (e.cache && e.cache.allComposites) return e.cache.allComposites; for (var t = [].concat(e.composites), n = 0; n < e.composites.length; n++) t = t.concat(i.allComposites(e.composites[n])); return e.cache && (e.cache.allComposites = t), t }, i.get = function(e, t, n) { var o, r; switch (n) { + case "body": + o = i.allBodies(e); break; + case "constraint": + o = i.allConstraints(e); break; + case "composite": + o = i.allComposites(e).concat(e) } return o ? 0 === (r = o.filter((function(e) { return e.id.toString() === t.toString() }))).length ? null : r[0] : null }, i.move = function(e, t, n) { return i.remove(e, t), i.add(n, t), e }, i.rebase = function(e) { for (var t = i.allBodies(e).concat(i.allConstraints(e)).concat(i.allComposites(e)), n = 0; n < t.length; n++) t[n].id = r.nextId(); return e }, i.translate = function(e, t, n) { for (var o = n ? i.allBodies(e) : e.bodies, r = 0; r < o.length; r++) s.translate(o[r], t); return e }, i.rotate = function(e, t, n, o) { for (var r = Math.cos(t), a = Math.sin(t), l = o ? i.allBodies(e) : e.bodies, c = 0; c < l.length; c++) { var u = l[c], + d = u.position.x - n.x, + p = u.position.y - n.y; + s.setPosition(u, { x: n.x + (d * r - p * a), y: n.y + (d * a + p * r) }), s.rotate(u, t) } return e }, i.scale = function(e, t, n, o, r) { for (var a = r ? i.allBodies(e) : e.bodies, l = 0; l < a.length; l++) { var c = a[l], + u = c.position.x - o.x, + d = c.position.y - o.y; + s.setPosition(c, { x: o.x + u * t, y: o.y + d * n }), s.scale(c, t, n) } return e }, i.bounds = function(e) { for (var t = i.allBodies(e), n = [], o = 0; o < t.length; o += 1) { var r = t[o]; + n.push(r.bounds.min, r.bounds.max) } return a.create(n) } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(3), + r = n(2), + a = n(7), + s = (n(16), n(0)), + l = n(1), + c = n(11);! function() { i._inertiaScale = 4, i._nextCollidingGroupId = 1, i._nextNonCollidingGroupId = -1, i._nextCategory = 1, i.create = function(t) { var n = { id: s.nextId(), type: "body", label: "Body", parts: [], plugin: {}, angle: 0, vertices: o.fromPath("L 0 0 L 40 0 L 40 40 L 0 40"), position: { x: 0, y: 0 }, force: { x: 0, y: 0 }, torque: 0, positionImpulse: { x: 0, y: 0 }, constraintImpulse: { x: 0, y: 0, angle: 0 }, totalContacts: 0, speed: 0, angularSpeed: 0, velocity: { x: 0, y: 0 }, angularVelocity: 0, isSensor: !1, isStatic: !1, isSleeping: !1, motion: 0, sleepThreshold: 60, density: .001, restitution: 0, friction: .1, frictionStatic: .5, frictionAir: .01, collisionFilter: { category: 1, mask: 4294967295, group: 0 }, slop: .05, timeScale: 1, render: { visible: !0, opacity: 1, strokeStyle: null, fillStyle: null, lineWidth: null, sprite: { xScale: 1, yScale: 1, xOffset: 0, yOffset: 0 } }, events: null, bounds: null, chamfer: null, circleRadius: 0, positionPrev: null, anglePrev: 0, parent: null, axes: null, area: 0, mass: 0, inertia: 0, _original: null }, + i = s.extend(n, t); return e(i, t), i }, i.nextGroup = function(e) { return e ? i._nextNonCollidingGroupId-- : i._nextCollidingGroupId++ }, i.nextCategory = function() { return i._nextCategory = i._nextCategory << 1, i._nextCategory }; var e = function(e, t) { t = t || {}, i.set(e, { bounds: e.bounds || l.create(e.vertices), positionPrev: e.positionPrev || r.clone(e.position), anglePrev: e.anglePrev || e.angle, vertices: e.vertices, parts: e.parts || [e], isStatic: e.isStatic, isSleeping: e.isSleeping, parent: e.parent || e }), o.rotate(e.vertices, e.angle, e.position), c.rotate(e.axes, e.angle), l.update(e.bounds, e.vertices, e.velocity), i.set(e, { axes: t.axes || e.axes, area: t.area || e.area, mass: t.mass || e.mass, inertia: t.inertia || e.inertia }); var n = e.isStatic ? "#14151f" : s.choose(["#f19648", "#f5d259", "#f55a3c", "#063e7b", "#ececd1"]), + a = e.isStatic ? "#555" : "#ccc", + u = e.isStatic && null === e.render.fillStyle ? 1 : 0; + e.render.fillStyle = e.render.fillStyle || n, e.render.strokeStyle = e.render.strokeStyle || a, e.render.lineWidth = e.render.lineWidth || u, e.render.sprite.xOffset += -(e.bounds.min.x - e.position.x) / (e.bounds.max.x - e.bounds.min.x), e.render.sprite.yOffset += -(e.bounds.min.y - e.position.y) / (e.bounds.max.y - e.bounds.min.y) }; + i.set = function(e, t, n) { var o; for (o in "string" == typeof t && (o = t, (t = {})[o] = n), t) + if (Object.prototype.hasOwnProperty.call(t, o)) switch (n = t[o], o) { + case "isStatic": + i.setStatic(e, n); break; + case "isSleeping": + a.set(e, n); break; + case "mass": + i.setMass(e, n); break; + case "density": + i.setDensity(e, n); break; + case "inertia": + i.setInertia(e, n); break; + case "vertices": + i.setVertices(e, n); break; + case "position": + i.setPosition(e, n); break; + case "angle": + i.setAngle(e, n); break; + case "velocity": + i.setVelocity(e, n); break; + case "angularVelocity": + i.setAngularVelocity(e, n); break; + case "parts": + i.setParts(e, n); break; + case "centre": + i.setCentre(e, n); break; + default: + e[o] = n } }, i.setStatic = function(e, t) { for (var n = 0; n < e.parts.length; n++) { var i = e.parts[n]; + i.isStatic = t, t ? (i._original = { restitution: i.restitution, friction: i.friction, mass: i.mass, inertia: i.inertia, density: i.density, inverseMass: i.inverseMass, inverseInertia: i.inverseInertia }, i.restitution = 0, i.friction = 1, i.mass = i.inertia = i.density = 1 / 0, i.inverseMass = i.inverseInertia = 0, i.positionPrev.x = i.position.x, i.positionPrev.y = i.position.y, i.anglePrev = i.angle, i.angularVelocity = 0, i.speed = 0, i.angularSpeed = 0, i.motion = 0) : i._original && (i.restitution = i._original.restitution, i.friction = i._original.friction, i.mass = i._original.mass, i.inertia = i._original.inertia, i.density = i._original.density, i.inverseMass = i._original.inverseMass, i.inverseInertia = i._original.inverseInertia, i._original = null) } }, i.setMass = function(e, t) { var n = e.inertia / (e.mass / 6); + e.inertia = n * (t / 6), e.inverseInertia = 1 / e.inertia, e.mass = t, e.inverseMass = 1 / e.mass, e.density = e.mass / e.area }, i.setDensity = function(e, t) { i.setMass(e, t * e.area), e.density = t }, i.setInertia = function(e, t) { e.inertia = t, e.inverseInertia = 1 / e.inertia }, i.setVertices = function(e, t) { t[0].body === e ? e.vertices = t : e.vertices = o.create(t, e), e.axes = c.fromVertices(e.vertices), e.area = o.area(e.vertices), i.setMass(e, e.density * e.area); var n = o.centre(e.vertices); + o.translate(e.vertices, n, -1), i.setInertia(e, i._inertiaScale * o.inertia(e.vertices, e.mass)), o.translate(e.vertices, e.position), l.update(e.bounds, e.vertices, e.velocity) }, i.setParts = function(e, t, n) { var r; for (t = t.slice(0), e.parts.length = 0, e.parts.push(e), e.parent = e, r = 0; r < t.length; r++) { var a = t[r]; + a !== e && (a.parent = e, e.parts.push(a)) } if (1 !== e.parts.length) { if (n = void 0 === n || n) { var s = []; for (r = 0; r < t.length; r++) s = s.concat(t[r].vertices); + o.clockwiseSort(s); var l = o.hull(s), + c = o.centre(l); + i.setVertices(e, l), o.translate(e.vertices, c) } var u = i._totalProperties(e); + e.area = u.area, e.parent = e, e.position.x = u.centre.x, e.position.y = u.centre.y, e.positionPrev.x = u.centre.x, e.positionPrev.y = u.centre.y, i.setMass(e, u.mass), i.setInertia(e, u.inertia), i.setPosition(e, u.centre) } }, i.setCentre = function(e, t, n) { n ? (e.positionPrev.x += t.x, e.positionPrev.y += t.y, e.position.x += t.x, e.position.y += t.y) : (e.positionPrev.x = t.x - (e.position.x - e.positionPrev.x), e.positionPrev.y = t.y - (e.position.y - e.positionPrev.y), e.position.x = t.x, e.position.y = t.y) }, i.setPosition = function(e, t) { var n = r.sub(t, e.position); + e.positionPrev.x += n.x, e.positionPrev.y += n.y; for (var i = 0; i < e.parts.length; i++) { var a = e.parts[i]; + a.position.x += n.x, a.position.y += n.y, o.translate(a.vertices, n), l.update(a.bounds, a.vertices, e.velocity) } }, i.setAngle = function(e, t) { var n = t - e.angle; + e.anglePrev += n; for (var i = 0; i < e.parts.length; i++) { var a = e.parts[i]; + a.angle += n, o.rotate(a.vertices, n, e.position), c.rotate(a.axes, n), l.update(a.bounds, a.vertices, e.velocity), i > 0 && r.rotateAbout(a.position, n, e.position, a.position) } }, i.setVelocity = function(e, t) { e.positionPrev.x = e.position.x - t.x, e.positionPrev.y = e.position.y - t.y, e.velocity.x = t.x, e.velocity.y = t.y, e.speed = r.magnitude(e.velocity) }, i.setAngularVelocity = function(e, t) { e.anglePrev = e.angle - t, e.angularVelocity = t, e.angularSpeed = Math.abs(e.angularVelocity) }, i.translate = function(e, t) { i.setPosition(e, r.add(e.position, t)) }, i.rotate = function(e, t, n) { if (n) { var o = Math.cos(t), + r = Math.sin(t), + a = e.position.x - n.x, + s = e.position.y - n.y; + i.setPosition(e, { x: n.x + (a * o - s * r), y: n.y + (a * r + s * o) }), i.setAngle(e, e.angle + t) } else i.setAngle(e, e.angle + t) }, i.scale = function(e, t, n, r) { var a = 0, + s = 0; + r = r || e.position; for (var u = 0; u < e.parts.length; u++) { var d = e.parts[u]; + o.scale(d.vertices, t, n, r), d.axes = c.fromVertices(d.vertices), d.area = o.area(d.vertices), i.setMass(d, e.density * d.area), o.translate(d.vertices, { x: -d.position.x, y: -d.position.y }), i.setInertia(d, i._inertiaScale * o.inertia(d.vertices, d.mass)), o.translate(d.vertices, { x: d.position.x, y: d.position.y }), u > 0 && (a += d.area, s += d.inertia), d.position.x = r.x + (d.position.x - r.x) * t, d.position.y = r.y + (d.position.y - r.y) * n, l.update(d.bounds, d.vertices, e.velocity) } e.parts.length > 1 && (e.area = a, e.isStatic || (i.setMass(e, e.density * a), i.setInertia(e, s))), e.circleRadius && (t === n ? e.circleRadius *= t : e.circleRadius = null) }, i.update = function(e, t, n, i) { var a = Math.pow(t * n * e.timeScale, 2), + s = 1 - e.frictionAir * n * e.timeScale, + u = e.position.x - e.positionPrev.x, + d = e.position.y - e.positionPrev.y; + e.velocity.x = u * s * i + e.force.x / e.mass * a, e.velocity.y = d * s * i + e.force.y / e.mass * a, e.positionPrev.x = e.position.x, e.positionPrev.y = e.position.y, e.position.x += e.velocity.x, e.position.y += e.velocity.y, e.angularVelocity = (e.angle - e.anglePrev) * s * i + e.torque / e.inertia * a, e.anglePrev = e.angle, e.angle += e.angularVelocity, e.speed = r.magnitude(e.velocity), e.angularSpeed = Math.abs(e.angularVelocity); for (var p = 0; p < e.parts.length; p++) { var f = e.parts[p]; + o.translate(f.vertices, e.velocity), p > 0 && (f.position.x += e.velocity.x, f.position.y += e.velocity.y), 0 !== e.angularVelocity && (o.rotate(f.vertices, e.angularVelocity, e.position), c.rotate(f.axes, e.angularVelocity), p > 0 && r.rotateAbout(f.position, e.angularVelocity, e.position, f.position)), l.update(f.bounds, f.vertices, e.velocity) } }, i.applyForce = function(e, t, n) { e.force.x += n.x, e.force.y += n.y; var i = t.x - e.position.x, + o = t.y - e.position.y; + e.torque += i * n.y - o * n.x }, i._totalProperties = function(e) { for (var t = { mass: 0, area: 0, inertia: 0, centre: { x: 0, y: 0 } }, n = 1 === e.parts.length ? 0 : 1; n < e.parts.length; n++) { var i = e.parts[n], + o = i.mass !== 1 / 0 ? i.mass : 1; + t.mass += o, t.area += i.area, t.inertia += i.inertia, t.centre = r.add(t.centre, r.mult(i.position, o)) } return t.centre = r.div(t.centre, t.mass), t } }() }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(4); + i._motionWakeThreshold = .18, i._motionSleepThreshold = .08, i._minBias = .9, i.update = function(e, t) { for (var n = t * t * t, o = 0; o < e.length; o++) { var r = e[o], + a = r.speed * r.speed + r.angularSpeed * r.angularSpeed; if (0 === r.force.x && 0 === r.force.y) { var s = Math.min(r.motion, a), + l = Math.max(r.motion, a); + r.motion = i._minBias * s + (1 - i._minBias) * l, r.sleepThreshold > 0 && r.motion < i._motionSleepThreshold * n ? (r.sleepCounter += 1, r.sleepCounter >= r.sleepThreshold && i.set(r, !0)) : r.sleepCounter > 0 && (r.sleepCounter -= 1) } else i.set(r, !1) } }, i.afterCollisions = function(e, t) { for (var n = t * t * t, o = 0; o < e.length; o++) { var r = e[o]; if (r.isActive) { var a = r.collision, + s = a.bodyA.parent, + l = a.bodyB.parent; if (!(s.isSleeping && l.isSleeping || s.isStatic || l.isStatic) && (s.isSleeping || l.isSleeping)) { var c = s.isSleeping && !s.isStatic ? s : l, + u = c === s ? l : s;!c.isStatic && u.motion > i._motionWakeThreshold * n && i.set(c, !1) } } } }, i.set = function(e, t) { var n = e.isSleeping; + t ? (e.isSleeping = !0, e.sleepCounter = e.sleepThreshold, e.positionImpulse.x = 0, e.positionImpulse.y = 0, e.positionPrev.x = e.position.x, e.positionPrev.y = e.position.y, e.anglePrev = e.angle, e.speed = 0, e.angularSpeed = 0, e.motion = 0, n || o.trigger(e, "sleepStart")) : (e.isSleeping = !1, e.sleepCounter = 0, n && o.trigger(e, "sleepEnd")) } }, function(e, t, n) { var i = {}; + e.exports = i; var o, r, a, s = n(3), + l = n(9); + o = [], r = { overlap: 0, axis: null }, a = { overlap: 0, axis: null }, i.create = function(e, t) { return { pair: null, collided: !1, bodyA: e, bodyB: t, parentA: e.parent, parentB: t.parent, depth: 0, normal: { x: 0, y: 0 }, tangent: { x: 0, y: 0 }, penetration: { x: 0, y: 0 }, supports: [] } }, i.collides = function(e, t, n) { if (i._overlapAxes(r, e.vertices, t.vertices, e.axes), r.overlap <= 0) return null; if (i._overlapAxes(a, t.vertices, e.vertices, t.axes), a.overlap <= 0) return null; var o, c, u = n && n.table[l.id(e, t)]; + u ? o = u.collision : ((o = i.create(e, t)).collided = !0, o.bodyA = e.id < t.id ? e : t, o.bodyB = e.id < t.id ? t : e, o.parentA = o.bodyA.parent, o.parentB = o.bodyB.parent), e = o.bodyA, t = o.bodyB, c = r.overlap < a.overlap ? r : a; var d = o.normal, + p = o.supports, + f = c.axis, + v = f.x, + y = f.y; + v * (t.position.x - e.position.x) + y * (t.position.y - e.position.y) < 0 ? (d.x = v, d.y = y) : (d.x = -v, d.y = -y), o.tangent.x = -d.y, o.tangent.y = d.x, o.depth = c.overlap, o.penetration.x = d.x * o.depth, o.penetration.y = d.y * o.depth; var m = i._findSupports(e, t, d, 1), + g = 0; if (s.contains(e.vertices, m[0]) && (p[g++] = m[0]), s.contains(e.vertices, m[1]) && (p[g++] = m[1]), g < 2) { var x = i._findSupports(t, e, d, -1); + s.contains(t.vertices, x[0]) && (p[g++] = x[0]), g < 2 && s.contains(t.vertices, x[1]) && (p[g++] = x[1]) } return 0 === g && (p[g++] = m[0]), p.length = g, o }, i._overlapAxes = function(e, t, n, i) { var o, r, a, s, l, c, u = t.length, + d = n.length, + p = t[0].x, + f = t[0].y, + v = n[0].x, + y = n[0].y, + m = i.length, + g = Number.MAX_VALUE, + x = 0; for (l = 0; l < m; l++) { var h = i[l], + b = h.x, + S = h.y, + w = p * b + f * S, + A = v * b + y * S, + P = w, + C = A; for (c = 1; c < u; c += 1)(s = t[c].x * b + t[c].y * S) > P ? P = s : s < w && (w = s); for (c = 1; c < d; c += 1)(s = n[c].x * b + n[c].y * S) > C ? C = s : s < A && (A = s); if ((o = (r = P - A) < (a = C - w) ? r : a) < g && (g = o, x = l, o <= 0)) break } e.axis = i[x], e.overlap = g }, i._projectToAxis = function(e, t, n) { for (var i = t[0].x * n.x + t[0].y * n.y, o = i, r = 1; r < t.length; r += 1) { var a = t[r].x * n.x + t[r].y * n.y; + a > o ? o = a : a < i && (i = a) } e.min = i, e.max = o }, i._findSupports = function(e, t, n, i) { var r, a, s, l, c, u = t.vertices, + d = u.length, + p = e.position.x, + f = e.position.y, + v = n.x * i, + y = n.y * i, + m = Number.MAX_VALUE; for (c = 0; c < d; c += 1)(l = v * (p - (a = u[c]).x) + y * (f - a.y)) < m && (m = l, r = a); return m = v * (p - (s = u[(d + r.index - 1) % d]).x) + y * (f - s.y), v * (p - (a = u[(r.index + 1) % d]).x) + y * (f - a.y) < m ? (o[0] = r, o[1] = a, o) : (o[0] = r, o[1] = s, o) } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(17); + i.create = function(e, t) { var n = e.bodyA, + o = e.bodyB, + r = { id: i.id(n, o), bodyA: n, bodyB: o, collision: e, contacts: [], activeContacts: [], separation: 0, isActive: !0, confirmedActive: !0, isSensor: n.isSensor || o.isSensor, timeCreated: t, timeUpdated: t, inverseMass: 0, friction: 0, frictionStatic: 0, restitution: 0, slop: 0 }; return i.update(r, e, t), r }, i.update = function(e, t, n) { var i = e.contacts, + r = t.supports, + a = e.activeContacts, + s = t.parentA, + l = t.parentB, + c = s.vertices.length; + e.isActive = !0, e.timeUpdated = n, e.collision = t, e.separation = t.depth, e.inverseMass = s.inverseMass + l.inverseMass, e.friction = s.friction < l.friction ? s.friction : l.friction, e.frictionStatic = s.frictionStatic > l.frictionStatic ? s.frictionStatic : l.frictionStatic, e.restitution = s.restitution > l.restitution ? s.restitution : l.restitution, e.slop = s.slop > l.slop ? s.slop : l.slop, t.pair = e, a.length = 0; for (var u = 0; u < r.length; u++) { var d = r[u], + p = d.body === s ? d.index : c + d.index, + f = i[p]; + f ? a.push(f) : a.push(i[p] = o.create(d)) } }, i.setActive = function(e, t, n) { t ? (e.isActive = !0, e.timeUpdated = n) : (e.isActive = !1, e.activeContacts.length = 0) }, i.id = function(e, t) { return e.id < t.id ? "A" + e.id + "B" + t.id : "A" + t.id + "B" + e.id } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(3), + r = n(2), + a = n(7), + s = n(1), + l = n(11), + c = n(0); + i._warming = .4, i._torqueDampen = 1, i._minLength = 1e-6, i.create = function(e) { var t = e; + t.bodyA && !t.pointA && (t.pointA = { x: 0, y: 0 }), t.bodyB && !t.pointB && (t.pointB = { x: 0, y: 0 }); var n = t.bodyA ? r.add(t.bodyA.position, t.pointA) : t.pointA, + i = t.bodyB ? r.add(t.bodyB.position, t.pointB) : t.pointB, + o = r.magnitude(r.sub(n, i)); + t.length = void 0 !== t.length ? t.length : o, t.id = t.id || c.nextId(), t.label = t.label || "Constraint", t.type = "constraint", t.stiffness = t.stiffness || (t.length > 0 ? 1 : .7), t.damping = t.damping || 0, t.angularStiffness = t.angularStiffness || 0, t.angleA = t.bodyA ? t.bodyA.angle : t.angleA, t.angleB = t.bodyB ? t.bodyB.angle : t.angleB, t.plugin = {}; var a = { visible: !0, lineWidth: 2, strokeStyle: "#ffffff", type: "line", anchors: !0 }; return 0 === t.length && t.stiffness > .1 ? (a.type = "pin", a.anchors = !1) : t.stiffness < .9 && (a.type = "spring"), t.render = c.extend(a, t.render), t }, i.preSolveAll = function(e) { for (var t = 0; t < e.length; t += 1) { var n = e[t], + i = n.constraintImpulse; + n.isStatic || 0 === i.x && 0 === i.y && 0 === i.angle || (n.position.x += i.x, n.position.y += i.y, n.angle += i.angle) } }, i.solveAll = function(e, t) { for (var n = 0; n < e.length; n += 1) { var o = e[n], + r = !o.bodyA || o.bodyA && o.bodyA.isStatic, + a = !o.bodyB || o.bodyB && o.bodyB.isStatic; + (r || a) && i.solve(e[n], t) } for (n = 0; n < e.length; n += 1) r = !(o = e[n]).bodyA || o.bodyA && o.bodyA.isStatic, a = !o.bodyB || o.bodyB && o.bodyB.isStatic, r || a || i.solve(e[n], t) }, i.solve = function(e, t) { var n = e.bodyA, + o = e.bodyB, + a = e.pointA, + s = e.pointB; if (n || o) { n && !n.isStatic && (r.rotate(a, n.angle - e.angleA, a), e.angleA = n.angle), o && !o.isStatic && (r.rotate(s, o.angle - e.angleB, s), e.angleB = o.angle); var l = a, + c = s; if (n && (l = r.add(n.position, a)), o && (c = r.add(o.position, s)), l && c) { var u = r.sub(l, c), + d = r.magnitude(u); + d < i._minLength && (d = i._minLength); var p, f, v, y, m, g = (d - e.length) / d, + x = e.stiffness < 1 ? e.stiffness * t : e.stiffness, + h = r.mult(u, g * x), + b = (n ? n.inverseMass : 0) + (o ? o.inverseMass : 0), + S = b + ((n ? n.inverseInertia : 0) + (o ? o.inverseInertia : 0)); if (e.damping) { var w = r.create(); + v = r.div(u, d), m = r.sub(o && r.sub(o.position, o.positionPrev) || w, n && r.sub(n.position, n.positionPrev) || w), y = r.dot(v, m) } n && !n.isStatic && (f = n.inverseMass / b, n.constraintImpulse.x -= h.x * f, n.constraintImpulse.y -= h.y * f, n.position.x -= h.x * f, n.position.y -= h.y * f, e.damping && (n.positionPrev.x -= e.damping * v.x * y * f, n.positionPrev.y -= e.damping * v.y * y * f), p = r.cross(a, h) / S * i._torqueDampen * n.inverseInertia * (1 - e.angularStiffness), n.constraintImpulse.angle -= p, n.angle -= p), o && !o.isStatic && (f = o.inverseMass / b, o.constraintImpulse.x += h.x * f, o.constraintImpulse.y += h.y * f, o.position.x += h.x * f, o.position.y += h.y * f, e.damping && (o.positionPrev.x += e.damping * v.x * y * f, o.positionPrev.y += e.damping * v.y * y * f), p = r.cross(s, h) / S * i._torqueDampen * o.inverseInertia * (1 - e.angularStiffness), o.constraintImpulse.angle += p, o.angle += p) } } }, i.postSolveAll = function(e) { for (var t = 0; t < e.length; t++) { var n = e[t], + c = n.constraintImpulse; if (!(n.isStatic || 0 === c.x && 0 === c.y && 0 === c.angle)) { a.set(n, !1); for (var u = 0; u < n.parts.length; u++) { var d = n.parts[u]; + o.translate(d.vertices, c), u > 0 && (d.position.x += c.x, d.position.y += c.y), 0 !== c.angle && (o.rotate(d.vertices, c.angle, n.position), l.rotate(d.axes, c.angle), u > 0 && r.rotateAbout(d.position, c.angle, n.position, d.position)), s.update(d.bounds, d.vertices, n.velocity) } c.angle *= i._warming, c.x *= i._warming, c.y *= i._warming } } }, i.pointAWorld = function(e) { return { x: (e.bodyA ? e.bodyA.position.x : 0) + (e.pointA ? e.pointA.x : 0), y: (e.bodyA ? e.bodyA.position.y : 0) + (e.pointA ? e.pointA.y : 0) } }, i.pointBWorld = function(e) { return { x: (e.bodyB ? e.bodyB.position.x : 0) + (e.pointB ? e.pointB.x : 0), y: (e.bodyB ? e.bodyB.position.y : 0) + (e.pointB ? e.pointB.y : 0) } } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(2), + r = n(0); + i.fromVertices = function(e) { for (var t = {}, n = 0; n < e.length; n++) { var i = (n + 1) % e.length, + a = o.normalise({ x: e[i].y - e[n].y, y: e[n].x - e[i].x }), + s = 0 === a.y ? 1 / 0 : a.x / a.y; + t[s = s.toFixed(3).toString()] = a } return r.values(t) }, i.rotate = function(e, t) { if (0 !== t) + for (var n = Math.cos(t), i = Math.sin(t), o = 0; o < e.length; o++) { var r, a = e[o]; + r = a.x * n - a.y * i, a.y = a.x * i + a.y * n, a.x = r } } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(3), + r = n(0), + a = n(6), + s = n(1), + l = n(2); + i.rectangle = function(e, t, n, i, s) { s = s || {}; var l = { label: "Rectangle Body", position: { x: e, y: t }, vertices: o.fromPath("L 0 0 L " + n + " 0 L " + n + " " + i + " L 0 " + i) }; if (s.chamfer) { var c = s.chamfer; + l.vertices = o.chamfer(l.vertices, c.radius, c.quality, c.qualityMin, c.qualityMax), delete s.chamfer } return a.create(r.extend({}, l, s)) }, i.trapezoid = function(e, t, n, i, s, l) { l = l || {}; var c, u = n * (s *= .5), + d = u + (1 - 2 * s) * n, + p = d + u; + c = s < .5 ? "L 0 0 L " + u + " " + -i + " L " + d + " " + -i + " L " + p + " 0" : "L 0 0 L " + d + " " + -i + " L " + p + " 0"; var f = { label: "Trapezoid Body", position: { x: e, y: t }, vertices: o.fromPath(c) }; if (l.chamfer) { var v = l.chamfer; + f.vertices = o.chamfer(f.vertices, v.radius, v.quality, v.qualityMin, v.qualityMax), delete l.chamfer } return a.create(r.extend({}, f, l)) }, i.circle = function(e, t, n, o, a) { o = o || {}; var s = { label: "Circle Body", circleRadius: n }; + a = a || 25; var l = Math.ceil(Math.max(10, Math.min(a, n))); return l % 2 == 1 && (l += 1), i.polygon(e, t, l, n, r.extend({}, s, o)) }, i.polygon = function(e, t, n, s, l) { if (l = l || {}, n < 3) return i.circle(e, t, s, l); for (var c = 2 * Math.PI / n, u = "", d = .5 * c, p = 0; p < n; p += 1) { var f = d + p * c, + v = Math.cos(f) * s, + y = Math.sin(f) * s; + u += "L " + v.toFixed(3) + " " + y.toFixed(3) + " " } var m = { label: "Polygon Body", position: { x: e, y: t }, vertices: o.fromPath(u) }; if (l.chamfer) { var g = l.chamfer; + m.vertices = o.chamfer(m.vertices, g.radius, g.quality, g.qualityMin, g.qualityMax), delete l.chamfer } return a.create(r.extend({}, m, l)) }, i.fromVertices = function(e, t, n, i, c, u, d, p) { var f, v, y, m, g, x, h, b, S, w, A = r.getDecomp(); for (f = Boolean(A && A.quickDecomp), i = i || {}, y = [], c = void 0 !== c && c, u = void 0 !== u ? u : .01, d = void 0 !== d ? d : 10, p = void 0 !== p ? p : .01, r.isArray(n[0]) || (n = [n]), S = 0; S < n.length; S += 1) + if (g = n[S], !(m = o.isConvex(g)) && !f && r.warnOnce("Bodies.fromVertices: Install the 'poly-decomp' library and use Common.setDecomp or provide 'decomp' as a global to decompose concave vertices."), m || !f) g = m ? o.clockwiseSort(g) : o.hull(g), y.push({ position: { x: e, y: t }, vertices: g }); + else { var P = g.map((function(e) { return [e.x, e.y] })); + A.makeCCW(P), !1 !== u && A.removeCollinearPoints(P, u), !1 !== p && A.removeDuplicatePoints && A.removeDuplicatePoints(P, p); var C = A.quickDecomp(P); for (x = 0; x < C.length; x++) { var B = C[x].map((function(e) { return { x: e[0], y: e[1] } })); + d > 0 && o.area(B) < d || y.push({ position: o.centre(B), vertices: B }) } } for (x = 0; x < y.length; x++) y[x] = a.create(r.extend(y[x], i)); if (c) + for (x = 0; x < y.length; x++) { var M = y[x]; for (h = x + 1; h < y.length; h++) { var k = y[h]; if (s.overlaps(M.bounds, k.bounds)) { var _ = M.vertices, + I = k.vertices; for (b = 0; b < M.vertices.length; b++) + for (w = 0; w < k.vertices.length; w++) { var T = l.magnitudeSquared(l.sub(_[(b + 1) % _.length], I[w])), + R = l.magnitudeSquared(l.sub(_[b], I[(w + 1) % I.length])); + T < 5 && R < 5 && (_[b].isInternal = !0, I[w].isInternal = !0) } } } } + return y.length > 1 ? (v = a.create(r.extend({ parts: y.slice(0) }, i)), a.setPosition(v, { x: e, y: t }), v) : y[0] } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(0); + i.create = function(e) { var t = {}; return e || o.log("Mouse.create: element was undefined, defaulting to document.body", "warn"), t.element = e || document.body, t.absolute = { x: 0, y: 0 }, t.position = { x: 0, y: 0 }, t.mousedownPosition = { x: 0, y: 0 }, t.mouseupPosition = { x: 0, y: 0 }, t.offset = { x: 0, y: 0 }, t.scale = { x: 1, y: 1 }, t.wheelDelta = 0, t.button = -1, t.pixelRatio = parseInt(t.element.getAttribute("data-pixel-ratio"), 10) || 1, t.sourceEvents = { mousemove: null, mousedown: null, mouseup: null, mousewheel: null }, t.mousemove = function(e) { var n = i._getRelativeMousePosition(e, t.element, t.pixelRatio); + e.changedTouches && (t.button = 0, e.preventDefault()), t.absolute.x = n.x, t.absolute.y = n.y, t.position.x = t.absolute.x * t.scale.x + t.offset.x, t.position.y = t.absolute.y * t.scale.y + t.offset.y, t.sourceEvents.mousemove = e }, t.mousedown = function(e) { var n = i._getRelativeMousePosition(e, t.element, t.pixelRatio); + e.changedTouches ? (t.button = 0, e.preventDefault()) : t.button = e.button, t.absolute.x = n.x, t.absolute.y = n.y, t.position.x = t.absolute.x * t.scale.x + t.offset.x, t.position.y = t.absolute.y * t.scale.y + t.offset.y, t.mousedownPosition.x = t.position.x, t.mousedownPosition.y = t.position.y, t.sourceEvents.mousedown = e }, t.mouseup = function(e) { var n = i._getRelativeMousePosition(e, t.element, t.pixelRatio); + e.changedTouches && e.preventDefault(), t.button = -1, t.absolute.x = n.x, t.absolute.y = n.y, t.position.x = t.absolute.x * t.scale.x + t.offset.x, t.position.y = t.absolute.y * t.scale.y + t.offset.y, t.mouseupPosition.x = t.position.x, t.mouseupPosition.y = t.position.y, t.sourceEvents.mouseup = e }, t.mousewheel = function(e) { t.wheelDelta = Math.max(-1, Math.min(1, e.wheelDelta || -e.detail)), e.preventDefault() }, i.setElement(t, t.element), t }, i.setElement = function(e, t) { e.element = t, t.addEventListener("mousemove", e.mousemove), t.addEventListener("mousedown", e.mousedown), t.addEventListener("mouseup", e.mouseup), t.addEventListener("mousewheel", e.mousewheel), t.addEventListener("DOMMouseScroll", e.mousewheel), t.addEventListener("touchmove", e.mousemove), t.addEventListener("touchstart", e.mousedown), t.addEventListener("touchend", e.mouseup) }, i.clearSourceEvents = function(e) { e.sourceEvents.mousemove = null, e.sourceEvents.mousedown = null, e.sourceEvents.mouseup = null, e.sourceEvents.mousewheel = null, e.wheelDelta = 0 }, i.setOffset = function(e, t) { e.offset.x = t.x, e.offset.y = t.y, e.position.x = e.absolute.x * e.scale.x + e.offset.x, e.position.y = e.absolute.y * e.scale.y + e.offset.y }, i.setScale = function(e, t) { e.scale.x = t.x, e.scale.y = t.y, e.position.x = e.absolute.x * e.scale.x + e.offset.x, e.position.y = e.absolute.y * e.scale.y + e.offset.y }, i._getRelativeMousePosition = function(e, t, n) { var i, o, r = t.getBoundingClientRect(), + a = document.documentElement || document.body.parentNode || document.body, + s = void 0 !== window.pageXOffset ? window.pageXOffset : a.scrollLeft, + l = void 0 !== window.pageYOffset ? window.pageYOffset : a.scrollTop, + c = e.changedTouches; return c ? (i = c[0].pageX - r.left - s, o = c[0].pageY - r.top - l) : (i = e.pageX - r.left - s, o = e.pageY - r.top - l), { x: i / (t.clientWidth / (t.width || t.clientWidth) * n), y: o / (t.clientHeight / (t.height || t.clientHeight) * n) } } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(0), + r = n(8); + i.create = function(e) { return o.extend({ bodies: [], pairs: null }, e) }, i.setBodies = function(e, t) { e.bodies = t.slice(0) }, i.clear = function(e) { e.bodies = [] }, i.collisions = function(e) { var t, n, o = [], + a = e.pairs, + s = e.bodies, + l = s.length, + c = i.canCollide, + u = r.collides; for (s.sort(i._compareBoundsX), t = 0; t < l; t++) { var d = s[t], + p = d.bounds, + f = d.bounds.max.x, + v = d.bounds.max.y, + y = d.bounds.min.y, + m = d.isStatic || d.isSleeping, + g = d.parts.length, + x = 1 === g; for (n = t + 1; n < l; n++) { var h = s[n]; if ((M = h.bounds).min.x > f) break; if (!(v < M.min.y || y > M.max.y) && (!m || !h.isStatic && !h.isSleeping) && c(d.collisionFilter, h.collisionFilter)) { var b = h.parts.length; if (x && 1 === b)(C = u(d, h, a)) && o.push(C); + else + for (var S = b > 1 ? 1 : 0, w = g > 1 ? 1 : 0; w < g; w++) + for (var A = d.parts[w], P = (p = A.bounds, S); P < b; P++) { var C, B = h.parts[P], + M = B.bounds; + p.min.x > M.max.x || p.max.x < M.min.x || p.max.y < M.min.y || p.min.y > M.max.y || (C = u(A, B, a)) && o.push(C) } } } } return o }, i.canCollide = function(e, t) { return e.group === t.group && 0 !== e.group ? e.group > 0 : 0 != (e.mask & t.category) && 0 != (t.mask & e.category) }, i._compareBoundsX = function(e, t) { return e.bounds.min.x - t.bounds.min.x } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(0); + i._registry = {}, i.register = function(e) { if (i.isPlugin(e) || o.warn("Plugin.register:", i.toString(e), "does not implement all required fields."), e.name in i._registry) { var t = i._registry[e.name], + n = i.versionParse(e.version).number, + r = i.versionParse(t.version).number; + n > r ? (o.warn("Plugin.register:", i.toString(t), "was upgraded to", i.toString(e)), i._registry[e.name] = e) : n < r ? o.warn("Plugin.register:", i.toString(t), "can not be downgraded to", i.toString(e)) : e !== t && o.warn("Plugin.register:", i.toString(e), "is already registered to different plugin object") } else i._registry[e.name] = e; return e }, i.resolve = function(e) { return i._registry[i.dependencyParse(e).name] }, i.toString = function(e) { return "string" == typeof e ? e : (e.name || "anonymous") + "@" + (e.version || e.range || "0.0.0") }, i.isPlugin = function(e) { return e && e.name && e.version && e.install }, i.isUsed = function(e, t) { return e.used.indexOf(t) > -1 }, i.isFor = function(e, t) { var n = e.for && i.dependencyParse(e.for); return !e.for || t.name === n.name && i.versionSatisfies(t.version, n.range) }, i.use = function(e, t) { if (e.uses = (e.uses || []).concat(t || []), 0 !== e.uses.length) { for (var n = i.dependencies(e), r = o.topologicalSort(n), a = [], s = 0; s < r.length; s += 1) + if (r[s] !== e.name) { var l = i.resolve(r[s]); + l ? i.isUsed(e, l.name) || (i.isFor(l, e) || (o.warn("Plugin.use:", i.toString(l), "is for", l.for, "but installed on", i.toString(e) + "."), l._warned = !0), l.install ? l.install(e) : (o.warn("Plugin.use:", i.toString(l), "does not specify an install function."), l._warned = !0), l._warned ? (a.push("🔶 " + i.toString(l)), delete l._warned) : a.push("✅ " + i.toString(l)), e.used.push(l.name)) : a.push("❌ " + r[s]) } a.length > 0 && o.info(a.join(" ")) } else o.warn("Plugin.use:", i.toString(e), "does not specify any dependencies to install.") }, i.dependencies = function(e, t) { var n = i.dependencyParse(e), + r = n.name; if (!(r in (t = t || {}))) { e = i.resolve(e) || e, t[r] = o.map(e.uses || [], (function(t) { i.isPlugin(t) && i.register(t); var r = i.dependencyParse(t), + a = i.resolve(t); return a && !i.versionSatisfies(a.version, r.range) ? (o.warn("Plugin.dependencies:", i.toString(a), "does not satisfy", i.toString(r), "used by", i.toString(n) + "."), a._warned = !0, e._warned = !0) : a || (o.warn("Plugin.dependencies:", i.toString(t), "used by", i.toString(n), "could not be resolved."), e._warned = !0), r.name })); for (var a = 0; a < t[r].length; a += 1) i.dependencies(t[r][a], t); return t } }, i.dependencyParse = function(e) { return o.isString(e) ? (/^[\w-]+(@(\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-+]+)?))?$/.test(e) || o.warn("Plugin.dependencyParse:", e, "is not a valid dependency string."), { name: e.split("@")[0], range: e.split("@")[1] || "*" }) : { name: e.name, range: e.range || e.version } }, i.versionParse = function(e) { var t = /^(\*)|(\^|~|>=|>)?\s*((\d+)\.(\d+)\.(\d+))(-[0-9A-Za-z-+]+)?$/; + t.test(e) || o.warn("Plugin.versionParse:", e, "is not a valid version or range."); var n = t.exec(e), + i = Number(n[4]), + r = Number(n[5]), + a = Number(n[6]); return { isRange: Boolean(n[1] || n[2]), version: n[3], range: e, operator: n[1] || n[2] || "", major: i, minor: r, patch: a, parts: [i, r, a], prerelease: n[7], number: 1e8 * i + 1e4 * r + a } }, i.versionSatisfies = function(e, t) { t = t || "*"; var n = i.versionParse(t), + o = i.versionParse(e); if (n.isRange) { if ("*" === n.operator || "*" === e) return !0; if (">" === n.operator) return o.number > n.number; if (">=" === n.operator) return o.number >= n.number; if ("~" === n.operator) return o.major === n.major && o.minor === n.minor && o.patch >= n.patch; if ("^" === n.operator) return n.major > 0 ? o.major === n.major && o.number >= n.number : n.minor > 0 ? o.minor === n.minor && o.patch >= n.patch : o.patch === n.patch } return e === t || "*" === e } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(0), + r = n(5), + a = n(1), + s = n(4), + l = n(2), + c = n(13);! function() { var e, t; "undefined" != typeof window && (e = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || function(e) { window.setTimeout((function() { e(o.now()) }), 1e3 / 60) }, t = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame), i._goodFps = 30, i._goodDelta = 1e3 / 60, i.create = function(e) { var t = { engine: null, element: null, canvas: null, mouse: null, frameRequestId: null, timing: { historySize: 60, delta: 0, deltaHistory: [], lastTime: 0, lastTimestamp: 0, lastElapsed: 0, timestampElapsed: 0, timestampElapsedHistory: [], engineDeltaHistory: [], engineElapsedHistory: [], elapsedHistory: [] }, options: { width: 800, height: 600, pixelRatio: 1, background: "#14151f", wireframeBackground: "#14151f", hasBounds: !!e.bounds, enabled: !0, wireframes: !0, showSleeping: !0, showDebug: !1, showStats: !1, showPerformance: !1, showBounds: !1, showVelocity: !1, showCollisions: !1, showSeparations: !1, showAxes: !1, showPositions: !1, showAngleIndicator: !1, showIds: !1, showVertexNumbers: !1, showConvexHulls: !1, showInternalEdges: !1, showMousePosition: !1 } }, + n = o.extend(t, e); return n.canvas && (n.canvas.width = n.options.width || n.canvas.width, n.canvas.height = n.options.height || n.canvas.height), n.mouse = e.mouse, n.engine = e.engine, n.canvas = n.canvas || d(n.options.width, n.options.height), n.context = n.canvas.getContext("2d"), n.textures = {}, n.bounds = n.bounds || { min: { x: 0, y: 0 }, max: { x: n.canvas.width, y: n.canvas.height } }, n.controller = i, n.options.showBroadphase = !1, 1 !== n.options.pixelRatio && i.setPixelRatio(n, n.options.pixelRatio), o.isElement(n.element) && n.element.appendChild(n.canvas), n }, i.run = function(t) {! function o(r) { t.frameRequestId = e(o), n(t, r), i.world(t, r), (t.options.showStats || t.options.showDebug) && i.stats(t, t.context, r), (t.options.showPerformance || t.options.showDebug) && i.performance(t, t.context, r) }() }, i.stop = function(e) { t(e.frameRequestId) }, i.setPixelRatio = function(e, t) { var n = e.options, + i = e.canvas; "auto" === t && (t = p(i)), n.pixelRatio = t, i.setAttribute("data-pixel-ratio", t), i.width = n.width * t, i.height = n.height * t, i.style.width = n.width + "px", i.style.height = n.height + "px" }, i.lookAt = function(e, t, n, i) { i = void 0 === i || i, t = o.isArray(t) ? t : [t], n = n || { x: 0, y: 0 }; for (var r = { min: { x: 1 / 0, y: 1 / 0 }, max: { x: -1 / 0, y: -1 / 0 } }, a = 0; a < t.length; a += 1) { var s = t[a], + l = s.bounds ? s.bounds.min : s.min || s.position || s, + u = s.bounds ? s.bounds.max : s.max || s.position || s; + l && u && (l.x < r.min.x && (r.min.x = l.x), u.x > r.max.x && (r.max.x = u.x), l.y < r.min.y && (r.min.y = l.y), u.y > r.max.y && (r.max.y = u.y)) } var d = r.max.x - r.min.x + 2 * n.x, + p = r.max.y - r.min.y + 2 * n.y, + f = e.canvas.height, + v = e.canvas.width / f, + y = d / p, + m = 1, + g = 1; + y > v ? g = y / v : m = v / y, e.options.hasBounds = !0, e.bounds.min.x = r.min.x, e.bounds.max.x = r.min.x + d * m, e.bounds.min.y = r.min.y, e.bounds.max.y = r.min.y + p * g, i && (e.bounds.min.x += .5 * d - d * m * .5, e.bounds.max.x += .5 * d - d * m * .5, e.bounds.min.y += .5 * p - p * g * .5, e.bounds.max.y += .5 * p - p * g * .5), e.bounds.min.x -= n.x, e.bounds.max.x -= n.x, e.bounds.min.y -= n.y, e.bounds.max.y -= n.y, e.mouse && (c.setScale(e.mouse, { x: (e.bounds.max.x - e.bounds.min.x) / e.canvas.width, y: (e.bounds.max.y - e.bounds.min.y) / e.canvas.height }), c.setOffset(e.mouse, e.bounds.min)) }, i.startViewTransform = function(e) { var t = e.bounds.max.x - e.bounds.min.x, + n = e.bounds.max.y - e.bounds.min.y, + i = t / e.options.width, + o = n / e.options.height; + e.context.setTransform(e.options.pixelRatio / i, 0, 0, e.options.pixelRatio / o, 0, 0), e.context.translate(-e.bounds.min.x, -e.bounds.min.y) }, i.endViewTransform = function(e) { e.context.setTransform(e.options.pixelRatio, 0, 0, e.options.pixelRatio, 0, 0) }, i.world = function(e, t) { var n, u = o.now(), + d = e.engine, + p = d.world, + f = e.canvas, + y = e.context, + m = e.options, + g = e.timing, + x = r.allBodies(p), + h = r.allConstraints(p), + b = m.wireframes ? m.wireframeBackground : m.background, + S = [], + w = [], + A = { timestamp: d.timing.timestamp }; if (s.trigger(e, "beforeRender", A), e.currentBackground !== b && v(e, b), y.globalCompositeOperation = "source-in", y.fillStyle = "transparent", y.fillRect(0, 0, f.width, f.height), y.globalCompositeOperation = "source-over", m.hasBounds) { for (n = 0; n < x.length; n++) { var P = x[n]; + a.overlaps(P.bounds, e.bounds) && S.push(P) } for (n = 0; n < h.length; n++) { var C = h[n], + B = C.bodyA, + M = C.bodyB, + k = C.pointA, + _ = C.pointB; + B && (k = l.add(B.position, C.pointA)), M && (_ = l.add(M.position, C.pointB)), k && _ && ((a.contains(e.bounds, k) || a.contains(e.bounds, _)) && w.push(C)) } i.startViewTransform(e), e.mouse && (c.setScale(e.mouse, { x: (e.bounds.max.x - e.bounds.min.x) / e.options.width, y: (e.bounds.max.y - e.bounds.min.y) / e.options.height }), c.setOffset(e.mouse, e.bounds.min)) } else w = h, S = x, 1 !== e.options.pixelRatio && e.context.setTransform(e.options.pixelRatio, 0, 0, e.options.pixelRatio, 0, 0);!m.wireframes || d.enableSleeping && m.showSleeping ? i.bodies(e, S, y) : (m.showConvexHulls && i.bodyConvexHulls(e, S, y), i.bodyWireframes(e, S, y)), m.showBounds && i.bodyBounds(e, S, y), (m.showAxes || m.showAngleIndicator) && i.bodyAxes(e, S, y), m.showPositions && i.bodyPositions(e, S, y), m.showVelocity && i.bodyVelocity(e, S, y), m.showIds && i.bodyIds(e, S, y), m.showSeparations && i.separations(e, d.pairs.list, y), m.showCollisions && i.collisions(e, d.pairs.list, y), m.showVertexNumbers && i.vertexNumbers(e, S, y), m.showMousePosition && i.mousePosition(e, e.mouse, y), i.constraints(w, y), m.hasBounds && i.endViewTransform(e), s.trigger(e, "afterRender", A), g.lastElapsed = o.now() - u }, i.stats = function(e, t, n) { for (var i = e.engine, o = i.world, a = r.allBodies(o), s = 0, l = 0, c = 0; c < a.length; c += 1) s += a[c].parts.length; var u = { Part: s, Body: a.length, Cons: r.allConstraints(o).length, Comp: r.allComposites(o).length, Pair: i.pairs.list.length }; for (var d in t.fillStyle = "#0e0f19", t.fillRect(l, 0, 302.5, 44), t.font = "12px Arial", t.textBaseline = "top", t.textAlign = "right", u) { var p = u[d]; + t.fillStyle = "#aaa", t.fillText(d, l + 55, 8), t.fillStyle = "#eee", t.fillText(p, l + 55, 26), l += 55 } }, i.performance = function(e, t) { var n = e.engine, + o = e.timing, + r = o.deltaHistory, + a = o.elapsedHistory, + s = o.timestampElapsedHistory, + l = o.engineDeltaHistory, + c = o.engineElapsedHistory, + d = n.timing.lastDelta, + p = u(r), + f = u(a), + v = u(l), + y = u(c), + m = u(s) / p || 0, + g = 1e3 / p || 0; + t.fillStyle = "#0e0f19", t.fillRect(0, 50, 370, 34), i.status(t, 10, 69, 60, 4, r.length, Math.round(g) + " fps", g / i._goodFps, (function(e) { return r[e] / p - 1 })), i.status(t, 82, 69, 60, 4, l.length, d.toFixed(2) + " dt", i._goodDelta / d, (function(e) { return l[e] / v - 1 })), i.status(t, 154, 69, 60, 4, c.length, y.toFixed(2) + " ut", 1 - y / i._goodFps, (function(e) { return c[e] / y - 1 })), i.status(t, 226, 69, 60, 4, a.length, f.toFixed(2) + " rt", 1 - f / i._goodFps, (function(e) { return a[e] / f - 1 })), i.status(t, 298, 69, 60, 4, s.length, m.toFixed(2) + " x", m * m * m, (function(e) { return (s[e] / r[e] / m || 0) - 1 })) }, i.status = function(e, t, n, i, r, a, s, l, c) { e.strokeStyle = "#888", e.fillStyle = "#444", e.lineWidth = 1, e.fillRect(t, n + 7, i, 1), e.beginPath(), e.moveTo(t, n + 7 - r * o.clamp(.4 * c(0), -2, 2)); for (var u = 0; u < i; u += 1) e.lineTo(t + u, n + 7 - (u < a ? r * o.clamp(.4 * c(u), -2, 2) : 0)); + e.stroke(), e.fillStyle = "hsl(" + o.clamp(25 + 95 * l, 0, 120) + ",100%,60%)", e.fillRect(t, n - 7, 4, 4), e.font = "12px Arial", e.textBaseline = "middle", e.textAlign = "right", e.fillStyle = "#eee", e.fillText(s, t + i, n - 5) }, i.constraints = function(e, t) { for (var n = t, i = 0; i < e.length; i++) { var r = e[i]; if (r.render.visible && r.pointA && r.pointB) { var a, s, c = r.bodyA, + u = r.bodyB; if (a = c ? l.add(c.position, r.pointA) : r.pointA, "pin" === r.render.type) n.beginPath(), n.arc(a.x, a.y, 3, 0, 2 * Math.PI), n.closePath(); + else { if (s = u ? l.add(u.position, r.pointB) : r.pointB, n.beginPath(), n.moveTo(a.x, a.y), "spring" === r.render.type) + for (var d, p = l.sub(s, a), f = l.perp(l.normalise(p)), v = Math.ceil(o.clamp(r.length / 5, 12, 20)), y = 1; y < v; y += 1) d = y % 2 == 0 ? 1 : -1, n.lineTo(a.x + p.x * (y / v) + f.x * d * 4, a.y + p.y * (y / v) + f.y * d * 4); + n.lineTo(s.x, s.y) } r.render.lineWidth && (n.lineWidth = r.render.lineWidth, n.strokeStyle = r.render.strokeStyle, n.stroke()), r.render.anchors && (n.fillStyle = r.render.strokeStyle, n.beginPath(), n.arc(a.x, a.y, 3, 0, 2 * Math.PI), n.arc(s.x, s.y, 3, 0, 2 * Math.PI), n.closePath(), n.fill()) } } }, i.bodies = function(e, t, n) { var i, o, r, a, s = n, + l = (e.engine, e.options), + c = l.showInternalEdges || !l.wireframes; for (r = 0; r < t.length; r++) + if ((i = t[r]).render.visible) + for (a = i.parts.length > 1 ? 1 : 0; a < i.parts.length; a++) + if ((o = i.parts[a]).render.visible) { if (l.showSleeping && i.isSleeping ? s.globalAlpha = .5 * o.render.opacity : 1 !== o.render.opacity && (s.globalAlpha = o.render.opacity), o.render.sprite && o.render.sprite.texture && !l.wireframes) { var u = o.render.sprite, + d = f(e, u.texture); + s.translate(o.position.x, o.position.y), s.rotate(o.angle), s.drawImage(d, d.width * -u.xOffset * u.xScale, d.height * -u.yOffset * u.yScale, d.width * u.xScale, d.height * u.yScale), s.rotate(-o.angle), s.translate(-o.position.x, -o.position.y) } else { if (o.circleRadius) s.beginPath(), s.arc(o.position.x, o.position.y, o.circleRadius, 0, 2 * Math.PI); + else { s.beginPath(), s.moveTo(o.vertices[0].x, o.vertices[0].y); for (var p = 1; p < o.vertices.length; p++) !o.vertices[p - 1].isInternal || c ? s.lineTo(o.vertices[p].x, o.vertices[p].y) : s.moveTo(o.vertices[p].x, o.vertices[p].y), o.vertices[p].isInternal && !c && s.moveTo(o.vertices[(p + 1) % o.vertices.length].x, o.vertices[(p + 1) % o.vertices.length].y); + s.lineTo(o.vertices[0].x, o.vertices[0].y), s.closePath() } l.wireframes ? (s.lineWidth = 1, s.strokeStyle = "#bbb", s.stroke()) : (s.fillStyle = o.render.fillStyle, o.render.lineWidth && (s.lineWidth = o.render.lineWidth, s.strokeStyle = o.render.strokeStyle, s.stroke()), s.fill()) } s.globalAlpha = 1 } }, i.bodyWireframes = function(e, t, n) { var i, o, r, a, s, l = n, + c = e.options.showInternalEdges; for (l.beginPath(), r = 0; r < t.length; r++) + if ((i = t[r]).render.visible) + for (s = i.parts.length > 1 ? 1 : 0; s < i.parts.length; s++) { for (o = i.parts[s], l.moveTo(o.vertices[0].x, o.vertices[0].y), a = 1; a < o.vertices.length; a++) !o.vertices[a - 1].isInternal || c ? l.lineTo(o.vertices[a].x, o.vertices[a].y) : l.moveTo(o.vertices[a].x, o.vertices[a].y), o.vertices[a].isInternal && !c && l.moveTo(o.vertices[(a + 1) % o.vertices.length].x, o.vertices[(a + 1) % o.vertices.length].y); + l.lineTo(o.vertices[0].x, o.vertices[0].y) } l.lineWidth = 1, l.strokeStyle = "#bbb", l.stroke() }, i.bodyConvexHulls = function(e, t, n) { var i, o, r, a = n; for (a.beginPath(), o = 0; o < t.length; o++) + if ((i = t[o]).render.visible && 1 !== i.parts.length) { for (a.moveTo(i.vertices[0].x, i.vertices[0].y), r = 1; r < i.vertices.length; r++) a.lineTo(i.vertices[r].x, i.vertices[r].y); + a.lineTo(i.vertices[0].x, i.vertices[0].y) } a.lineWidth = 1, a.strokeStyle = "rgba(255,255,255,0.2)", a.stroke() }, i.vertexNumbers = function(e, t, n) { var i, o, r, a = n; for (i = 0; i < t.length; i++) { var s = t[i].parts; for (r = s.length > 1 ? 1 : 0; r < s.length; r++) { var l = s[r]; for (o = 0; o < l.vertices.length; o++) a.fillStyle = "rgba(255,255,255,0.2)", a.fillText(i + "_" + o, l.position.x + .8 * (l.vertices[o].x - l.position.x), l.position.y + .8 * (l.vertices[o].y - l.position.y)) } } }, i.mousePosition = function(e, t, n) { var i = n; + i.fillStyle = "rgba(255,255,255,0.8)", i.fillText(t.position.x + " " + t.position.y, t.position.x + 5, t.position.y - 5) }, i.bodyBounds = function(e, t, n) { var i = n, + o = (e.engine, e.options); + i.beginPath(); for (var r = 0; r < t.length; r++) { if (t[r].render.visible) + for (var a = t[r].parts, s = a.length > 1 ? 1 : 0; s < a.length; s++) { var l = a[s]; + i.rect(l.bounds.min.x, l.bounds.min.y, l.bounds.max.x - l.bounds.min.x, l.bounds.max.y - l.bounds.min.y) } } o.wireframes ? i.strokeStyle = "rgba(255,255,255,0.08)" : i.strokeStyle = "rgba(0,0,0,0.1)", i.lineWidth = 1, i.stroke() }, i.bodyAxes = function(e, t, n) { var i, o, r, a, s = n, + l = (e.engine, e.options); for (s.beginPath(), o = 0; o < t.length; o++) { var c = t[o], + u = c.parts; if (c.render.visible) + if (l.showAxes) + for (r = u.length > 1 ? 1 : 0; r < u.length; r++) + for (i = u[r], a = 0; a < i.axes.length; a++) { var d = i.axes[a]; + s.moveTo(i.position.x, i.position.y), s.lineTo(i.position.x + 20 * d.x, i.position.y + 20 * d.y) } else + for (r = u.length > 1 ? 1 : 0; r < u.length; r++) + for (i = u[r], a = 0; a < i.axes.length; a++) s.moveTo(i.position.x, i.position.y), s.lineTo((i.vertices[0].x + i.vertices[i.vertices.length - 1].x) / 2, (i.vertices[0].y + i.vertices[i.vertices.length - 1].y) / 2) } l.wireframes ? (s.strokeStyle = "indianred", s.lineWidth = 1) : (s.strokeStyle = "rgba(255, 255, 255, 0.4)", s.globalCompositeOperation = "overlay", s.lineWidth = 2), s.stroke(), s.globalCompositeOperation = "source-over" }, i.bodyPositions = function(e, t, n) { var i, o, r, a, s = n, + l = (e.engine, e.options); for (s.beginPath(), r = 0; r < t.length; r++) + if ((i = t[r]).render.visible) + for (a = 0; a < i.parts.length; a++) o = i.parts[a], s.arc(o.position.x, o.position.y, 3, 0, 2 * Math.PI, !1), s.closePath(); for (l.wireframes ? s.fillStyle = "indianred" : s.fillStyle = "rgba(0,0,0,0.5)", s.fill(), s.beginPath(), r = 0; r < t.length; r++)(i = t[r]).render.visible && (s.arc(i.positionPrev.x, i.positionPrev.y, 2, 0, 2 * Math.PI, !1), s.closePath()); + s.fillStyle = "rgba(255,165,0,0.8)", s.fill() }, i.bodyVelocity = function(e, t, n) { var i = n; + i.beginPath(); for (var o = 0; o < t.length; o++) { var r = t[o]; + r.render.visible && (i.moveTo(r.position.x, r.position.y), i.lineTo(r.position.x + 2 * (r.position.x - r.positionPrev.x), r.position.y + 2 * (r.position.y - r.positionPrev.y))) } i.lineWidth = 3, i.strokeStyle = "cornflowerblue", i.stroke() }, i.bodyIds = function(e, t, n) { var i, o, r = n; for (i = 0; i < t.length; i++) + if (t[i].render.visible) { var a = t[i].parts; for (o = a.length > 1 ? 1 : 0; o < a.length; o++) { var s = a[o]; + r.font = "12px Arial", r.fillStyle = "rgba(255,255,255,0.5)", r.fillText(s.id, s.position.x + 10, s.position.y - 10) } } }, i.collisions = function(e, t, n) { var i, o, r, a, s = n, + l = e.options; for (s.beginPath(), r = 0; r < t.length; r++) + if ((i = t[r]).isActive) + for (o = i.collision, a = 0; a < i.activeContacts.length; a++) { var c = i.activeContacts[a].vertex; + s.rect(c.x - 1.5, c.y - 1.5, 3.5, 3.5) } + for (l.wireframes ? s.fillStyle = "rgba(255,255,255,0.7)" : s.fillStyle = "orange", s.fill(), s.beginPath(), r = 0; r < t.length; r++) + if ((i = t[r]).isActive && (o = i.collision, i.activeContacts.length > 0)) { var u = i.activeContacts[0].vertex.x, + d = i.activeContacts[0].vertex.y; + 2 === i.activeContacts.length && (u = (i.activeContacts[0].vertex.x + i.activeContacts[1].vertex.x) / 2, d = (i.activeContacts[0].vertex.y + i.activeContacts[1].vertex.y) / 2), o.bodyB === o.supports[0].body || !0 === o.bodyA.isStatic ? s.moveTo(u - 8 * o.normal.x, d - 8 * o.normal.y) : s.moveTo(u + 8 * o.normal.x, d + 8 * o.normal.y), s.lineTo(u, d) } l.wireframes ? s.strokeStyle = "rgba(255,165,0,0.7)" : s.strokeStyle = "orange", s.lineWidth = 1, s.stroke() }, i.separations = function(e, t, n) { var i, o, r, a, s, l = n, + c = e.options; for (l.beginPath(), s = 0; s < t.length; s++) + if ((i = t[s]).isActive) { r = (o = i.collision).bodyA; var u = 1; + (a = o.bodyB).isStatic || r.isStatic || (u = .5), a.isStatic && (u = 0), l.moveTo(a.position.x, a.position.y), l.lineTo(a.position.x - o.penetration.x * u, a.position.y - o.penetration.y * u), u = 1, a.isStatic || r.isStatic || (u = .5), r.isStatic && (u = 0), l.moveTo(r.position.x, r.position.y), l.lineTo(r.position.x + o.penetration.x * u, r.position.y + o.penetration.y * u) } c.wireframes ? l.strokeStyle = "rgba(255,165,0,0.5)" : l.strokeStyle = "orange", l.stroke() }, i.inspector = function(e, t) { e.engine; var n, i = e.selected, + o = e.render, + r = o.options; if (r.hasBounds) { var a = o.bounds.max.x - o.bounds.min.x, + s = o.bounds.max.y - o.bounds.min.y, + l = a / o.options.width, + c = s / o.options.height; + t.scale(1 / l, 1 / c), t.translate(-o.bounds.min.x, -o.bounds.min.y) } for (var u = 0; u < i.length; u++) { var d = i[u].data; switch (t.translate(.5, .5), t.lineWidth = 1, t.strokeStyle = "rgba(255,165,0,0.9)", t.setLineDash([1, 2]), d.type) { + case "body": + n = d.bounds, t.beginPath(), t.rect(Math.floor(n.min.x - 3), Math.floor(n.min.y - 3), Math.floor(n.max.x - n.min.x + 6), Math.floor(n.max.y - n.min.y + 6)), t.closePath(), t.stroke(); break; + case "constraint": + var p = d.pointA; + d.bodyA && (p = d.pointB), t.beginPath(), t.arc(p.x, p.y, 10, 0, 2 * Math.PI), t.closePath(), t.stroke() } t.setLineDash([]), t.translate(-.5, -.5) } null !== e.selectStart && (t.translate(.5, .5), t.lineWidth = 1, t.strokeStyle = "rgba(255,165,0,0.6)", t.fillStyle = "rgba(255,165,0,0.1)", n = e.selectBounds, t.beginPath(), t.rect(Math.floor(n.min.x), Math.floor(n.min.y), Math.floor(n.max.x - n.min.x), Math.floor(n.max.y - n.min.y)), t.closePath(), t.stroke(), t.fill(), t.translate(-.5, -.5)), r.hasBounds && t.setTransform(1, 0, 0, 1, 0, 0) }; var n = function(e, t) { var n = e.engine, + o = e.timing, + r = o.historySize, + a = n.timing.timestamp; + o.delta = t - o.lastTime || i._goodDelta, o.lastTime = t, o.timestampElapsed = a - o.lastTimestamp || 0, o.lastTimestamp = a, o.deltaHistory.unshift(o.delta), o.deltaHistory.length = Math.min(o.deltaHistory.length, r), o.engineDeltaHistory.unshift(n.timing.lastDelta), o.engineDeltaHistory.length = Math.min(o.engineDeltaHistory.length, r), o.timestampElapsedHistory.unshift(o.timestampElapsed), o.timestampElapsedHistory.length = Math.min(o.timestampElapsedHistory.length, r), o.engineElapsedHistory.unshift(n.timing.lastElapsed), o.engineElapsedHistory.length = Math.min(o.engineElapsedHistory.length, r), o.elapsedHistory.unshift(o.lastElapsed), o.elapsedHistory.length = Math.min(o.elapsedHistory.length, r) }, + u = function(e) { for (var t = 0, n = 0; n < e.length; n += 1) t += e[n]; return t / e.length || 0 }, + d = function(e, t) { var n = document.createElement("canvas"); return n.width = e, n.height = t, n.oncontextmenu = function() { return !1 }, n.onselectstart = function() { return !1 }, n }, + p = function(e) { var t = e.getContext("2d"); return (window.devicePixelRatio || 1) / (t.webkitBackingStorePixelRatio || t.mozBackingStorePixelRatio || t.msBackingStorePixelRatio || t.oBackingStorePixelRatio || t.backingStorePixelRatio || 1) }, + f = function(e, t) { var n = e.textures[t]; return n || ((n = e.textures[t] = new Image).src = t, n) }, + v = function(e, t) { var n = t; /(jpg|gif|png)$/.test(t) && (n = "url(" + t + ")"), e.canvas.style.background = n, e.canvas.style.backgroundSize = "contain", e.currentBackground = t } }() }, function(e, t) { var n = {}; + e.exports = n, n.create = function(e) { return { vertex: e, normalImpulse: 0, tangentImpulse: 0 } } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(7), + r = n(19), + a = n(14), + s = n(20), + l = n(4), + c = n(5), + u = n(10), + d = n(0), + p = n(6); + i.create = function(e) { e = e || {}; var t = d.extend({ positionIterations: 6, velocityIterations: 4, constraintIterations: 2, enableSleeping: !1, events: [], plugin: {}, gravity: { x: 0, y: 1, scale: .001 }, timing: { timestamp: 0, timeScale: 1, lastDelta: 0, lastElapsed: 0 } }, e); return t.world = e.world || c.create({ label: "World" }), t.pairs = e.pairs || s.create(), t.detector = e.detector || a.create(), t.grid = { buckets: [] }, t.world.gravity = t.gravity, t.broadphase = t.grid, t.metrics = {}, t }, i.update = function(e, t, n) { var p = d.now(); + t = t || 1e3 / 60, n = n || 1; var f, v = e.world, + y = e.detector, + m = e.pairs, + g = e.timing, + x = g.timestamp; + g.timestamp += t * g.timeScale, g.lastDelta = t * g.timeScale; var h = { timestamp: g.timestamp }; + l.trigger(e, "beforeUpdate", h); var b = c.allBodies(v), + S = c.allConstraints(v); for (v.isModified && a.setBodies(y, b), v.isModified && c.setModified(v, !1, !1, !0), e.enableSleeping && o.update(b, g.timeScale), i._bodiesApplyGravity(b, e.gravity), i._bodiesUpdate(b, t, g.timeScale, n, v.bounds), u.preSolveAll(b), f = 0; f < e.constraintIterations; f++) u.solveAll(S, g.timeScale); + u.postSolveAll(b), y.pairs = e.pairs; var w = a.collisions(y); for (s.update(m, w, x), e.enableSleeping && o.afterCollisions(m.list, g.timeScale), m.collisionStart.length > 0 && l.trigger(e, "collisionStart", { pairs: m.collisionStart }), r.preSolvePosition(m.list), f = 0; f < e.positionIterations; f++) r.solvePosition(m.list, g.timeScale); for (r.postSolvePosition(b), u.preSolveAll(b), f = 0; f < e.constraintIterations; f++) u.solveAll(S, g.timeScale); for (u.postSolveAll(b), r.preSolveVelocity(m.list), f = 0; f < e.velocityIterations; f++) r.solveVelocity(m.list, g.timeScale); return m.collisionActive.length > 0 && l.trigger(e, "collisionActive", { pairs: m.collisionActive }), m.collisionEnd.length > 0 && l.trigger(e, "collisionEnd", { pairs: m.collisionEnd }), i._bodiesClearForces(b), l.trigger(e, "afterUpdate", h), e.timing.lastElapsed = d.now() - p, e }, i.merge = function(e, t) { if (d.extend(e, t), t.world) { e.world = t.world, i.clear(e); for (var n = c.allBodies(e.world), r = 0; r < n.length; r++) { var a = n[r]; + o.set(a, !1), a.id = d.nextId() } } }, i.clear = function(e) { s.clear(e.pairs), a.clear(e.detector) }, i._bodiesClearForces = function(e) { for (var t = 0; t < e.length; t++) { var n = e[t]; + n.force.x = 0, n.force.y = 0, n.torque = 0 } }, i._bodiesApplyGravity = function(e, t) { var n = void 0 !== t.scale ? t.scale : .001; if ((0 !== t.x || 0 !== t.y) && 0 !== n) + for (var i = 0; i < e.length; i++) { var o = e[i]; + o.isStatic || o.isSleeping || (o.force.y += o.mass * t.y * n, o.force.x += o.mass * t.x * n) } }, i._bodiesUpdate = function(e, t, n, i, o) { for (var r = 0; r < e.length; r++) { var a = e[r]; + a.isStatic || a.isSleeping || p.update(a, t, n, i) } } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(3), + r = n(1); + i._restingThresh = 4, i._restingThreshTangent = 6, i._positionDampen = .9, i._positionWarming = .8, i._frictionNormalMultiplier = 5, i.preSolvePosition = function(e) { var t, n, i, o = e.length; for (t = 0; t < o; t++)(n = e[t]).isActive && (i = n.activeContacts.length, n.collision.parentA.totalContacts += i, n.collision.parentB.totalContacts += i) }, i.solvePosition = function(e, t) { var n, o, r, a, s, l, c, u, d = i._positionDampen, + p = e.length; for (n = 0; n < p; n++)(o = e[n]).isActive && !o.isSensor && (a = (r = o.collision).parentA, s = r.parentB, l = r.normal, o.separation = l.x * (s.positionImpulse.x + r.penetration.x - a.positionImpulse.x) + l.y * (s.positionImpulse.y + r.penetration.y - a.positionImpulse.y)); for (n = 0; n < p; n++)(o = e[n]).isActive && !o.isSensor && (a = (r = o.collision).parentA, s = r.parentB, l = r.normal, u = (o.separation - o.slop) * t, (a.isStatic || s.isStatic) && (u *= 2), a.isStatic || a.isSleeping || (c = d / a.totalContacts, a.positionImpulse.x += l.x * u * c, a.positionImpulse.y += l.y * u * c), s.isStatic || s.isSleeping || (c = d / s.totalContacts, s.positionImpulse.x -= l.x * u * c, s.positionImpulse.y -= l.y * u * c)) }, i.postSolvePosition = function(e) { for (var t = i._positionWarming, n = e.length, a = o.translate, s = r.update, l = 0; l < n; l++) { var c = e[l], + u = c.positionImpulse, + d = u.x, + p = u.y, + f = c.velocity; if (c.totalContacts = 0, 0 !== d || 0 !== p) { for (var v = 0; v < c.parts.length; v++) { var y = c.parts[v]; + a(y.vertices, u), s(y.bounds, y.vertices, f), y.position.x += d, y.position.y += p } c.positionPrev.x += d, c.positionPrev.y += p, d * f.x + p * f.y < 0 ? (u.x = 0, u.y = 0) : (u.x *= t, u.y *= t) } } }, i.preSolveVelocity = function(e) { var t, n, i = e.length; for (t = 0; t < i; t++) { var o = e[t]; if (o.isActive && !o.isSensor) { var r = o.activeContacts, + a = r.length, + s = o.collision, + l = s.parentA, + c = s.parentB, + u = s.normal, + d = s.tangent; for (n = 0; n < a; n++) { var p = r[n], + f = p.vertex, + v = p.normalImpulse, + y = p.tangentImpulse; if (0 !== v || 0 !== y) { var m = u.x * v + d.x * y, + g = u.y * v + d.y * y; + l.isStatic || l.isSleeping || (l.positionPrev.x += m * l.inverseMass, l.positionPrev.y += g * l.inverseMass, l.anglePrev += l.inverseInertia * ((f.x - l.position.x) * g - (f.y - l.position.y) * m)), c.isStatic || c.isSleeping || (c.positionPrev.x -= m * c.inverseMass, c.positionPrev.y -= g * c.inverseMass, c.anglePrev -= c.inverseInertia * ((f.x - c.position.x) * g - (f.y - c.position.y) * m)) } } } } }, i.solveVelocity = function(e, t) { var n, o, r, a, s = t * t, + l = i._restingThresh * s, + c = i._frictionNormalMultiplier, + u = i._restingThreshTangent * s, + d = Number.MAX_VALUE, + p = e.length; for (r = 0; r < p; r++) { var f = e[r]; if (f.isActive && !f.isSensor) { var v = f.collision, + y = v.parentA, + m = v.parentB, + g = y.velocity, + x = m.velocity, + h = v.normal.x, + b = v.normal.y, + S = v.tangent.x, + w = v.tangent.y, + A = f.activeContacts, + P = A.length, + C = 1 / P, + B = y.inverseMass + m.inverseMass, + M = f.friction * f.frictionStatic * c * s; for (g.x = y.position.x - y.positionPrev.x, g.y = y.position.y - y.positionPrev.y, x.x = m.position.x - m.positionPrev.x, x.y = m.position.y - m.positionPrev.y, y.angularVelocity = y.angle - y.anglePrev, m.angularVelocity = m.angle - m.anglePrev, a = 0; a < P; a++) { var k = A[a], + _ = k.vertex, + I = _.x - y.position.x, + T = _.y - y.position.y, + R = _.x - m.position.x, + E = _.y - m.position.y, + V = g.x - T * y.angularVelocity, + L = g.y + I * y.angularVelocity, + O = V - (x.x - E * m.angularVelocity), + D = L - (x.y + R * m.angularVelocity), + F = h * O + b * D, + H = S * O + w * D, + j = f.separation + F, + q = Math.min(j, 1), + W = (q = j < 0 ? 0 : q) * M; + H > W || -H > W ? (o = H > 0 ? H : -H, (n = f.friction * (H > 0 ? 1 : -1) * s) < -o ? n = -o : n > o && (n = o)) : (n = H, o = d); var G = I * b - T * h, + N = R * b - E * h, + U = C / (B + y.inverseInertia * G * G + m.inverseInertia * N * N), + z = (1 + f.restitution) * F * U; if (n *= U, F * F > l && F < 0) k.normalImpulse = 0; + else { var X = k.normalImpulse; + k.normalImpulse += z, k.normalImpulse = Math.min(k.normalImpulse, 0), z = k.normalImpulse - X } if (H * H > u) k.tangentImpulse = 0; + else { var Q = k.tangentImpulse; + k.tangentImpulse += n, k.tangentImpulse < -o && (k.tangentImpulse = -o), k.tangentImpulse > o && (k.tangentImpulse = o), n = k.tangentImpulse - Q } var Y = h * z + S * n, + Z = b * z + w * n; + y.isStatic || y.isSleeping || (y.positionPrev.x += Y * y.inverseMass, y.positionPrev.y += Z * y.inverseMass, y.anglePrev += (I * Z - T * Y) * y.inverseInertia), m.isStatic || m.isSleeping || (m.positionPrev.x -= Y * m.inverseMass, m.positionPrev.y -= Z * m.inverseMass, m.anglePrev -= (R * Z - E * Y) * m.inverseInertia) } } } } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(9), + r = n(0); + i.create = function(e) { return r.extend({ table: {}, list: [], collisionStart: [], collisionActive: [], collisionEnd: [] }, e) }, i.update = function(e, t, n) { var i, r, a, s, l, c, u = e.list, + d = u.length, + p = e.table, + f = t.length, + v = e.collisionStart, + y = e.collisionEnd, + m = e.collisionActive; for (v.length = 0, y.length = 0, m.length = 0, c = 0; c < d; c++) u[c].confirmedActive = !1; for (c = 0; c < f; c++)(l = (i = t[c]).pair) ? (l.isActive ? m.push(l) : v.push(l), o.update(l, i, n), l.confirmedActive = !0) : (p[(l = o.create(i, n)).id] = l, v.push(l), u.push(l)); var g = []; for (d = u.length, c = 0; c < d; c++)(l = u[c]).confirmedActive || (r = l.collision.bodyA, a = l.collision.bodyB, (!r.isSleeping && !r.isStatic || !a.isSleeping && !a.isStatic || r.isStatic && a.isStatic) && (o.setActive(l, !1, n), y.push(l), g.push(c))); for (c = 0; c < g.length; c++) l = u[s = g[c] - c], u.splice(s, 1), delete p[l.id] }, i.clear = function(e) { return e.table = {}, e.list.length = 0, e.collisionStart.length = 0, e.collisionActive.length = 0, e.collisionEnd.length = 0, e } }, function(e, t, n) { var i = e.exports = n(22); + i.Axes = n(11), i.Bodies = n(12), i.Body = n(6), i.Bounds = n(1), i.Collision = n(8), i.Common = n(0), i.Composite = n(5), i.Composites = n(23), i.Constraint = n(10), i.Contact = n(17), i.Detector = n(14), i.Engine = n(18), i.Events = n(4), i.Grid = n(24), i.Mouse = n(13), i.MouseConstraint = n(25), i.Pair = n(9), i.Pairs = n(20), i.Plugin = n(15), i.Query = n(26), i.Render = n(16), i.Resolver = n(19), i.Runner = n(27), i.SAT = n(28), i.Sleeping = n(7), i.Svg = n(29), i.Vector = n(2), i.Vertices = n(3), i.World = n(30), i.Engine.run = i.Runner.run, i.Common.deprecated(i.Engine, "run", "Engine.run ➤ use Matter.Runner.run(engine) instead") }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(15), + r = n(0); + i.name = "matter-js", i.version = "0.18.0-alpha+0eeceb5", i.uses = [], i.used = [], i.use = function() { o.use(i, Array.prototype.slice.call(arguments)) }, i.before = function(e, t) { return e = e.replace(/^Matter./, ""), r.chainPathBefore(i, e, t) }, i.after = function(e, t) { return e = e.replace(/^Matter./, ""), r.chainPathAfter(i, e, t) } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(5), + r = n(10), + a = n(0), + s = n(6), + l = n(12), + c = a.deprecated; + i.stack = function(e, t, n, i, r, a, l) { for (var c, u = o.create({ label: "Stack" }), d = e, p = t, f = 0, v = 0; v < i; v++) { for (var y = 0, m = 0; m < n; m++) { var g = l(d, p, m, v, c, f); if (g) { var x = g.bounds.max.y - g.bounds.min.y, + h = g.bounds.max.x - g.bounds.min.x; + x > y && (y = x), s.translate(g, { x: .5 * h, y: .5 * x }), d = g.bounds.max.x + r, o.addBody(u, g), c = g, f += 1 } else d += r } p += y + a, d = e } return u }, i.chain = function(e, t, n, i, s, l) { for (var c = e.bodies, u = 1; u < c.length; u++) { var d = c[u - 1], + p = c[u], + f = d.bounds.max.y - d.bounds.min.y, + v = d.bounds.max.x - d.bounds.min.x, + y = p.bounds.max.y - p.bounds.min.y, + m = { bodyA: d, pointA: { x: v * t, y: f * n }, bodyB: p, pointB: { x: (p.bounds.max.x - p.bounds.min.x) * i, y: y * s } }, + g = a.extend(m, l); + o.addConstraint(e, r.create(g)) } return e.label += " Chain", e }, i.mesh = function(e, t, n, i, s) { var l, c, u, d, p, f = e.bodies; for (l = 0; l < n; l++) { for (c = 1; c < t; c++) u = f[c - 1 + l * t], d = f[c + l * t], o.addConstraint(e, r.create(a.extend({ bodyA: u, bodyB: d }, s))); if (l > 0) + for (c = 0; c < t; c++) u = f[c + (l - 1) * t], d = f[c + l * t], o.addConstraint(e, r.create(a.extend({ bodyA: u, bodyB: d }, s))), i && c > 0 && (p = f[c - 1 + (l - 1) * t], o.addConstraint(e, r.create(a.extend({ bodyA: p, bodyB: d }, s)))), i && c < t - 1 && (p = f[c + 1 + (l - 1) * t], o.addConstraint(e, r.create(a.extend({ bodyA: p, bodyB: d }, s)))) } return e.label += " Mesh", e }, i.pyramid = function(e, t, n, o, r, a, l) { return i.stack(e, t, n, o, r, a, (function(t, i, a, c, u, d) { var p = Math.min(o, Math.ceil(n / 2)), + f = u ? u.bounds.max.x - u.bounds.min.x : 0; if (!(c > p || a < (c = p - c) || a > n - 1 - c)) return 1 === d && s.translate(u, { x: (a + (n % 2 == 1 ? 1 : -1)) * f, y: 0 }), l(e + (u ? a * f : 0) + a * r, i, a, c, u, d) })) }, i.newtonsCradle = function(e, t, n, i, a) { for (var s = o.create({ label: "Newtons Cradle" }), c = 0; c < n; c++) { var u = l.circle(e + c * (1.9 * i), t + a, i, { inertia: 1 / 0, restitution: 1, friction: 0, frictionAir: 1e-4, slop: 1 }), + d = r.create({ pointA: { x: e + c * (1.9 * i), y: t }, bodyB: u }); + o.addBody(s, u), o.addConstraint(s, d) } return s }, c(i, "newtonsCradle", "Composites.newtonsCradle ➤ moved to newtonsCradle example"), i.car = function(e, t, n, i, a) { var c = s.nextGroup(!0), + u = .5 * -n + 20, + d = .5 * n - 20, + p = o.create({ label: "Car" }), + f = l.rectangle(e, t, n, i, { collisionFilter: { group: c }, chamfer: { radius: .5 * i }, density: 2e-4 }), + v = l.circle(e + u, t + 0, a, { collisionFilter: { group: c }, friction: .8 }), + y = l.circle(e + d, t + 0, a, { collisionFilter: { group: c }, friction: .8 }), + m = r.create({ bodyB: f, pointB: { x: u, y: 0 }, bodyA: v, stiffness: 1, length: 0 }), + g = r.create({ bodyB: f, pointB: { x: d, y: 0 }, bodyA: y, stiffness: 1, length: 0 }); return o.addBody(p, f), o.addBody(p, v), o.addBody(p, y), o.addConstraint(p, m), o.addConstraint(p, g), p }, c(i, "car", "Composites.car ➤ moved to car example"), i.softBody = function(e, t, n, o, r, s, c, u, d, p) { d = a.extend({ inertia: 1 / 0 }, d), p = a.extend({ stiffness: .2, render: { type: "line", anchors: !1 } }, p); var f = i.stack(e, t, n, o, r, s, (function(e, t) { return l.circle(e, t, u, d) })); return i.mesh(f, n, o, c, p), f.label = "Soft Body", f }, c(i, "softBody", "Composites.softBody ➤ moved to softBody and cloth examples") }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(9), + r = n(0), + a = r.deprecated; + i.create = function(e) { return r.extend({ buckets: {}, pairs: {}, pairsList: [], bucketWidth: 48, bucketHeight: 48 }, e) }, i.update = function(e, t, n, o) { var r, a, s, l, c, u = n.world, + d = e.buckets, + p = !1; for (r = 0; r < t.length; r++) { var f = t[r]; if ((!f.isSleeping || o) && (!u.bounds || !(f.bounds.max.x < u.bounds.min.x || f.bounds.min.x > u.bounds.max.x || f.bounds.max.y < u.bounds.min.y || f.bounds.min.y > u.bounds.max.y))) { var v = i._getRegion(e, f); if (!f.region || v.id !== f.region.id || o) { f.region && !o || (f.region = v); var y = i._regionUnion(v, f.region); for (a = y.startCol; a <= y.endCol; a++) + for (s = y.startRow; s <= y.endRow; s++) { l = d[c = i._getBucketId(a, s)]; var m = a >= v.startCol && a <= v.endCol && s >= v.startRow && s <= v.endRow, + g = a >= f.region.startCol && a <= f.region.endCol && s >= f.region.startRow && s <= f.region.endRow;!m && g && g && l && i._bucketRemoveBody(e, l, f), (f.region === v || m && !g || o) && (l || (l = i._createBucket(d, c)), i._bucketAddBody(e, l, f)) } f.region = v, p = !0 } } } p && (e.pairsList = i._createActivePairsList(e)) }, a(i, "update", "Grid.update ➤ replaced by Matter.Detector"), i.clear = function(e) { e.buckets = {}, e.pairs = {}, e.pairsList = [] }, a(i, "clear", "Grid.clear ➤ replaced by Matter.Detector"), i._regionUnion = function(e, t) { var n = Math.min(e.startCol, t.startCol), + o = Math.max(e.endCol, t.endCol), + r = Math.min(e.startRow, t.startRow), + a = Math.max(e.endRow, t.endRow); return i._createRegion(n, o, r, a) }, i._getRegion = function(e, t) { var n = t.bounds, + o = Math.floor(n.min.x / e.bucketWidth), + r = Math.floor(n.max.x / e.bucketWidth), + a = Math.floor(n.min.y / e.bucketHeight), + s = Math.floor(n.max.y / e.bucketHeight); return i._createRegion(o, r, a, s) }, i._createRegion = function(e, t, n, i) { return { id: e + "," + t + "," + n + "," + i, startCol: e, endCol: t, startRow: n, endRow: i } }, i._getBucketId = function(e, t) { return "C" + e + "R" + t }, i._createBucket = function(e, t) { return e[t] = [] }, i._bucketAddBody = function(e, t, n) { var i, r = e.pairs, + a = o.id, + s = t.length; for (i = 0; i < s; i++) { var l = t[i]; if (!(n.id === l.id || n.isStatic && l.isStatic)) { var c = a(n, l), + u = r[c]; + u ? u[2] += 1 : r[c] = [n, l, 1] } } t.push(n) }, i._bucketRemoveBody = function(e, t, n) { var i, a = e.pairs, + s = o.id; + t.splice(r.indexOf(t, n), 1); var l = t.length; for (i = 0; i < l; i++) { var c = a[s(n, t[i])]; + c && (c[2] -= 1) } }, i._createActivePairsList = function(e) { var t, n, i = e.pairs, + o = r.keys(i), + a = o.length, + s = []; for (n = 0; n < a; n++)(t = i[o[n]])[2] > 0 ? s.push(t) : delete i[o[n]]; return s } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(3), + r = n(7), + a = n(13), + s = n(4), + l = n(14), + c = n(10), + u = n(5), + d = n(0), + p = n(1); + i.create = function(e, t) { var n = (e ? e.mouse : null) || (t ? t.mouse : null); + n || (e && e.render && e.render.canvas ? n = a.create(e.render.canvas) : t && t.element ? n = a.create(t.element) : (n = a.create(), d.warn("MouseConstraint.create: options.mouse was undefined, options.element was undefined, may not function as expected"))); var o = { type: "mouseConstraint", mouse: n, element: null, body: null, constraint: c.create({ label: "Mouse Constraint", pointA: n.position, pointB: { x: 0, y: 0 }, length: .01, stiffness: .1, angularStiffness: 1, render: { strokeStyle: "#90EE90", lineWidth: 3 } }), collisionFilter: { category: 1, mask: 4294967295, group: 0 } }, + r = d.extend(o, t); return s.on(e, "beforeUpdate", (function() { var t = u.allBodies(e.world); + i.update(r, t), i._triggerEvents(r) })), r }, i.update = function(e, t) { var n = e.mouse, + i = e.constraint, + a = e.body; if (0 === n.button) { if (i.bodyB) r.set(i.bodyB, !1), i.pointA = n.position; + else + for (var c = 0; c < t.length; c++) + if (a = t[c], p.contains(a.bounds, n.position) && l.canCollide(a.collisionFilter, e.collisionFilter)) + for (var u = a.parts.length > 1 ? 1 : 0; u < a.parts.length; u++) { var d = a.parts[u]; if (o.contains(d.vertices, n.position)) { i.pointA = n.position, i.bodyB = e.body = a, i.pointB = { x: n.position.x - a.position.x, y: n.position.y - a.position.y }, i.angleB = a.angle, r.set(a, !1), s.trigger(e, "startdrag", { mouse: n, body: a }); break } } } else i.bodyB = e.body = null, i.pointB = null, a && s.trigger(e, "enddrag", { mouse: n, body: a }) }, i._triggerEvents = function(e) { var t = e.mouse, + n = t.sourceEvents; + n.mousemove && s.trigger(e, "mousemove", { mouse: t }), n.mousedown && s.trigger(e, "mousedown", { mouse: t }), n.mouseup && s.trigger(e, "mouseup", { mouse: t }), a.clearSourceEvents(t) } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(2), + r = n(8), + a = n(1), + s = n(12), + l = n(3); + i.collides = function(e, t) { for (var n = [], i = t.length, o = e.bounds, s = r.collides, l = a.overlaps, c = 0; c < i; c++) { var u = t[c], + d = u.parts.length, + p = 1 === d ? 0 : 1; if (l(u.bounds, o)) + for (var f = p; f < d; f++) { var v = u.parts[f]; if (l(v.bounds, o)) { var y = s(v, e); if (y) { n.push(y); break } } } } return n }, i.ray = function(e, t, n, r) { r = r || 1e-100; for (var a = o.angle(t, n), l = o.magnitude(o.sub(t, n)), c = .5 * (n.x + t.x), u = .5 * (n.y + t.y), d = s.rectangle(c, u, l, r, { angle: a }), p = i.collides(d, e), f = 0; f < p.length; f += 1) { var v = p[f]; + v.body = v.bodyB = v.bodyA } return p }, i.region = function(e, t, n) { for (var i = [], o = 0; o < e.length; o++) { var r = e[o], + s = a.overlaps(r.bounds, t); + (s && !n || !s && n) && i.push(r) } return i }, i.point = function(e, t) { for (var n = [], i = 0; i < e.length; i++) { var o = e[i]; if (a.contains(o.bounds, t)) + for (var r = 1 === o.parts.length ? 0 : 1; r < o.parts.length; r++) { var s = o.parts[r]; if (a.contains(s.bounds, t) && l.contains(s.vertices, t)) { n.push(o); break } } } return n } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(4), + r = n(18), + a = n(0);! function() { var e, t, n; + ("undefined" != typeof window && (e = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame, t = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame), e) || (e = function(e) { n = setTimeout((function() { e(a.now()) }), 1e3 / 60) }, t = function() { clearTimeout(n) }); + i.create = function(e) { var t = a.extend({ fps: 60, correction: 1, deltaSampleSize: 60, counterTimestamp: 0, frameCounter: 0, deltaHistory: [], timePrev: null, timeScalePrev: 1, frameRequestId: null, isFixed: !1, enabled: !0 }, e); return t.delta = t.delta || 1e3 / t.fps, t.deltaMin = t.deltaMin || 1e3 / t.fps, t.deltaMax = t.deltaMax || 1e3 / (.5 * t.fps), t.fps = 1e3 / t.delta, t }, i.run = function(t, n) { return void 0 !== t.positionIterations && (n = t, t = i.create()), + function o(r) { t.frameRequestId = e(o), r && t.enabled && i.tick(t, n, r) }(), t }, i.tick = function(e, t, n) { var i, a = t.timing, + s = 1, + l = { timestamp: a.timestamp }; + o.trigger(e, "beforeTick", l), e.isFixed ? i = e.delta : (i = n - e.timePrev || e.delta, e.timePrev = n, e.deltaHistory.push(i), e.deltaHistory = e.deltaHistory.slice(-e.deltaSampleSize), s = (i = (i = (i = Math.min.apply(null, e.deltaHistory)) < e.deltaMin ? e.deltaMin : i) > e.deltaMax ? e.deltaMax : i) / e.delta, e.delta = i), 0 !== e.timeScalePrev && (s *= a.timeScale / e.timeScalePrev), 0 === a.timeScale && (s = 0), e.timeScalePrev = a.timeScale, e.correction = s, e.frameCounter += 1, n - e.counterTimestamp >= 1e3 && (e.fps = e.frameCounter * ((n - e.counterTimestamp) / 1e3), e.counterTimestamp = n, e.frameCounter = 0), o.trigger(e, "tick", l), o.trigger(e, "beforeUpdate", l), r.update(t, i, s), o.trigger(e, "afterUpdate", l), o.trigger(e, "afterTick", l) }, i.stop = function(e) { t(e.frameRequestId) }, i.start = function(e, t) { i.run(e, t) } }() }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(8), + r = n(0).deprecated; + i.collides = function(e, t) { return o.collides(e, t) }, r(i, "collides", "SAT.collides ➤ replaced by Collision.collides") }, function(e, t, n) { var i = {}; + e.exports = i; + n(1); var o = n(0); + i.pathToVertices = function(e, t) { "undefined" == typeof window || "SVGPathSeg" in window || o.warn("Svg.pathToVertices: SVGPathSeg not defined, a polyfill is required."); var n, r, a, s, l, c, u, d, p, f, v, y = [], + m = 0, + g = 0, + x = 0; + t = t || 15; var h = function(e, t, n) { var i = n % 2 == 1 && n > 1; if (!p || e != p.x || t != p.y) { p && i ? (f = p.x, v = p.y) : (f = 0, v = 0); var o = { x: f + e, y: v + t };!i && p || (p = o), y.push(o), g = f + e, x = v + t } }, + b = function(e) { var t = e.pathSegTypeAsLetter.toUpperCase(); if ("Z" !== t) { switch (t) { + case "M": + case "L": + case "T": + case "C": + case "S": + case "Q": + g = e.x, x = e.y; break; + case "H": + g = e.x; break; + case "V": + x = e.y } h(g, x, e.pathSegType) } }; for (i._svgPathToAbsolute(e), a = e.getTotalLength(), c = [], n = 0; n < e.pathSegList.numberOfItems; n += 1) c.push(e.pathSegList.getItem(n)); for (u = c.concat(); m < a;) { if ((l = c[e.getPathSegAtLength(m)]) != d) { for (; u.length && u[0] != l;) b(u.shift()); + d = l } switch (l.pathSegTypeAsLetter.toUpperCase()) { + case "C": + case "T": + case "S": + case "Q": + case "A": + s = e.getPointAtLength(m), h(s.x, s.y, 0) } m += t } for (n = 0, r = u.length; n < r; ++n) b(u[n]); return y }, i._svgPathToAbsolute = function(e) { for (var t, n, i, o, r, a, s = e.pathSegList, l = 0, c = 0, u = s.numberOfItems, d = 0; d < u; ++d) { var p = s.getItem(d), + f = p.pathSegTypeAsLetter; if (/[MLHVCSQTA]/.test(f)) "x" in p && (l = p.x), "y" in p && (c = p.y); + else switch ("x1" in p && (i = l + p.x1), "x2" in p && (r = l + p.x2), "y1" in p && (o = c + p.y1), "y2" in p && (a = c + p.y2), "x" in p && (l += p.x), "y" in p && (c += p.y), f) { + case "m": + s.replaceItem(e.createSVGPathSegMovetoAbs(l, c), d); break; + case "l": + s.replaceItem(e.createSVGPathSegLinetoAbs(l, c), d); break; + case "h": + s.replaceItem(e.createSVGPathSegLinetoHorizontalAbs(l), d); break; + case "v": + s.replaceItem(e.createSVGPathSegLinetoVerticalAbs(c), d); break; + case "c": + s.replaceItem(e.createSVGPathSegCurvetoCubicAbs(l, c, i, o, r, a), d); break; + case "s": + s.replaceItem(e.createSVGPathSegCurvetoCubicSmoothAbs(l, c, r, a), d); break; + case "q": + s.replaceItem(e.createSVGPathSegCurvetoQuadraticAbs(l, c, i, o), d); break; + case "t": + s.replaceItem(e.createSVGPathSegCurvetoQuadraticSmoothAbs(l, c), d); break; + case "a": + s.replaceItem(e.createSVGPathSegArcAbs(l, c, p.r1, p.r2, p.angle, p.largeArcFlag, p.sweepFlag), d); break; + case "z": + case "Z": + l = t, c = n } + "M" != f && "m" != f || (t = l, n = c) } } }, function(e, t, n) { var i = {}; + e.exports = i; var o = n(5); + n(0); + i.create = o.create, i.add = o.add, i.remove = o.remove, i.clear = o.clear, i.addComposite = o.addComposite, i.addBody = o.addBody, i.addConstraint = o.addConstraint }]) })); \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/style.css b/WebGames-master/WebGames-master/n-gon-master/style.css new file mode 100644 index 00000000..9b15685e --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/style.css @@ -0,0 +1,1745 @@ +:root { + --build-bg-color: #aeb6c2; + --card-color: #fafcfd; + --hover-card-color: #e5e5ed; +} + +body { + font-family: "Helvetica", "Arial", sans-serif; + margin: 0; + overflow: hidden; + cursor: auto; + /* filter: grayscale(1); */ + /* transition: background-color 0.2s ease-in-out; */ +} + +canvas { + position: absolute; + top: 0; + left: 0; + z-index: 0; + user-select: none; +} + +select { + font-size: 0.8em; + border: 1px #333 solid; + border-radius: 6px; +} + +select option { + background-color: #fff; +} + +input { + padding: 0px 4px; + font-size: 0.8em; + border: 1px #333 solid; + border-radius: 4px; +} + +a { + text-decoration: none; + color: #08c; +} + +em { + opacity: 0.7; +} + +#splash { + user-select: none; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 2; + transition: opacity 5s ease-in; +} + +*:focus { + outline: none; +} + +table { + border-collapse: collapse; + width: 360px; +} + +tr { + padding: 10px; + text-align: left; +} + +td { + padding-left: 10px; +} + +.key-input-train { + padding: 0px 5px; + border: 2px solid #444; + color: #444; + border-radius: 4px; + background-color: #d0d0d0; + text-align: center; + font-weight: 400; +} + +.key-input { + padding: 3px 8px; + border: 2px solid #333; + background-color: #fff; + text-align: center; +} + +.pause-table { + width: auto; +} + +.key-input-pause { + width: 15px; + padding: 0px 2px; + border: 2px solid #333; + background-color: #fff; + text-align: center; +} + +.key-used { + color: #777; + font-size: 80%; +} + +summary { + font-size: 1.2em; +} + +.SVG-button { + border: 1.5px #333 solid; + border-radius: 8px; + background-color: #fff; +} + +.SVG-button:hover { + background-color: #eee; +} + +.SVG-button-splash { + border: 2px #333 solid; + border-radius: 8px; + background-color: #fff; + transition: opacity 5s ease-in; +} + +.SVG-button-splash:hover { + background-color: #eee; +} + +#start-button { + position: absolute; + bottom: 108px; + right: 4px; + z-index: 12; + /* top-left | top-right | bottom-right | bottom-left */ + /* border-radius: 8px 8px 0 0; */ +} + +#training-button { + position: absolute; + bottom: 56px; + right: 4px; + z-index: 12; + /* border-radius: 8px 0px 0 0; */ +} + +#experiment-button { + position: absolute; + bottom: 4px; + right: 4px; + z-index: 12; + /* border-radius: 8px 0 8px 8px; */ +} + + + + + +#construct { + display: none; + position: absolute; + bottom: 0%; + right: 0%; + z-index: 1; + width: 250px; + height: 200px; + background-color: #fff; + color: #000; + font-size: 0.9em; + white-space: pre; + padding: 3px; + border: 1px #333 solid; +} + +#flex-center { + display: flex; + align-items: center; + justify-content: center; + height: 100%; +} + +.choose-grid { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + padding: 10px 1px; + margin: 0px; + border: 0px; + z-index: 12; + max-height: 99vh; + font-size: 1.3em; + display: grid; + grid-template-columns: repeat(3, 384px); + align-items: stretch; + visibility: hidden; + opacity: 0; + transition: opacity 0.25s linear; + overflow: auto; + -ms-overflow-style: none; + scrollbar-width: none; +} + +.choose-grid-no-images { + border-radius: 8px; + border: 10px solid #444; + gap: 10px; + background-color: #444; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + margin: 0px; + z-index: 12; + max-height: 99vh; + font-size: 1.3em; + display: grid; + grid-template-columns: 384px; + align-items: stretch; + visibility: hidden; + opacity: 0; + transition: opacity 0.25s linear; + overflow: auto; + -ms-overflow-style: none; + scrollbar-width: none; + /* box-shadow: 7px 7px 6px rgba(0, 0, 0, 0.13); */ +} + + +#choose-grid::-webkit-scrollbar { + display: none; +} + +.choose-grid-module { + line-height: 160%; + background-color: var(--card-color); + font-size: 0.75em; +} + +.choose-grid-module:hover { + background-color: var(--hover-card-color); +} + +.choose-grid-module:hover .card-text { + background-color: var(--hover-card-color); +} + +.research-select { + float: right; + margin-right: 10px; +} + +.pause-grid { + padding: 2px; + margin: 0px; + display: none; + grid-template-columns: 384px; + grid-auto-rows: minmax(auto, auto); + align-content: start; + align-items: start; + z-index: 2; + font-size: 1.3em; +} + +#pause-grid-right { + position: absolute; + top: -2px; + right: -4px; + overflow: auto; + max-height: 100vh; + -ms-overflow-style: none; + scrollbar-width: none; + padding: 1px; +} + +#pause-grid-right::-webkit-scrollbar { + display: none; +} + +#pause-grid-left { + position: absolute; + top: -2px; + left: -4px; + overflow: auto; + max-height: 100vh; + -ms-overflow-style: none; + scrollbar-width: none; +} + +#pause-grid-left::-webkit-scrollbar { + display: none; +} + +.pause-grid-module { + line-height: 160%; + background-color: var(--card-color); + font-size: 0.75em; +} + +.sort { + padding: 0.1em 0.3em; + border: 1px solid #444; + /* min-height: 88px; */ + line-height: 100%; + background-color: var(--card-color); +} + +.sort-button { + border: 1px #333 solid; + border-radius: 0.4em; + background-color: #fff; + font-size: 0.5em; + /* padding: 0.3em; */ + +} + +.sort-button:hover { + background-color: #eee; +} + +.pause-eject .card-text { + animation: techColorCycle 1s linear infinite alternate; +} + +#experiment-grid { + display: flex; + justify-content: center; + padding: 0px; + margin: 0px; + border: 0px; + background-color: var(--build-bg-color); + display: none; + grid-template-columns: repeat(auto-fit, 384px); + grid-auto-flow: row; + /* grid-auto-rows: minmax(auto, auto); */ + position: relative; + /* bottom: 0px; */ + z-index: 10; + font-size: 1.3em; + -ms-overflow-style: none; + /* IE and Edge */ + scrollbar-width: none; + /* Firefox */ +} + +#experiment-grid::-webkit-scrollbar { + display: none; +} + +.experiment-grid-module { + line-height: 160%; + background-color: var(--card-color); + font-size: 0.75em; +} + +.experiment-grid-hide { + display: none; +} + +.grid-title { + padding-bottom: 6px; + padding-top: 4px; + font-size: 1.4em; + font-weight: 600; +} + +.experiment-grid-module:hover:not(.build-tech-selected, .build-field-selected, .build-gun-selected) { + background-color: var(--card-color); +} + +.experiment-start-box { + background-color: var(--card-color); + position: sticky; + top: 0; + z-index: 10; + align-self: start; + width: 276px; + line-height: 200%; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + border: 2px #333 solid; + border-top: 0px; + border-radius: 10px; + border-top-left-radius: 0px; + /* border-bottom-left-radius: 0px; */ + border-top-right-radius: 0px; + padding: 0.2em 0px; + /* height: 210px; */ + box-shadow: 8px 8px 6px rgba(0, 0, 50, 0.15); + /* opacity: 0.1; */ +} + +.card-background { + height: 340px; + background-size: contain; + background-repeat: no-repeat; + display: flex; + justify-content: flex-end; + flex-direction: column; +} + +.card-text { + background-color: var(--card-color); + padding: 0.5em 1em; + border: 1px solid #444; + margin-top: -1px; + margin-right: -1px; + font-size: 0.92em; + min-height: 88px; + /* border-radius: 5px; */ +} + +.cancel-card { + text-align: center; + font-size: 1.1em; + font-weight: 100; + justify-self: end; + border: 1px solid #444; + margin-top: -1px; + margin-right: -1px; + padding: 1px; + line-height: 160%; + background-color: var(--card-color); +} + +.cancel-card:hover { + background-color: var(--hover-card-color); +} + +.research-card { + font-size: 1.1em; + font-weight: 100; + border: 1px solid #444; + margin-top: -1px; + margin-right: -1px; + padding: 1px 0px 1px 10px; + line-height: 160%; + background-color: var(--card-color); +} + +.research-card:hover { + background-color: var(--hover-card-color); +} + +.research-cancel { + display: flex; + gap: 10px; + line-height: 160%; + /* background-color: var(--card-color); */ + font-size: 1em; + position: sticky; + top: 0px; + z-index: 10; +} + +.sticky { + position: sticky; + top: 0px; + z-index: 10; +} + +/* keeps 5 columns at 1440px */ +@media (min-width: 1710px) and (max-width: 1950px) { + + .experiment-grid-module, + .choose-grid-module, + .pause-grid-module, + .research-cancel { + line-height: 143%; + font-size: 0.68em; + } + + .research-cancel { + font-size: 0.9em; + } + + #experiment-grid, + .choose-grid, + .pause-grid { + grid-template-columns: repeat(auto-fit, 340px); + } + + .card-background { + height: 290px; + } + + .card-text { + min-height: 75px; + } +} + +/* (min-width: 30em) and (max-width: 80em) */ +@media (max-width: 1709px) { + + .experiment-grid-module, + .choose-grid-module, + .pause-grid-module { + line-height: 139%; + font-size: 0.58em; + } + + .research-cancel { + font-size: 0.8em; + } + + #experiment-grid, + .choose-grid, + .pause-grid { + grid-template-columns: repeat(auto-fit, 285px); + } + + .card-background { + height: 240px; + } + + .card-text { + min-height: 64px; + } +} + +/* .card-text */ +.choose-grid-no-images .card-text, +.choose-grid-no-images .research-card, +.choose-grid-no-images .cancel-card { + border-radius: 5px; +} + +.experiment-grid-module:hover .card-text { + background-color: var(--hover-card-color); +} + +.build-tech-selected .card-text { + background-color: hsl(253, 100%, 84%); +} + +.build-tech-selected.experiment-grid-module:hover .card-text { + background-color: hsl(253, 100%, 81%); +} + +.build-gun-selected .card-text { + background-color: hsl(218, 100%, 81%); +} + +.build-gun-selected.experiment-grid-module:hover .card-text { + background-color: hsl(218, 100%, 76%); +} + +.build-field-selected .card-text { + background-color: hsl(193, 100%, 75%); +} + +.build-field-selected.experiment-grid-module:hover .card-text { + background-color: hsl(193, 100%, 68%); +} + +.experiment-grid-disabled { + /* background-color: var(--build-bg-color); */ + /* color: #000; */ + opacity: 0.35; +} + +.experiment-grid-disabled[data-descr] { + position: relative; +} + +.experiment-grid-disabled[data-descr]:hover::after { + content: '\a \00a0 \00a0 \00a0 REQUIRES:\a \00a0 \00a0 \00a0 ' attr(data-descr); + white-space: pre-wrap; + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 100%; + background-color: var(--build-bg-color); + z-index: 1; + opacity: 1; + transition: opacity 0.5s ease; +} + +#info { + position: absolute; + bottom: 3px; + left: 3px; + z-index: 10; + font-size: 1.5em; + transition: opacity 5s ease-in; + width: 100%; + + /* border: 1.5px #333 solid; */ + /* border-radius: 8px; */ + /* background-color: #fff; */ +} + +.details-div { + padding: 10px; + border-radius: 8px; + border: 2px #333 solid; + background-color: var(--card-color); +} + + +#dmg { + position: absolute; + z-index: 2; + width: 100%; + height: 100%; + display: none; + /* background-color also set in mass-energy tech */ + background-color: #f67; + opacity: 0; + transition: opacity 1s; +} + +#damage-bar { + position: absolute; + /* top: 1px; + left: 15px; + height: 7px; + width: 0px; + transition: width 0.3s linear; */ + top: 16px; + right: 4px; + height: 0px; + width: 7px; + transition: height 0.25s linear; + opacity: 1; + z-index: 2; + pointer-events: none; + background-color: rgb(255, 55, 95); + /* border-bottom: 1.5px solid #701; */ + /* border-right: 1.5px solid #701; */ + display: none; +} + +#defense-bar { + position: absolute; + top: 8px; + left: 15px; + height: 7px; + width: 0px; + transition: width 0.25s linear; + opacity: 1; + z-index: 2; + pointer-events: none; + background-color: #fff; + border-right: 1.5px solid #777; + display: none; +} + +#health { + position: absolute; + top: 15px; + left: 15px; + height: 20px; + width: 0px; + transition: width 1s ease-out; + z-index: 2; + pointer-events: none; + background-color: rgb(9, 245, 166); + border-right: 2px solid rgb(51, 162, 125); + display: none; +} + +#health-bg { + position: absolute; + top: 15px; + left: 15px; + height: 20px; + width: 0px; + transition: width 1s ease-out; + background-color: #032; + opacity: 0.1; + z-index: 1; + pointer-events: none; + display: none; +} + +/* background on title page */ +#fade-out { + position: absolute; + z-index: 2; + width: 100%; + height: 100%; + background-color: #e2e9ec; + opacity: 1; + transition: opacity 3s; + pointer-events: none; +} + +#guns { + position: absolute; + top: 82px; + left: 15px; + z-index: 2; + font-size: 23px; + color: #222; + background-color: rgba(255, 255, 255, 0.2); + line-height: 120%; + user-select: none; + pointer-events: none; + padding: 0px 5px 0px 5px; + border-radius: 5px; +} + +#field { + position: absolute; + top: 45px; + left: 15px; + z-index: 2; + font-size: 23px; + color: #000; + text-align: right; + opacity: 0.7; + background-color: rgba(190, 210, 245, 0.25); + user-select: none; + pointer-events: none; + padding: 0px 5px 0px 5px; + border-radius: 5px; +} + +#right-HUD { + position: absolute; + top: 15px; + right: 15px; + z-index: 2; + font-size: 20px; + text-align: right; + line-height: 120%; + user-select: none; + pointer-events: none; + /*border: 2px solid rgba(0, 0, 0, 0.4);*/ + color: #222; + padding: 0px 5px 0px 5px; + border-radius: 5px; + opacity: 0.35; + background-color: rgba(255, 255, 255, 0.4); +} + +#right-HUD-constraint { + position: absolute; + top: 12px; + right: 15px; + z-index: 2; + font-size: 20px; + text-align: right; + line-height: 120%; + user-select: none; + pointer-events: none; + padding: 5px 10px 5px 10px; + border-radius: 8px; + color: #624; + opacity: 0.35; + background-color: rgba(255, 215, 241, 0.4); + /* color: rgb(141, 23, 88); + opacity: 0.35; + background-color: rgba(141, 23, 88, 0.1); */ + /* font-weight: 400; */ + transition: all 0.5s linear; +} + +#text-log { + z-index: 2; + position: absolute; + bottom: 10px; + left: 10px; + padding: 10px; + border-radius: 4px; + line-height: 140%; + font-size: 1.15em; + color: #555; + background-color: rgba(255, 255, 255, 0.5); + pointer-events: none; + user-select: none; +} + +.constraint { + color: rgb(141, 23, 88); + /* font-weight: 100; */ + /* text-decoration: underline; */ +} + +.color-text { + color: #000; +} + +.color-var { + color: hsl(253, 100%, 58%); +} + +.color-symbol { + color: hsl(290, 100%, 40%); +} + +.color-gun { + color: hsl(218, 100%, 58%); +} + +.highlight { + border-radius: 6px; + background-color: #ff0; + padding: 3px; +} + +.color-f { + color: #0ad; + letter-spacing: 1px; +} + +.color-s { + color: #04f; + letter-spacing: 1px; +} + +.color-d { + color: #f03; + letter-spacing: 1px; +} + +.color-p { + color: #067; + letter-spacing: 1px; +} + +.color-h { + color: #0b7; + letter-spacing: 1px; +} + +.color-e { + color: #d60; + letter-spacing: 1px; +} + +.color-m { + color: hsl(253, 100%, 50%); + letter-spacing: 1px; +} + +.color-g { + color: hsl(218, 80%, 40%); + letter-spacing: 1px; +} + +.color-ammo { + color: #356; +} + +.color-choice { + display: inline-block; +} + +.color-choice span { + display: inline-block; + animation: bounce 3s infinite; + transform-origin: bottom; + color: #555; +} + +.color-choice span:nth-child(1) { + animation-delay: 0s; +} + +.color-choice span:nth-child(2) { + animation-delay: 1s; +} + +.color-choice span:nth-child(3) { + animation-delay: 2s; +} + +@keyframes bounce { + 0% { + transform: translateY(0); + } + + 15% { + transform: translateY(-2px); + color: #aaa; + } + + 30% { + transform: translateY(0); + } + + 100% { + transform: translateY(0); + } +} + +.color-invulnerable { + color: #fff; + text-shadow: 0px 0px 7px #000; +} + +.color-dark-matter { + color: #246; + text-shadow: 0px 0px 7px #246; +} + +.color-tokamak { + color: #5c3ab8; + font-weight: 100; + text-shadow: 0px -5px 9px rgb(255, 0, 204); +} + + + +.color-dup { + font-variant: small-caps; + letter-spacing: 1px; + text-shadow: 1.5px -1.5px hsla(243, 100%, 38%, 0.2); +} + +.color-remove { + text-decoration: line-through; + /* letter-spacing: 2px; */ + border-radius: 3px; + padding: 0px 3px; + background-color: hsl(255, 40%, 71%); + color: #fff; +} + +.color-cloaked { + letter-spacing: 2px; + animation: cloak 6s linear infinite alternate; + color: rgba(0, 0, 0, 0); +} + +@keyframes cloak { + 0% { + text-shadow: 0px 0px 0px #000; + opacity: 1; + } + + 50% { + text-shadow: 0px 0px 0px #000; + opacity: 1; + } + + 100% { + text-shadow: 0px 0px 15px #000; + opacity: 0; + } +} + +.color-laser { + color: #f02; + font-weight: 100; + letter-spacing: -0.8px; +} + +.color-plasma { + color: #c0e; + letter-spacing: 1px; + background-color: rgba(132, 0, 255, 0.06); + padding: 2px; + border-radius: 9px; + letter-spacing: 1px; +} + +.color-worm { + color: #fff; + text-shadow: 1px 0px 2px #234; +} + +.color-print { + color: #567; + font-family: 'Courier New', Courier, monospace; +} + +.color-defense { + background-color: hsla(227, 9%, 71%, 0.279); + padding: 2px; + border-radius: 4px; + letter-spacing: 1px; + font-weight: 100; +} + +.color-bot { + font-variant: small-caps; + background-color: rgba(75, 125, 150, 0.06); + border: 0.1em solid #146; + color: #146; + padding: 0em 0.3em 0.08em 0.3em; + font-weight: 400; +} + +.no-box { + border: none; + background-color: transparent; + padding: 0; +} + +.color-block { + background-color: rgba(0, 0, 0, 0.1); + border: 0.1em solid #333; + padding: 0.5px; + font-weight: 100; +} + +.color-cancel { + background-color: var(--card-color); + border: 0.15em #444 solid; + padding: 0.2em; + border-radius: 0.2em; + font-weight: 800; + font-size: 1em; +} + +.color-junk { + letter-spacing: 1px; + font-family: Lucida Console, Courier, monospace; +} + +.color-r { + color: #f7b; + letter-spacing: 1px; +} + +.color-flop { + text-decoration: underline; + font-weight: 100; + letter-spacing: -1px; +} + +.color-alt { + text-decoration: underline; + font-weight: 100; + letter-spacing: -1px; +} + +.faded { + opacity: 0.7; + font-size: 90%; +} + +.circle-grid { + width: 1.32em; + height: 1.32em; + border-radius: 50%; + display: inline-block; + margin-bottom: -0.3em; +} + +.circle-grid-instant { + width: 1.1em; + height: 1.1em; + border-radius: 50%; + border: 0.15em solid hsl(255, 100%, 71%); + display: inline-block; + margin-bottom: -0.35em; +} + +.circle-grid-skin { + width: 1.25em; + height: 1.25em; + border-radius: 50%; + display: inline-block; + background-color: #fff; + opacity: 0.8; + border: 0.08em solid #222; + position: absolute; + top: -0.05em; + left: 0em; +} + +.circle-grid-skin-eye { + width: 0.18em; + height: 0.18em; + border-radius: 50%; + display: inline-block; + background-color: #fff; + border: 0.08em solid #222; + position: absolute; + top: 0.45em; + left: 0.9em; +} + +.junk { + background-color: hsl(254, 44%, 75%); + border-radius: 25%; +} + +.research-circle { + width: 0.9em; + height: 0.9em; + border-radius: 50%; + display: inline-block; + background-color: #f7b; + border: 0.065em #fff solid; + opacity: 0.85; + margin-bottom: -0.1em; +} + +.ammo-circle { + width: 0.75em; + height: 0.75em; + border-radius: 50%; + display: inline-block; + background-color: #467; + border: 0.05em #fff solid; + opacity: 0.95; + margin-bottom: -1.5px; +} + +.heal-circle { + width: 0.95em; + height: 0.95em; + border-radius: 50%; + display: inline-block; + background-color: #0d9; + border: 0.05em #fff solid; + opacity: 0.85; + margin-bottom: -2px; +} + +.heal-circle-energy { + width: 0.95em; + height: 0.95em; + border-radius: 50%; + display: inline-block; + background-color: #ff0; + border: 0.05em #000 solid; + opacity: 0.85; + margin-bottom: -2px; +} + +.coupling-circle { + width: 0.7em; + height: 0.7em; + border-radius: 50%; + display: inline-block; + background-color: #0ae; + border: 0.05em #fff solid; + margin-bottom: -0.5px; +} + +.boost-circle { + width: 0.7em; + height: 0.7em; + border-radius: 50%; + display: inline-block; + background-color: #f03; + border: 0.05em #fff solid; + opacity: 0.9; + margin-bottom: -0.5px; +} + +@keyframes pulse { + 0% { + border-radius: 0%; + } + + 100% { + border-radius: 50%; + } +} + +.field { + background-color: #0cf; +} + +.tech { + background-color: hsl(255, 100%, 71%); +} + +.gun { + background-color: rgb(0, 80, 218); +} + +.heal { + background-color: #0d9; +} + +.research { + background-color: #f7b; +} + +.color-speed { + display: inline-block; + transform: skew(-27deg); + /* font-weight: 400; */ + color: #038; +} + +.color-randomize { + display: inline-block; + animation: randomize 4s linear infinite alternate; + transform-origin: bottom; + color: #555; +} + +@keyframes randomize { + + 0%, + 100% { + font-family: Arial; + } + + 20% { + font-family: Times New Roman; + } + + 40% { + font-family: Verdana; + } + + 60% { + font-family: Georgia; + } + + 80% { + font-family: Courier New; + } +} + +.alt { + animation: alt 8s linear infinite alternate; + font-weight: 400; + letter-spacing: 1px; +} + +@keyframes alt { + 0% { + text-shadow: 3px 0px 0px; + } + + 100% { + text-shadow: -3px 0px 0px; + } + +} + +.flicker { + animation: flicker 4s linear infinite; +} + +@keyframes flicker { + 0% { + opacity: 1; + } + + 80% { + opacity: 1; + } + + 90% { + opacity: 0; + } + + 100% { + opacity: 1; + } +} + +.color-coupling { + text-shadow: 0px 0px 1.5px #0cf; + letter-spacing: 1px; + font-weight: 100; +} + +.box { + padding: 3px 8px 3px 8px; + border: 2px solid #444; + border-radius: 4px; + background-color: rgba(255, 255, 255, 0.5); +} + +.wrapper { + display: grid; + grid-template-columns: 360px 10px; + align-self: center; + justify-content: center; +} + +.grid-box { + align-self: center; + justify-self: center; +} + +.right { + text-align: right; +} + +.lore { + animation: bgColor 3.5s linear infinite; +} + +.lore-text { + animation: textColor 3s linear infinite; +} + +.entanglement { + font-size: 1.1em; + font-weight: 100; + text-align: center; + letter-spacing: 10px; + border: none; + background-color: var(--card-color); +} + +.flipX { + animation: 14s anim-flipX linear infinite; +} + +@keyframes anim-flipX { + 0% { + transform: rotateX(0.5turn); + } + + 50% { + transform: rotateX(1turn); + } + + 100% { + transform: rotateX(0.5turn); + } +} + +@keyframes fieldColorCycle { + 0% { + background-color: rgb(255, 255, 255) + } + + 100% { + background-color: rgb(0, 204, 255) + } +} + +@keyframes techColorCycle { + 0% { + background-color: hsl(253, 100%, 100%) + } + + 100% { + background-color: hsl(253, 100%, 90%) + } +} + +@keyframes bgColor { + 0% { + background-color: rgb(63, 218, 216) + } + + 10% { + background-color: rgb(47, 201, 226) + } + + 20% { + background-color: rgb(28, 127, 238) + } + + 30% { + background-color: rgb(95, 21, 242) + } + + 40% { + background-color: rgb(186, 12, 248) + } + + 50% { + background-color: rgb(251, 7, 217) + } + + 60% { + background-color: rgba(255, 0, 0) + } + + 70% { + background-color: rgb(255, 0, 0) + } + + 80% { + background-color: rgb(255, 154, 0) + } + + 90% { + background-color: rgb(208, 222, 33) + } + + 100% { + background-color: rgb(79, 220, 74) + } +} + +@keyframes textColor { + 0% { + color: rgb(63, 218, 216) + } + + 10% { + color: rgb(47, 201, 226) + } + + 20% { + color: rgb(28, 127, 238) + } + + 30% { + color: rgb(95, 21, 242) + } + + 40% { + color: rgb(186, 12, 248) + } + + 50% { + color: rgb(251, 7, 217) + } + + 60% { + color: rgba(255, 0, 0) + } + + 70% { + color: rgb(255, 0, 0) + } + + 80% { + color: rgb(255, 154, 0) + } + + 90% { + color: rgb(208, 222, 33) + } + + 100% { + color: rgb(79, 220, 74) + } +} + +.link { + color: #000; +} + +.link:hover { + text-decoration: underline; +} + +/* +.fade-ins { + animation: 1.5s linear 1s fadeins; +} + +@keyframes fadeins { + 0% { + opacity: 0; + } + + 100% { + opacity: 1; + } +} */ +.blurry-text { + color: transparent; + text-shadow: 0 0 10px rgba(0, 0, 0, 0.6); +} + +.unblur { + color: transparent; + text-shadow: 0 0 7px rgba(0, 0, 0, 0.5); + animation: 2.5s ease 0.5s normal forwards 1 unblur; +} + +@keyframes unblur { + 0% { + color: transparent; + text-shadow: 0 0 7px rgba(0, 0, 0, 0.5); + } + + 100% { + /* font-weight: 800; */ + color: #000; + text-shadow: 0 0 0px rgba(0, 0, 0, 0.5); + } +} + +.fade-in { + opacity: 0; + animation: 2s ease 1.5s normal forwards 1 fadein; +} + +.fade-in-fast { + opacity: 0; + animation: 1.5s ease 1s normal forwards 1 fadein; +} + +.fade-in-faster { + opacity: 0; + animation: 2s ease 0.5s normal forwards 1 fadein; +} + +@keyframes fadein { + 0% { + opacity: 0; + } + + 100% { + opacity: 1; + } +} + +@keyframes dash { + to { + stroke-dashoffset: 0; + } +} + +.draw-lines { + stroke-dasharray: 20; + stroke-dashoffset: 20; + animation: dash 2.4s ease-in forwards; +} + +.draw-lines-dash { + stroke-dasharray: 4; + stroke-dashoffset: 4; + animation: dash 2.4s ease-in forwards; +} + +.draw-lines-o { + stroke-dasharray: 11; + stroke-dashoffset: 11; + animation: dash 2.4s ease-in forwards; +} + +.draw-lines-g { + stroke-dasharray: 17; + stroke-dashoffset: 17; + animation: dash 2.4s ease-in forwards; +} + +.draw-lines-box-1 { + stroke-dasharray: 1000; + stroke-dashoffset: 1000; + animation: dash 5s ease-in forwards; + animation-delay: 0s; +} + +.draw-lines-box-2 { + stroke-dasharray: 1000; + stroke-dashoffset: 1000; + animation: dash 2.6s ease-in forwards; + animation-delay: 1s; +} + +.draw-lines-box-3 { + stroke-dasharray: 1000; + stroke-dashoffset: 1000; + animation: dash 1.15s ease-in forwards; + animation-delay: 1.55s; +} + +.draw-lines3 { + stroke-dasharray: 3000; + stroke-dashoffset: 3000; + animation: dash 3.1s ease-in forwards; +} + +.draw-lines4 { + stroke-dasharray: 500; + stroke-dashoffset: 500; + animation: dash 3.5s ease-in forwards; +} + + + +.grid-container { + display: grid; + grid-template-columns: 0fr 5fr 0fr; + line-height: 150%; + background-color: #fff; + padding: 15px 0 14px 0; + border-radius: 5px; +} + +.far-right-column { + display: grid; + grid-template-rows: repeat(7, 1fr); + font-size: 2rem; + font-family: monospace; + align-self: center; + justify-self: center; + width: 22px; + /* padding: 0rem; */ +} + +.far-right-column>div { + padding-top: 50px; +} + +#difficulty-slider { + margin-top: 2.3rem; + /* height: 26.3rem; */ + height: 31.4rem; + width: 2rem; + writing-mode: vertical-lr; + direction: ltr; +} + +.left-column { + grid-row: 1 / span 7 +} + +.right-column { + display: grid; + grid-template-rows: repeat(7, 1fr); + /* to adjust the width of this column edit the "gridTemplateColumns" in the difficulty power up js code*/ +} + +.row { + transition: opacity 0.4s ease-out; + /* border: 2px #444 solid; */ + /* margin-top: -2px; */ + font-size: 1.2rem; + padding: 10px; +} + +.pause-difficulty-row { + line-height: 130%; + font-size: 1em; + padding: 7px 0px 7px 0px; + /* top | right | bottom | left */ + margin: -5px 0; +} + +#constraint-1 { + background-color: hsl(240, 18%, 95%); + border-radius: 7px 7px 0 0; +} + +#constraint-2 { + background-color: hsl(240, 18%, 93%); +} + +#constraint-3 { + background-color: hsl(240, 18%, 89%); +} + +#constraint-4 { + background-color: hsl(240, 18%, 85%); +} + +#constraint-5 { + background-color: hsl(240, 18%, 81%); +} + +#constraint-6 { + background-color: hsl(240, 18%, 77%); +} + +#constraint-7 { + background-color: hsl(240, 18%, 73%); + border-radius: 0 0 7px 7px; +} + +#constraint-1:hover { + background-color: hsl(240, 18%, 93%); + border: 1px #444 solid; + padding: 9px; +} + +#constraint-2:hover { + background-color: hsl(240, 18%, 91%); + border: 1px #444 solid; + padding: 9px; +} + +#constraint-3:hover { + background-color: hsl(240, 18%, 87%); + border: 1px #444 solid; + padding: 9px; +} + +#constraint-4:hover { + background-color: hsl(240, 18%, 83%); + border: 1px #444 solid; + padding: 9px; +} + +#constraint-5:hover { + background-color: hsl(240, 18%, 79%); + border: 1px #444 solid; + padding: 9px; +} + +#constraint-6:hover { + background-color: hsl(240, 18%, 75%); + border: 1px #444 solid; + padding: 9px; +} + +#constraint-7:hover { + background-color: hsl(240, 18%, 71%); + border: 1px #444 solid; + padding: 9px; +} + +#choose-difficulty { + text-align: center; + font-size: 1.1em; + padding: 5px; + margin-top: 10px; + color: #333; + border-radius: 5px; +} + +.pause-details { + background-color: #e2e9ec; + border: 1px solid #333; + border-radius: 5px; + padding: 7px; + margin-bottom: 10px; + /* box-shadow: 4px 4px 4px hsla(240, 0%, 17%, 0.14); */ +} + +.tooltip {} + +.tooltip .tooltiptext { + visibility: hidden; + background-color: #fff; + border-radius: 0.3em; + padding: 0.2em 0.3em; + border: solid #000 1px; + + position: relative; + z-index: 1; + bottom: 100%; + left: 0%; + margin-left: -50%; +} + +.tooltip:hover .tooltiptext { + visibility: visible; +} \ No newline at end of file diff --git a/WebGames-master/WebGames-master/n-gon-master/todo.txt b/WebGames-master/WebGames-master/n-gon-master/todo.txt new file mode 100644 index 00000000..7d47bf94 --- /dev/null +++ b/WebGames-master/WebGames-master/n-gon-master/todo.txt @@ -0,0 +1,1278 @@ +******************************************************** NEXT PATCH ************************************************** + +new level corridor + new level element fizzler - it removes blocks +interferometer has wider platforms, a few helpful blocks, and fewer mobs +level constraints are announced in console + +foam gun no longer pushes the player back when firing +wave gun buffs + 1.2x base damage + 1.1x base ammo + 0.1->0.13x speed in map + 0.25->0.30x speed in blocks + tech: phase velocity 1.4->1.5x damage +pigeonhole principle gives 1.3->1.4 damage per gun + you can no longer switch guns, your gun cycles each level +quenching 0.4->0.5x overheal converts into max health +tungsten carbide no longer has reduced coyote cycles +control theory 1.5->2x damage at max health +stability 0.3->0.2 damage taken at max health +overcharge +88->100 max energy, 4->5% JUNK +zoospore vector 10->13% chance for spores on mob death +replication 15->10% JUNK +interest 6->5% of your power ups spawn each level + +updated "about" details menu + moved classic n-gon to here from settings + added links to community content in "about" + Are there more links I should add? + added an n-gon SVG head image + +bugs + fixed outline on splash screen doesn't sync right on safari browser + fixed possible lock out on training levels: "hold", "throw", "throwAt" + from losing block behind a door + shortcut sort buttons in experiment mode properly order tech without clicking sort + fixed/increased the horizontal velocity contribution for some guns + this makes bullets shot on moving platforms more realistic + nail gun, super balls, foam, harpoon + +******************************************************** BUGS ******************************************************** + +figure out why seeded random isn't making runs the same: + shuffle is being used for a wide variety of things that don't need a seeded random + make two shuffle functions? + check which of these is working + level order + is flipped + constraint order + mob type order + boss order + gun, field, tech options + make field options offered precalculated so it doesn't depend on player choices? + generate all constraints at the start of the game + doesn't seem to be determined by the seed... + display future constraints in pause menu? + +player can become crouched while not touching the ground if they exit the ground while crouched + +*********************************************************** TODO ***************************************************** + +tech: demineralization - 0.2x damage taken, but it slowly reduces effect + increase to full: + at start of level? + when you get the tech + decrease: + over time + at start of new level + +!!conformal - similar rules for small and big scales linked to holographic principle +!!holonomy - parallel transport of a vector leads to movement (applies to curved space) + when far away from your wormhole regenerate 1% of your max energy per second + when far away from your wormhole reduce damage taken + heal last hit damage after enter wormhole +!!quasar - plasma torch from both ends + only after wormhole eats a block fire? + or just increase plasma length after eating block? + +make a text orb for JUNK text to make JUNK more clear + +procedural animation + https://www.youtube.com/watch?v=qlfh_rv6khY + +tech: ice-VII - 1.5x duration for ice-IX +tech: - freezing grenades/explosions +tech: - when you get a bot, get a second bot +tech: - after killing a Boss + heal to full + gain 3x damage for the rest of the level + +new level - rework testChamber + +Boss (or mob) that quickly moves towards player, but then moves perpendicularly to player, like dodging + could respond to when player presses fire key or to when it takes damage + +new snakeBoss type that eats mobs + each time it eats: + heal? + get shield if full? + make boss longer (if snake) + get shield + get orbitals + spawn spawns (little red square mobs) + when boss dies + spawn eaten mobs? + spawn generic mobs? + nothing + make snake new colors, width + +Boss mob - takes a snapshot of the positions of all mobs, player, blocks, power ups. Then 3 seconds later it teleports everything back to those spots. + after snap shot is stored draw outline of body positions for a second to show the change + immune after snapshot? or immune after teleport? +Boss mob - records the position of mobs every few cycles + makes a ghost copy of the mob that is delayed by a few seconds + ghost can damage player, but doesn't have a matter.js object + gives mobs short snake tails, like snakeBoss + brings 1 mob back to life every few seconds + +tech: atomic pile - lose 1 health if you are above the maximum energy + generate energy for each nearby mob? + do damage? + plasma torch tech? + +make player mass an adjustable var in the skin + does this mess with jump height or air control? +increase mass and movement speed at the same time + increase jump differently because it scales extra with mass + m.defaultMass = 4.5 + m.definePlayerMass() + possible player.mass bad interactions + grapple + +tech - after a power up is duplicated + update text to random effect after choosing tech, or after each trigger, or on first display of tech + pick 1 effect at random + become immune to damage taken for 5 seconds + summon JUNK bots for 10 seconds + 2x current energy + gain 1.01x damage permanently + cool name: + +after picking up heals gain ____ + 0.1x damage taken for 12s +after picking up ammo gain ____ + 4x fire rate for 12s +after picking up research gain ____ + +10 choices for 12s + +tech: Energy generation increases with you velocity + Newtons' 3rd law? + +tech - getting caught in an explosion gives you _____ + damage for 10 seconds? + heals + +explosions have a chance to spawn spores + infinite feedback loop with spores that explode? + +tech - getting a new gun also gives you 2 random tech for that gun + or a field? + can these guntech tech be converted into a player choice? + +how to reduce the number of clicks and keypresses + auto fire mode + player shoots at whatever is nearby + should player have to look towards mobs? + increase ammo? + +animate egg laying mobs + just draw a circle when it happens? + +improve new player experience + training is too long to be a tutorial + before nail gun level offer player option to continue or switch to normal game + ++40% foam size ++40% foam damage +-40% foam ammo gain +When foam is in an explosion it also explodes with size proportional to the size of the foam bubble +Requires foam, explosion source, not aerogel + +Cosmological natural selection: do something with black holes + spawn black hole mobs + after bosses die? + after any mob dies + at the start of new levels + make new black hole bullet mobs + +write code the checks version and compares it to the version from patch notes + and link to main page if they don't match + (this is because there are several outdated versions hosted on sites with ads) + +foam tech: increase size of foam and increase duration, but drop speed down, so they come to a stop and just hang + allow them to harm player? + this is probably just too annoying +Foam slow down mobs twice as much and slowly pulls them towards the ground + +30% foam damage + Half foam velocity + Foam is now effected by gravity + Requires a source of foam and not aerogel + https://en.m.wikipedia.org/wiki/Tungsten_hexafluoride + +if needles touch map and mob at the same time pin mob to map + this might be better as a railgun tech, or a railgun rework + name rebar + +make grappling hook of different shapes + shapes + longer + circular with spikes + indicate tech upgrades? + swarf, reel, tokamak + do this in draw or in verticies? + draw can have different colors + +player got stuck inside block that wasn't pick up able + +tech - killing a mob heals for the last damage you took + disable cloaking heal? maybe you don't need to disable, just don't heal twice + heal for 50%? + heal from mob damage or from kills? + +on sucker mob death trigger radiation damage AoE and a graphic (Hawking radiation) + +tech prismatic laser - cycles between different laser colors every 1-2 seconds + + +When you destroy an enemy’s shield it causes a large explosion. Requires not bubble fusion + +sword slash for plasma torch (giving up on this for now, had trouble making graphics look good) + activates when mouse is close to player + gradual activation + sharp cut off + use length of torch as cut off length + make it look like hollow knight slash + what about upgrades to extruder,plasma ball + give them their own version of a slash? + make a tech that buffs the slash, but it disables extruder,plasma ball + + + +more (all) bosses need to be made of parts + good examples: spiderBoss, dragonFlyBoss, beetleBoss + methods: + spawn adds in phases, like beetle and tether + constraints, like spider + be nice if each constrained part does something different + constrained mobs that regen after phases + flock, like cellBoss, blockBoss + Bosses that could be converted to more parts + "orbitalBoss", "shooterBoss", "bomberBoss", "launcherBoss", "laserTargetingBoss", "streamBoss", "pulsarBoss", "grenadierBoss", "blinkBoss", "laserBombingBoss", "blockBoss", "revolutionBoss", "slashBoss", "timeSkipBoss", "sneakBoss" + "sneakBoss" could get sneaker adds after each hide phase + "laserTargetingBoss" could have close range stabbers constrained, a few long range shooters, and a few laser shooters + +defense power up - a short term defense boost, like the ones for damage. + Or maybe it would last until you take one hit. + Or last until you lost a total of 20 health. + +use cross product rotation for other mobs? + snipers, shooters? + //gently rotate towards the player with a torque, use cross product to decided clockwise or counterclockwise + const laserStartVector = Vector.sub(this.position, this.vertices[this.swordVertex]) + const playerVector = Vector.sub(this.position, m.pos) + const cross = Matter.Vector.cross(laserStartVector, playerVector) + this.torque = 0.00002 * this.inertia * (cross > 0 ? 1 : -1) + +super-bot: fires super balls + +tech: after a needle hits a mobs + the needle splits into 3 needles? + reset your fire CD? + fire again for zero ammo + 2x damage for each consecutive mob hit? + +mob non-combat behaviors, like Rain World + gathering + blocks + eating blocks to heal? + power ups + eating power ups and ejecting them on death + flocking + grouping near mobs + keeping distance from mobs + sharing velocity with other mobs: boids + wander + random walk with a bias towards the player + play + fight other mobs + +consider increasing the base player horizontal movement + maybe only increase ground movement, air control seems fine + would this unbalance any maps? + +tech stubs should be a tech unlocked by skins + nitinol, tungsten? + maybe give another benefit? + defense? + make a shared variable for skin defense, since you can only have one skin + +make a lemming that walks until it hits a wall and then turns around robotically + body or mob? + can't be killed? + +mobs attack mines + mines periodically set all mobs to have player location to be the mine + is this going to work with all mob vision types? + +tech circular polarization - wave gun bullets move in a circle + +Tech: relativity + Simulation speed scales with movement speed. When still, time moves at 0.4 speed, at full walking speed it’s 1. (So if you’re falling or something and you move faster the simulation will be faster than usual) + Also a damage and/or defense boost to make it worth using + +wormhole tech - teleport away mobs with mass below 3 when they get too near the player + short CD, small energy cost, only mobs below a mass + +tech: Bose Einstein condensate - freezes enemies in pilot wave, and drains some energy? + +mob status effect - vulnerability + mobs take 4x damage for __ time + afterwards mobs go back to normal damage taken + graphical effect while they take extra damage + needs to come from a "rare"ish effect + merge with the decloaking damage effect + decloaking gives all mobs (nearby??) a 3x damage taken status? + this can be merged with the stun crit damage tech + also the increased damage every hit tech? + bad idea because the graphical effect will be too annoying + +tech: sporangium that grow little trees + the trees have an area of effect damage for about 6-10 seconds + maybe something similar to radioactive drones, but maybe a few smaller shapes + +hookBoss fires a hook that pulls player towards it + hook does a bit of damage + player targeted unless cloaking + also add effect to finalBoss + +mob status effect - emit - mobs fire lasers for a few seconds + tech: phosphorescence - mobs emit after being hit with laser beams + +Tech: "Solid rocket motor": Missiles would start at 300% speed and 200% missile damage upon explosion, but the speed and damage would decrease to 40% speed and damage as time goes on +tech: every time shotgun fires it's a different shotgun mode: nails, ice, needles, worms, fleas, rivets, ... but you get more ammo + +for tech power ups no tech options are displayed until you research once + or display only JUNK until you research once + increase the number of options after each research + +When receiving damage, in addition to becoming invulnerable to attacks, also become intangible for the set period of time + +tech increase max energy and energy to 5000, but you can no longer regen energy through any process + +it would be nice if there was incentive to go slow when choosing tech so n-gon is more relaxing + add some css based visual effects for opening up a tech,gun,field + +make a new coupling effect for perfect diamagnetism + +make a faster smaller version of cell boss that also has map collisions + +laserMines need a copy of laser-bot method + this is a very rare bug, so not a priority + +JUNK tech description that changes similar to cards in inscription + that changes based on mouse position + can you tell if mouse is over card? + +PWA? + https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps + https://codeburst.io/how-to-easily-turn-your-static-website-to-a-progressive-web-app-pwa-b0af08da9693 + https://github.com/landgreen/n-gon/pull/32/files + +Tech:when relay switch/flip flop is on, turn ammo powerups into boosts, when relay swicth/flip flop is off, ammo powerups remain ammo powerups + or toggle other power ups + health/ammo + +complete blowSuckBoss... or don't + +tech: laser reflections increase damage + +JUNK tech different effects based on night or day + use system time + +Boss that shoots out a ring of bullets, then after a few seconds it gravitates the bullets back + +tech give laser mines more lasers (3->4? 5?) + +rewindBoss: after hitting 1/5 damage thresholds the boss rewinds back in time to where it was a few seconds ago + track it's data like player history + +make orbitals increase orbital rotation speed after Orbital boss takes damage + +worms can target player, buff their damage + can't target player in first few seconds? + +plasma field tech - similar to regression, but for plasma ticks + +greatly increase walking speed + not mid air control? + for time dilation field + make jumping normal + +junk tech: charged shot +immediately fire all of your ammo + +after taking damage explode while invulnerable + scale explosion radius with damage + +tech: get sent to a new tab that closes in 3 minutes + in the new tab you play reactor + if you die in reactor you die in game, if you win you get 2-3 tech in the original game? + give player equipment like many-worlds + count guns, field, tech and give random stuff on new tab + i-frame instead of tab? + +tech: missiles explode a 2nd time after 1/2 a second (with a slightly different position determined by original velocity) + +seed isn't working right from shared URL + +mob mechanics + bullets hit player and stay attached for 4-5 seconds, slowing player + hopperBullets? + black hole sucker effect on tail + vines + attached to map and grows, a series of spheres connected by vines + if node dies it's removed from tree + vine do + keeps track of connection tree + nested object with nesting to show connection + spawns new nodes + draws connections as quad lines + +standing wave no longer pushes mobs away, but it can do damage to mobs caught in area effect + Standing wave harmonics no longer deflects, but instead discharges excess energy as lightning toward nearby enemies +negative mass field does damage to mobs inside field + combine with standing wave effect? pilot wave? + +store value of last hit health lost + tech: killing the mob that caused the last hit spawns a heal power up equal to 1/2 of last hit + time limit for effect? + need to also store who hit player + +add small SVG pics to in-game console + when? + one for each field? + use stuff on physics notes: +simulation.inGameConsole(` + + + + + + + + + + +`); + +path-finding + build a path-finding map on level load + how to convert vertices into block grid? + check points for map collisions and build grid + is there a path-finding algorithm for vertices, instead of block grid + use for: + mobs, + drones? + bots that can go far from player and return + +make plasma ball power up and block pick up still work when you have no no energy + make a unique CD var for plasma ball? + +tech: entropic gravity - gain defense for each research + requires wormhole or pilot wave or negative mass field? + +mitosis: after needle,bullets or rivets hit a surface split off into two smaller less damaging versions that have their velocity reset -firerate + +after killing a mob go invulnerable for 1 second + critical hit with laser, harpoon, nails, needle, rivet + +spawn 2 bots after exiting 1 level + or spawn 3 after 2 levels? + (randomize 2-5 bots) + replace all bot tech with this? + +cloaking field + for 6 seconds after de-cloaking tell all active mobs that the player is in the wrong position? + how to code? + just delay setting the m.isCloak for a couple seconds + and also set all active bots to remember player in the de-cloaked stop + +scrap bots can't move? + only works for nail, foam, laser + might be tricky code? + make a new bot type called scrap bot? + +JUNK tech: Pacifism + You cannot attack mobs, mobs cannot attack you + over write the mob.damage and player.damage methods + +mob mechanic: beacon + periodically add locations to an array + teleport back to a location in the array + at random + if velocity not facing player? + +super balls do more damage after bouncing? + how to check for bounce? + maybe just increases damage after hitting a mob + +super short range foam that acts like flame thrower + high fire rate + short life spawn + start large? + extra ammo? + or only 1/2 of ammo is used? + +laser tech where bots move around and follow you while firing lasers in the direction you are looking + they fire when you fire? + they aim at player history aim location, with 1s delay + bots position spread out perpendicular to the direction you are looking + can they get stuck? + maybe absolution position, no collide + do they need to be physics objects then? + make a special bot type for this + beam is similar to diffuse beam + + + + +double research + +map ban option in settings + dropdown list with checkboxes by each map + +bullets that can target the player + occurs if no mobs targets around + worms? drones? missiles? spores? + all of the above? + +Currently, the mob just deals higher damage on impact, which is annoying although not hard to compete with nor unique +By "redesign" I mean replacing instances of the regular mob, since the same code is used for the tiny red projectiles (I think) just add a new mob and remove the old one from the rotation +The new mob should be as such, a "real" exploding mob: +Deals regular damage on impact, but breaks apart on touch into several red dots (like the ones thrown out by the going through walls boss) and a chance for also throwing a bomb or two (increases with difficulty) +If the mob is close to the player or heading into the player fast it will shatter as well (and the projectiles will inherit its speed) +By a formula such as +ShouldShatter(distToPlayer, speed) = distToPlayer * speed > threshold +Optionally (and a part I can do as I'm good at it and it doesn't revolve around a lot of functional code which you don't like other people doing): +Color changing based on the mob explosion status +Regular state: red +About to explode: animation to dark red +Exploding: several shockwaves from the explosion points and tiny trails given to the shrapnel for a second or two until they deaccelerate + +pause time like invariant for other things... + throwing blocks + charging railgun + charging anything? + +guntech fire a bullet that fires nail fragments after 1s in the same direction as the original bullet + like overwatch roadhog + +bring back: + the old phase decoherence field + make cloak only active on input.field down + could be a tech + would need some other buff + how to make it good enough + combine with not killing tech? + stun mobs that touch you while phased + firing doesn't exit you from cloak + but it does drain some energy + tech pilot wave: Bose Einstein condensate - freeze mobs in superposition with pilot wave + +tech: plasma drip + +plasma ball + graphics should look more like a real plasma ball + gently scale damage with circleRadius + balance corona discharge + delay on returning to player is annoying + scale float effect with ball size + tech upgrades + greatly improve floating effects while holding + black hole: gives the plasma ball gravity + stun on expansion + plasma orb increases in size and power as it eats enemies + while attached? + +flashlight effect + make level.do() graphic that only shows direction player is facing + pattern it after cloaking field, or timeSkipBoss + will it work with cloaking field at the same time + +double jump? + +tech: coyote time + you can still jump for 2 seconds after falling off a ledge + make it a JUNK tech? so you can keep the name + some other benefit + reduce your gravity also? + increase jump? + +tech smoke grenades - mobs inside a cloud can't see player + draw on the region so it's hard for player to see as well + you'd have to make something similar to MACHO that exists after an explosion goes off + maybe just keep it simple: + stun mobs for a long time, and draw a 99& alpha grey circle for the same time + don't worry about mobs seeing you inside the circle, the circle is kinda small so it doesn't matter + + +tech mines: mines fire _____ instead of nails + needles + super balls? + foam? + +tech: frozen mobs die at 10% life + +tech: harpoons stick into enemies + detonate after a short delay + attaches mob to wall if possible + firing while harpoon is stuck into an enemy rips it out of them, inflicting damage and stun and pulling them towards you + + + +enemies stuck with foam receive upward force over time + only form aerogel tech? + +Tech: superglue +Requires: foam + another gun or plasma torch or molecular assembler + Foam bubbles decay 50% slower + Enemies stuck with foam cannot move + Foam does 0 damage + Enemies stuck with foam take 25% more damage + should foam bots gets this also or is that too strong + +const ctx = canvas.getContext('2d', {‘willReadFrequently': true}); + +//deal with game crashes? +canvas.addEventListener("contextlost", onContextLost); +canvas.addEventListener("contextrestored", redraw); +ctx.reset(); + +a mine tech that makes mines you can stand on + works similar to the field block throwing system + but you don't need to find a block to throw + blocks explode after mobs touch them + or 3 seconds after you touch them + benefits from all block tech + +go non-collide with mobs when immune to damage? + +mobs that are invulnerable from the front + +vertical reversed version of reservoir level, start at top and press buttons to lower slime + mechanic: push a very large block into slime in order to stand on it and avoid slime + +add anticipation to more mob attacks + stabber + striker + +can mob bullets damage other mob? + maybe if they switch collisions and classType === "body" or obj.classType === "bullet" + +figure out how to get friction effects on map/body to apply to player +also horizontal moving platform? + +growBoss and cellBoss are too similar + +variant of Occam's razor - remove 50% of your tech for each removed get: + 2 bots? + 50 energy max + +tech immune to harm after mob kill + require no other mob kill tech? + cloaking field tech? + +final boss invulnerability + until mobs are cleared? + in between phases + for all of one phase + +JUNK tech - do something fun to the mob display health method + +new platform element, spring + toggle to on when player touches platform + platform extends in any direction + +boss that gives nearby mobs invulnerability + invulnerability needs to toggle off and on + boss is only mildly aggressive + repulsed by player up to a point + attracted to mobs + +training + save training level progress as local variable + reset progress to zero if you clear all training levels + maybe only save progress if you made if past the trainingHeal level + make the training button more obvious if the account has only played 1-2 times + larger? + position? + animated text? + uses the lore voice/text code? + replace all mob clear triggers with button triggers? + tutorial rooms: + look around with your mouse? + easier deflecting level, with 1-2 attacking mobs + gun rooms: (different mobs type in each room) + different mobs in each room + how to introduce mob shields? + "hopper" "slasher" "shooter "grenadier" "striker" "laser" "stabber" "springer" "pulsar" "launcher" "launcherOne" "exploder" "sneaker" "sucker" "sniper" "spinner" "grower" "beamer" "focuser" "spawner" "ghoster" + spores - use 1 ammo to take out several mobs at once, you have to block with your shield until the mobs die + drones - use mouse to bring drones around a couple corners + foam - slow boss mob, and run away + laser - reflect off walls to hit mobs + field rooms: + standing wave - bullets come from every direction + perfect diamagnetism - drop field to rapid stream of bullets and fire gun at them + negative mass - fly over a bunch of ground based mobs , hoppers + molecular assembler - guide drones around the corner + plasma torch - nothing fancy, just kill mobs + time dilation - get past some mobs + cloaking - sneak past mobs to collect some heals + pilot wave - toss blocks at mobs + worm hole - teleport past lasers + puzzle/platforming rooms: + use the double constrained platforms + stealth room + probably should make 2+ + combat rooms: + boss gauntlet, spawn with nothing but a few power ups and fight 10 bosses + use no gun, just bots to kil stuff + +balance time dilation with bose einstein (you can freeze everything and take no damage) + code is still there, need to balance + balance with energy drain? + +make a line of constrained mobs move like a snake + apply forces with directions determined by time and position on the snake + +tech: basic research - heal power ups spawn as research power ups instead, and using research heals you (needs to be pretty low, like 3% health) +tech: maintenance - heals no longer spawn, but using research heals you 100% + +foam tech - make it move slower, last much longer, and push away other foam bullets + not sure about bouncing off walls, but that might be fun too + +tech extend fracture analysis to give bonus damage to frozen also, but reduce the 400%->300%? + +pulsar mobs retarget too easily +also they drift around too much + +convert blocked mobs into bullets + only for the very small bullets that move fast after being blocked + delete bulletmob and spawn a nail-like bullet with the same properties as the bulletmob + +electric motors: increases movement speed and jump height, but jumping and moving costs energy + overwrite the key event listeners? + JUNK tech? + +mob that fires bullets in 4,5,6,7 different directions at once, no aiming + grow a bit before it fires to indicate state + +quasarBoss: inverted pulsar boss that hits everything except where its aiming + +intro map: diegeticly draw a mouse with field highlighted + also indicate space? + dynamically adjust drawing after picking up a gun + +give history boss legs? + +field tech - disable blocking, but does high damage to mobs inside field + and maybe slows mobs it damages + +mob/boss that fires a laser at player, but give player time to avoid + laser isn't always on + they target where player was 1 second ago + they turn to face player? + +Plasma Burner: upgrade for plasma torch, basically just a jet engine. does high damage, but short range, mostly for player movement. + maybe reduce gravity to really low then apply a vector away from mouse direction + +auto-gon - auto battler with n-gon mob AI and tech + you build a group of mobs and bosses from n-gon + they fight other mobs and bosses + similar research and tech system to n-gon + some mobs can fire player weapons + +Pilot wave tech + Energy use is increased, but you can now shape blocks using pressure + Grouping blocks will merge them into a massive ball + Size, density is determined by total mass + +aoe effect pushes mobs away, then rapidly pulls them in + for mines? + +mob: spawning seekers on death + +drones can combine with other drones to get bigger? +drones that grab powers ups can grab more then one and get even bigger each time + +it would be helpful if there was a mechanism to recover mobs that fly off the map + add a ceiling system and a left/right walls system similar to the floor checks but only for mobs +make non moving bosses not move after getting hit + shooter, shielding, + +scrolling console history in pause menu? +pause should at least show the last in game console message + +in testing mode console log the body you click on + +tech: Standing Wave: Shockwave. Use FIELD button to shrink your shield and charge up, release to unleash a Shockwave. + +tech: quantized shields - harmonic standing wave field can only lose 33 energy per hit + draw 1,2,3 levels of the field based on energy? + the blocked value only scales up to 2x or 4x (33 energy) blocked + doesn't stack with spherical tech + +make a tech that improves all charge guns + for: pulse, foam, railgun + effect: + faster charge rate? + fire speed already does that... + harm reduction while charging + less ammo/energy used while charging? + +tech plasma : plasma length increases then decreases as you hold down the field button (like stabbing with a spear) + grows to 1.5 longer after 0.3 seconds, then returns to normal length over 1 second, until field is pressed again + extra energy is drained when field is longer + +energy conservation 6% damage recovered as energy + there is space for a negative effect in the text... + +tech: use the ability for power ups to have custom code + (note: this code is half way done, it just needs to be completed) + attracted to player + attracted to other power ups + explode if they touch? + +apply the new gun.do functions to other guns + railgun + crouching missile? + works similar to foam + performance issues? + +look into improving mouse lag with pointer lock? +https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API +https://www.vsynctester.com/game.html +https://news.ycombinator.com/item?id=26530272 + +tech: time dilation - when you exit time dilation rewind to the state you entered + position, velocity, and health + no energy cost + +be able to open up custom mode in the normal game + might need to be rebuilt from scratch + while in through testing mode? + have a way to make limited changes as allowed by tech you pick up in game + disable the in custom setting flag + +make different move methods + tech crouch charge jump + tech double jump + +tech when mobs are at full health you do 40% to them + +tech- move super fast, go intangible, drain energy very fast + this is like a dodge roll + tech for standing wave?, cloaking? + +tech pilot wave: mini black hole - pull mobs and blocks in with more force + also from farther away + also do damage? +tech pilot wave: antigravity - blocks have no gravity for a few seconds after exiting the field + maybe they bounce too? + maybe they explode? + +new power up - increase damage and fire speed, for 15 seconds + named boost? + enabled by a tech + power up color: ? + how to indicate effect duration + or just give the effect after picking up a reroll + +tech- do 50% more damage in close, but 50% less at a distance + code it like techisFarAwayDmg + have these tech disable each other + +new status effect: weakness, mobs do 75% les damage + graphic indication? + +new status effect: fear - push mob away from player for a time + +new status effect - apply status effect to mobs that makes blocks attracted to them + only lasts a few cycles + or zero cycles and it doesn't need to be a status + +have some mobs spawn in later in the level (in hard and why modes) + where + at defined points in array levelSpawns = [{x:0,y:0},{x:0,y:0}] + store the locations of mobs when the level starts to use as respawn points + remove the locations that are close to player + when? + after some mobs are dead + after the boss is killed + +look for tech that could update description text with count and tech is information + can only use variables that change in effect() and remove() + this.description = `8% chance to duplicate spawned power ups
chance to duplicate = ${techduplicateChance}` + +use mac automator to speed up your n-gon -> git sync + +movement fluidity + let legs jump on mobs, but player will still take damage + like: ori and the blind forest, celeste + many of the movement abilities in these games require levels to be built around the ability + general feeling of responsiveness and control + coyote time: can still jump a few cycles after leaving ground + tech double jump + tech air dash + tech wall jump + wall grab? + maybe remove falling damage and block damage? + +have a mob apply a positive status effect on other mobs, + heal? + make it yellow + damage bonus, but how? + possible balance issues + +css transition for pause menu + +animate new level spawn by having the map aspects randomly fly into place + +n-gon outreach ideas + blips - errant signal on youtube + reddit - r/IndieGaming + hacker news - show hacker news post + twitch - lets play + +******************************************************** LEVELS ******************************************************** + +map: observatory + button controls rotation of telescope + laser beam shoots out of telescope + button opens the dome + +level with mobs that follow a genetic algorithm + mobs have genes + the last mob that did damage saves it's genes to local storage + new mobs have the saved genes, but with some random mutations + mutations need to be balanced to prevent a gene from moving towards infinity + total genome must equal 1 (100%) + binary genes have a flat cost + example: phasing through walls might cost 0.2 + spectrum genes have a rate + example: acceleration cost 0.01 per 0.001 + possible genes + genes should only effect it's ability to touch the player + so not damage? + genome: spectrum + acceleration + top speed / air friction + damageReduction + duration? + health decreases naturally? + or they just go away like bullets? + spawn rate + look frequency / memory? + genome: binary + go through walls + blink/teleport (like striker) + grow when near target + split into two + shielded + occurs in a specialized level + named: gene lab, gene factory, genetic lab, genome facility + in the level sequence after lab and before gauntlet? + level ends after a period of time + exit is hidden until time is up and it appears + the level tests player durability/evasion + this is a nice contrast to the final level that tests damage output, and the gauntlet which tests AoE damage + +rename intro level to something lore related + +buttons can now on/off boosts + +repeat map in vertical when you fall teleport to above the mab, as if the map repeats + camera looks strange when you teleport player with a high velocity + +map element - player rotates a rotor that makes a platform go up or down + +level element: a zone with wind, anti-gravity, extra gravity + control with button + +******************************************************** MOBS ******************************************************** + +mob that charges up and then fires many bullets at once in a connect + +mob that draws a lin from it to the player, and past. then it charges across that line + +mob that spawns eggs after they die + eggs don't attack but grow back into a mob after about 10s + +mob mechanics + use the force at a location effect, like the plasma field + Matter.Body.applyForce(who, path[1], force) + +mob - after taking damage + release seekers + teleports + +hop boss: + AoE damage when landing + pull in player? and blocks? + extra gravity on falling? + immune to damage while falling? + +mob: molecule shapes - 2 separate mobs joined by a bond + use constraints: just spawn 2x or 3x groupings + low friction so they can spin around + spin when attacking player? + increase constraint length when attacking + +Mob: "Tentacle": Sits on wall. Is a black blob. When you get near it, reaches out and grabs you, similar to wires. Does not deal damage. + maybe it could be immune to damage? but it is spawned by an actual mob + +level Boss: fractal Sierpiński triangle + https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle + spawns a 1/2 size version of the boss, this version can also spawn a smaller version, but it is capped at some size level + they spawn once at the start of the level + if a version dies, one can be replaced every ten seconds by the largest version + +mob: wall mounted guns / lasers + not part of randomized mob pool, customized to each level + +level boss: fires a line intersection in a random direction every few seconds. + the last two intersections have a destructive laser between them. + +******************************************************** SOUND ******************************************************** + +add sounds + https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode + https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Advanced_techniques + style + interesting chords, like music, mixolyd + can fade into the background + chords gradual rise and fall in volume + shouldn't be traditional effects + adjust volume with distance + mute option to settings + end all sounds with each new level + write some functions to produce sounds + will this effect performance? + https://padenot.github.io/web-audio-perf/ + "Web Audio API implementation use two threads", so it probably isn't much of an issue + when to make sounds? + if near some strange thing in the level + after grabbing a power up, in the selection menu + from mobs, damage,inside field + when activating fields: time, negative mass, + + //setup audio context + function tone(frequency) { + const audioCtx = new(window.AudioContext || window.webkitAudioContext)(); + const oscillator = audioCtx.createOscillator(); + const gainNode = audioCtx.createGain(); + gainNode.gain.value = 0.25; //controls volume + oscillator.connect(gainNode); + gainNode.connect(audioCtx.destination); + oscillator.type = "sine"; // 'sine' 'square', 'sawtooth', 'triangle' and 'custom' + oscillator.frequency.value = frequency; // value in hertz + oscillator.start(); + return { oscillator: oscillator, audioCtx: audioCtx } + } + // https://www.fresnostate.edu/folklore/Olson/JUSTINT.HTM + // mixolyd. C D E F+ G A+ B + // key=G 264 297 330 356.40 396* 445.50 495 + // const t264 = tone(264) + // t264.oscillator.stop(t264.audioCtx.currentTime + 2) //in seconds, not milliseconds for some reason + // tone(297) + // tone(330) + // tone(356.40) + // tone(396) + // tone(445.50) + // tone(495) + +******************************************************** IMAGES ******************************************************** + +process: discord midjourney prompts -> "pixelmator pro" adjust color, repair, scale to 384x256, export PNG -> webP? -> place in /img folder +make n-gon a progressive web app to manage image downloads, cache +wave function collapse opens the pause menu after it triggers alternate reality + this is actually good, maybe reuse this code to get pause menu to open at any time +if pause is pressed while selecting power ups, display pause menu on top of selection menu +***styles*** + try --- Pastel drawing, Psychedelic art, Arabesque (cool patterns), knolling (everything spread out and placed on a flat mat) + try taking screen shots of fields graphics and feeding them into midJourney V4 + technology stuff --- Dan Matutina (cute complex technology), + Katsuhiro Otomo (intricate space technology), Tsutomu Nihei (black and white detailed future tech) + infographics of all know multiverses. 1980s Japanese graphic design, dimensional astrolabe, + Japanese poster graphics, Ralph McQuarrie (looks like star wars), Simon Stålenhag (retro-futuristic), Yoshiyuki Tomino (detailed anime future technology) + isometric: low-poly, box cutout, made in blender, Materials: matte clay + subtractive sculpture + kinetic sculpture + quantum stuff -- Hypertorus, Glowing Opal Pearlescent, Physics, Hydro-Dipping Hydrodipped, Vija Celmins, Matt Molloy (photo of golden waves in the sky) +***maybe redo*** + laser + supercritical fission +***past style themes*** + base prompt for player on 5.2: clean white robot spherical turret on bird legs test chamber + standing wave - a 3-D cyan transparent nested concentric aligned centered sphere with rings + by Philippe Starck + perfect diamagnetism - physics magnetic field chalk diagram + time dilation - graphic of a hyperbolic equation Luminogram + negative mass - Blacklight painting by Moebius + plasma torch - by Dan Mumford + + metamaterial cloaking - Scientific photography by Miki Asai, by Bruce Munro + molecular assembler - by Laurie Greasley 16-bit Isometric + wormhole - by Tim White + pilot wave - none + + nail gun - Screenprint + shotgun - blueprint by Dan McPharlin + grenades, missiles, explosions - vibrant fireball explosion sonic shockwave ring art by Victo Ngai --ar 3:2 --v 5 --s 750 + spores - turquoise black spores on a white background full color scientific anatomy by Ernst Haeckel + drones - insect quadcopter tilt-shift photography + super balls - By Akari Toriyama + wave - sound wave oscilloscope by Paul Catherall, concentric circles by Paul Catherall + Barbara Takenaga's painting depicting a clean sound wave on aoscilloscope device --ar 3:2 --v 5 + foam - black blobs Ink doodle + harpoon - iron harpoon on a rope weapon art white background by Eiichiro Oda --no fish --ar 3:2 --v 5 --s 750 + mine - by Dan McPharlin + laser - complex optical scientific equipment + knolling photography + + guns, ammo - isometric clean pixel art image cutaway of , style of tekkonkinkreet + defensive - Paper cutout + bots - hovering drone by Laurie Greasley 16-bit Isometric + generic energy tech - by Laurie Greasley + duplication, cancel - by Kazumasa Nagai + anti-shear topology, fracture analysis, shear stress - Chemigram + ON/OFF - ASCII art + block throwing - Bauhaus style + tech that adds JUNK - by Choi Jeong-hwa + ice IX - microscope images of ice crystals + tech that spawns health - glowing green balls by Enki Bilal + invulnerable - by Nick Veasey (photos that look like x-rays) + alternate reality - Fractal art + tech choice - mandala tile Mosaic + time, CPT, pause - by Lee Bontecou + boost, coupling power ups tech - cyan electron orbiting a black nucleus electric field as bas-relief //(by Kazumasa Nagai) + radioactive - volumetric atomic nucleus diagram by Paul Catherall + +******************************************************** LORE ******************************************************** + +look up sci-fi science ideas here https://projectrho.com/public_html/rocket/ + +possible names for tech + sidereal - with respect to the stars (an extra rotation for time keeping) + entropic gravity - gravity is emergent in a holographic way + (maybe a field tech for negative mass) + hypergolic - A hypergolic propellant combination used in a rocket engine is one whose components spontaneously ignite when they come into contact with each other. + swarm intelligence - for a drone tech + metaheuristic - is a higher-level procedure or heuristic designed to find, generate, or select a heuristic (partial search algorithm) that may provide a sufficiently good solution to an optimization problem, especially with incomplete or imperfect information or limited computation capacity + stochastic optimization + electrostatic discharge + Gödel's incompleteness + quantum zeno effect (perturbation of a system prevents some systems from evolving because it scrambles coherence) (apply to lasers, fields) + counterfactual - something false + regression to the mean + phlogiston theory is a superseded scientific theory that postulated the existence of a fire-like element called phlogiston + Laplace's demon was a notable published articulation of causal determinism on a scientific basis by Pierre-Simon Laplace in 1814.[1] According to determinism, if someone (the demon) knows the precise location and momentum of every atom in the universe, their past and future values for any given time are entailed; they can be calculated from the laws of classical mechanics. + evolutionary cosmology + eternal inflation + hypergraph + SQUID (for superconducting quantum interference device) is a very sensitive magnetometer used to measure extremely subtle magnetic fields, based on superconducting loops containing Josephson junctions. + Josephson junction - superconducting junction used in SQUIDS and quantum computers + nuclear pasta - hard matter in neutron star + nonlocal, nonlocality: maybe use for pilot wave + fine-tuned universe + nonperturbative + D-branes + instanton or pseudoparticle + soliton (wave packet) + hall effect thrusters + spaghettification + particle accelerator + superluminal signalling + NP-complete + lenticular lens: is an array of lenses, designed so that when viewed from slightly different angles, different parts of the image underneath are shown. + p-hacking JUNK tech + https://en.wikipedia.org/wiki/High-entropy_alloys high yield strength and low ductility, high temp resistance + https://en.wikipedia.org/wiki/Refractory_metals hard, high temp resistance + https://en.wikipedia.org/wiki/Upper-atmospheric_lightning#Elves + prion quine - self replicating protein + Unitarity - https://en.wikipedia.org/wiki/Unitarity_(physics) - all probabilities add up to 1, calculations work the same forward and backwards in time + this is violated by expansion of the universe + https://en.wikipedia.org/wiki/Cosmic_censorship_hypothesis - black holes can't leak + Alcubierre warp drive (FTL with negative mass) + Spherules - A spherule is a small sphere or spherical body. It can also refer to a thick-walled spherical structure that contains endospores and occurs in the parasitic form of fungi + negative entropy + memetics + magnetorquers - produce spin by pushing on earth's magnetic field + Josephson junction - superconducting junction + Pyroelectricity - voltage from temp changes - upgrade from piezoelectricity + Unruh effect - accelerating makes heat/thermal particles + configuration space - holds the position of everything (related to fermions/bosons and particle interactions) + stress–energy tensor + radioisotope thermoelectric generator - + retrovirus: these things make JUNK DNA so link it somehow to that tech? + Upon infection with a retrovirus, a cell converts the retroviral RNA into DNA and sometimes the DNA will be passed on to progeny as JUNK DNA + amalgam, amalgamation - the action, process, or result of combining or uniting. + thermoplastic - the stuff in 3-D printers, use for molecular assembler tech + ergosphere - region of a spinning black hole that might allow FTL or alternate realities. + equivalence principle - gravity and acceleration are the same + Casimir effect - attractive force between two close conductive plates + difference engine - early calculator/computer + cyanoacrylate - superglue use for a slowing effect? + superposition - something with waves overlapping + math terms - integral, derivative, Laplace transform, inflection point + quasicrystals - something with low friction, maybe defense? + Coalescence - things merging together like clouds. maybe mergin power ups? + trihydrogen cation - common molecule in space, dark matter tech? + superradiance - laser tech + cryocoolers - freezing effects + metaphysics - maybe this changes something deep and universal about physics? not sure + cork - used as a heat shield for rockets + P = NP - something with speeding up calculation times + transistivity - something where a>b and b>c -> a>c + lenticular - looks different from different angles (lasers?, cloaking?) + every few seconds pick a random skin tech? + De Sitter space - simple model of universe related to general relativity (mass-energy?) + active optics - something with lasers? maybe something with diffuse beam getting smaller + Quintessence - related to dark energy + biofilm - something defensive? related to spores? + +******************************************************* DESIGN ****************************************************** + +priorities + synergies between tech + difficult to achieve synergies that feel so powerful they are game breaking / changing + randomized content that adds repeatability + bosses, mobs, levels, tech + graphical indicators of tech effects and quantity + subtle lore woven into unexpected places + +add more randomize sub level map content + left/right sides of lock + small lab rooms + +list of powerful synergies + CPT + high energy regen + research + bot fabrication + ersatz bots + various bot upgrades + harpoon + high fire rate + alternator + time dilation + duplication 100% + interest + coupling, research + (peer review? or Bayesian statistics) + electronegativity and high energy? + electronegativity + anyon + duplication + Maxwells demon + interest + pair production + chain reaction + invulnerable + Abelian group + parasitism = clear all mobs on level + + +************************************************* COMMUNITY LINKS ************************************************* + +load old commits + www.cornbread2100.com/n-gon-loader + +n-gon fork + kgurchiek.github.io/n-gon-portal-gun + 3xiondev.github.io/n-gon-upgraded + coaldeficit.github.io/c-gon + n-gon-enhanced.vercel.app + +bookmarlet + github.com/Whyisthisnotavalable/n-scythe + github.com/kgurchiek/n-gon-mobile + github.com/kgurchiek/n-gon-controller + +text + ngon.fandom.com/wiki/N-gon + github.com/3xionDev/n-docs \ No newline at end of file diff --git a/WebGames-master/WebGames-master/script.js b/WebGames-master/WebGames-master/script.js index 356b4586..9504338a 100644 --- a/WebGames-master/WebGames-master/script.js +++ b/WebGames-master/WebGames-master/script.js @@ -423,6 +423,11 @@ const mainContentData = [ image: "/WebGames-master/WebGames-master/games2/assets/vex7.jpeg", link: "/WebGames-master/WebGames-master/games2/game/vex7/index.html", }, + { + name: "n-gon", + image: "/WebGames-master/WebGames-master/assets/n-gon.png", + link: "/WebGames-master/WebGames-master/n-gon-master/index.html", + }, ]; mainContentData.forEach(item => {