├── LICENSE ├── README.md ├── crate.png ├── index.html └── lost.js /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 1024-moves 2 | 3 | Play here : https://js13kgames.com/entries/1024-moves 4 | -------------------------------------------------------------------------------- /crate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GregPeck/1024-moves/14ffb867264d0bca90cd153af0313a34be361667/crate.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | CUBE 4 | 5 | 6 | 16 | 84 | 213 | 233 | 234 | 235 | 236 | 237 | 238 | -------------------------------------------------------------------------------- /lost.js: -------------------------------------------------------------------------------- 1 | function SfxrP(){this.set=function(a){for(var b=0;b<24;b++)this[String.fromCharCode(97+b)]=a[b]||0;this.c<.01&&(this.c=.01);var c=this.b+this.c+this.e;if(c<.18){var d=.18/c;this.b*=d,this.c*=d,this.e*=d}}}function sy(){this._p=new SfxrP;var a,b,c,d,e,f,g,h,i,j,k,l;this.reset=function(){var a=this._p;d=100/(a.f*a.f+.001),e=100/(a.g*a.g+.001),f=1-a.h*a.h*a.h*.01,g=-a.i*a.i*a.i*1e-6,a.a||(k=.5-a.n/2,l=5e-5*-a.o),h=1+a.l*a.l*(a.l>0?-.9:10),i=0,j=1==a.m?0:(1-a.m)*(1-a.m)*2e4+32},this.totalReset=function(){this.reset();var d=this._p;return a=d.b*d.b*1e5,b=d.c*d.c*1e5,c=d.e*d.e*1e5+12,3*((a+b+c)/3|0)},this.sW=function(m,n){var o=this._p,p=1!=o.s||o.v,q=o.v*o.v*.1,r=1+3e-4*o.w,s=o.s*o.s*o.s*.1,t=1+1e-4*o.t,u=1!=o.s,v=o.x*o.x,w=o.g,x=o.q||o.r,y=o.r*o.r*o.r*.2,z=o.q*o.q*(o.q<0?-1020:1020),A=o.p?((1-o.p)*(1-o.p)*2e4|0)+32:0,B=o.d,C=o.j/2,D=o.k*o.k*.01,E=o.a,F=a,G=1/a,H=1/b,I=1/c,J=5/(1+o.u*o.u*20)*(.01+s);J>.8&&(J=.8),J=1-J;for(var Q,S,U,W,Y,Z,K=!1,L=0,M=0,N=0,O=0,P=0,R=0,T=0,V=0,X=0,$=0,_=new Array(1024),aa=new Array(32),ba=_.length;ba--;)_[ba]=0;for(var ba=aa.length;ba--;)aa[ba]=2*Math.random()-1;for(var ba=0;ba=A&&(X=0,this.reset()),j&&++i>=j&&(j=0,d*=h),f+=g,d*=f,d>e&&(d=e,w>0&&(K=!0)),S=d,C>0&&($+=D,S*=1+Math.sin($)*C),S|=0,S<8&&(S=8),E||(k+=l,k<0?k=0:k>.5&&(k=.5)),++M>F)switch(M=0,++L){case 1:F=b;break;case 2:F=c}switch(L){case 0:N=M*G;break;case 1:N=1+2*(1-M*H)*B;break;case 2:N=1-M*I;break;case 3:N=0,K=!0}x&&(z+=y,U=0|z,U<0?U=-U:U>1023&&(U=1023)),p&&r&&(q*=r,q<1e-5?q=1e-5:q>.1&&(q=.1)),Z=0;for(var ca=8;ca--;){if(T++,T>=S&&(T%=S,3==E))for(var da=aa.length;da--;)aa[da]=2*Math.random()-1;switch(E){case 0:Y=T/S.5?W-1:W),Y=1.27323954*W+.405284735*W*W*(W<0?1:-1),Y=.225*((Y<0?-1:1)*Y*Y-Y)+Y;break;case 3:Y=aa[Math.abs(32*T/S|0)]}p&&(Q=R,s*=t,s<0?s=0:s>.1&&(s=.1),u?(P+=(Y-R)*s,P*=J):(R=Y,P=0),R+=P,O+=R-Q,O*=1-q,Y=O),x&&(_[V%1024]=Y,Y+=_[(V-U+1024)%1024],V++),Z+=Y}Z*=.125*N*v,m[ba]=Z>=1?1:Z<=-1?-1:Z}return n}}var synth=new sy;window.jsfxr=function(a){window._audioContext=window._audioContext||new AudioContext;var b=window._audioContext;synth._p.set(a);var c=synth.totalReset(),d=c+1>>1<<1,e=b.createBuffer(1,d,b.sampleRate),f=e.getChannelData(0);2*synth.sW(f,c);return e},window.playSound=function(n){if(!sound){return;}jsfxr(n);var o=window._audioContext,e=o.createBufferSource();e.buffer=jsfxr(n),e.loop=!1,e.connect(o.destination),e.start(o.currentTime);return [e.buffer,o,e]}; 2 | 3 | glMatrixArrayType="undefined"!=typeof Float32Array?Float32Array:"undefined"!=typeof WebGLFloatArray?WebGLFloatArray:Array;var mat3={};mat3.create=function(r){var t=new glMatrixArrayType(9);return r&&(t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],t[9]=r[9]),t},mat3.transpose=function(r,t){if(!t||r==t){var a=r[1],n=r[2],e=r[5];return r[1]=r[3],r[2]=r[6],r[3]=a,r[5]=r[7],r[6]=n,r[7]=e,r}return t[0]=r[0],t[1]=r[3],t[2]=r[6],t[3]=r[1],t[4]=r[4],t[5]=r[7],t[6]=r[2],t[7]=r[5],t[8]=r[8],t};var mat4={};mat4.create=function(r){var t=new glMatrixArrayType(16);return r&&(t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],t[9]=r[9],t[10]=r[10],t[11]=r[11],t[12]=r[12],t[13]=r[13],t[14]=r[14],t[15]=r[15]),t},mat4.identity=function(r){return r[0]=1,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=1,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=1,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1,r},mat4.toInverseMat3=function(r,t){var a=r[0],n=r[1],e=r[2],u=r[4],i=r[5],o=r[6],f=r[8],m=r[9],c=r[10],v=c*i-o*m,y=-c*u+o*f,l=m*u-i*f,s=a*v+n*y+e*l;return s?(s=1/s,t||(t=mat3.create()),t[0]=v*s,t[1]=(-c*n+e*m)*s,t[2]=(o*n-e*i)*s,t[3]=y*s,t[4]=(c*a-e*f)*s,t[5]=(-o*a+e*u)*s,t[6]=l*s,t[7]=(-m*a+n*f)*s,t[8]=(i*a-n*u)*s,t):null},mat4.translate=function(r,t,a){var n=t[0],e=t[1];if(t=t[2],!a||r==a)return r[12]=r[0]*n+r[4]*e+r[8]*t+r[12],r[13]=r[1]*n+r[5]*e+r[9]*t+r[13],r[14]=r[2]*n+r[6]*e+r[10]*t+r[14],r[15]=r[3]*n+r[7]*e+r[11]*t+r[15],r;var u=r[0],i=r[1],o=r[2],f=r[3],m=r[4],c=r[5],v=r[6],y=r[7],l=r[8],s=r[9],M=r[10],p=r[11];return a[0]=u,a[1]=i,a[2]=o,a[3]=f,a[4]=m,a[5]=c,a[6]=v,a[7]=y,a[8]=l,a[9]=s,a[10]=M,a[11]=p,a[12]=u*n+m*e+l*t+r[12],a[13]=i*n+c*e+s*t+r[13],a[14]=o*n+v*e+M*t+r[14],a[15]=f*n+y*e+p*t+r[15],a},mat4.rotate=function(r,t,a,n){var e=a[0],u=a[1];a=a[2];var i=Math.sqrt(e*e+u*u+a*a);if(!i)return null;1!=i&&(e*=i=1/i,u*=i,a*=i);var o=Math.sin(t),f=Math.cos(t),m=1-f;t=r[0],i=r[1];var c=r[2],v=r[3],y=r[4],l=r[5],s=r[6],M=r[7],p=r[8],A=r[9],d=r[10],h=r[11],F=e*e*m+f,g=u*e*m+a*o,x=a*e*m-u*o,T=e*u*m-a*o,b=u*u*m+f,w=a*u*m+e*o,G=e*a*m+u*o;return e=u*a*m-e*o,u=a*a*m+f,n?r!=n&&(n[12]=r[12],n[13]=r[13],n[14]=r[14],n[15]=r[15]):n=r,n[0]=t*F+y*g+p*x,n[1]=i*F+l*g+A*x,n[2]=c*F+s*g+d*x,n[3]=v*F+M*g+h*x,n[4]=t*T+y*b+p*w,n[5]=i*T+l*b+A*w,n[6]=c*T+s*b+d*w,n[7]=v*T+M*b+h*w,n[8]=t*G+y*e+p*u,n[9]=i*G+l*e+A*u,n[10]=c*G+s*e+d*u,n[11]=v*G+M*e+h*u,n},mat4.frustum=function(r,t,a,n,e,u,i){i||(i=mat4.create());var o=t-r,f=n-a,m=u-e;return i[0]=2*e/o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=2*e/f,i[6]=0,i[7]=0,i[8]=(t+r)/o,i[9]=(n+a)/f,i[10]=-(u+e)/m,i[11]=-1,i[12]=0,i[13]=0,i[14]=-u*e*2/m,i[15]=0,i},mat4.perspective=function(r,t,a,n,e){return r=a*Math.tan(r*Math.PI/360),t*=r,mat4.frustum(-t,t,-r,r,a,n,e)}; 4 | 5 | var sound = 1; 6 | var font = []; 7 | //font[0] = "111101101101111"; 8 | font[0] = "01110100011001110101110011000101110"; 9 | //font[1] = "010110010010111"; 10 | font[1] = "00100011000010000100001000010001110"; 11 | 12 | //font[2] = "111001111100111"; 13 | font[2] = "01110100010000100110010001000011111"; 14 | //font[3] = "111001111001111"; 15 | font[3] = "01110100010000100110000011000101110"; 16 | //font[4] = "101101111001001"; 17 | font[4] = "00010001100101010010111110001000010"; 18 | //font[5] = "111100111001111"; 19 | font[5] = "11111100001111000001000011000101110"; 20 | //font[6] = "111100111101111"; 21 | font[6] = "00110010001000011110100011000101110"; 22 | //font[7] = "111001010010010"; 23 | font[7] = "11111000010001000100010000100001000"; 24 | //font[8] = "111101111101111"; 25 | font[8] = "01110100011000101110100011000101110"; 26 | //font[9] = "111101111001111"; 27 | font[9] = "01110100011000101111000010001001100"; 28 | //font["A"] = "111101111101101"; 29 | font["A"] = "00100010101000110001111111000110001"; 30 | 31 | //font["B"] = "110101110101110"; 32 | font["B"] = "11110010010100101110010010100111110"; 33 | font["C"] = "01110100011000010000100001000101110"; 34 | font["D"] = "11110010010100101001010010100111110"; 35 | //font["E"] = "111100110100111"; 36 | font["E"] = "11111100001000011110100001000011111"; 37 | font["F"] = "11111100001000011110100001000010000"; 38 | //font["G"] = "111100101101111"; 39 | font["G"] = "01110100011000010011100011000101111"; 40 | font["H"] = "10001100011000111111100011000110001"; 41 | font["I"] = "01110001000010000100001000010001110"; 42 | font["J"] = "00111000100010000100001001001001100"; 43 | font["K"] = "10001100101010011000101001001010001"; 44 | font["L"] = "10000100001000010000100001000011111"; 45 | font["M"] = "10001110111010110101100011000110001"; 46 | font["N"] = "10001100011100110101100111000110001"; 47 | font["O"] = "01110100011000110001100011000101110"; 48 | font["P"] = "11110100011000111110100001000010000"; 49 | font["Q"] = "01110100011000110001101011001001101"; 50 | font["R"] = "11110100011000111110101001001010001"; 51 | //font["S"] = "111100111001111"; 52 | font["S"] = "01110100011000001110000011000101110"; 53 | //font["T"] = "111010010010010"; 54 | font["T"] = "11111001000010000100001000010000100"; 55 | font["U"] = "10001100011000110001100011000101110"; 56 | font["V"] = "10001100011000110001100010101000100"; 57 | font["W"] = "10001100011000110101101011010101010"; 58 | font["X"] = "10001100010101000100010101000110001"; 59 | font["Y"] = "10001100011000101010001000010000100"; 60 | font["Z"] = "11111000010001000100010001000011111"; 61 | font["-"] = "00000000000000011111000000000000000"; 62 | //font[":"] = "000010000010000"; 63 | font["."] = "00000000000000000000000000011000110"; 64 | font[","] = "00000000000000000000000110000100010"; 65 | //font["'"] = "001010000000000"; 66 | //font["?"] = "010101001010010"; 67 | //font["+"] = "000010111010000"; 68 | //font["="] = "000111000111000"; 69 | font["!"] = "00100001000010000100001000000000100"; 70 | font["("] = "00010001000100001000010000010000010"; 71 | font[")"] = "00100000100000100001000010001000100"; 72 | 73 | var speedZ = frame = totalMove =0; 74 | var gl, shaderProgram, shaderProgramLava, ctx, mur, red, portal, textureDoor, textureKey; 75 | var moveF = moveB = moveL = moveR = false; 76 | var UVW = []; 77 | var mvMatrix = mat4.create(); 78 | var pMatrix = mat4.create(); 79 | var lights = new Float32Array([ 80 | 0,0,0,0, 81 | 5,-5,2,2 82 | ]); 83 | var lightsDisplayed = []; 84 | var nbMoves = nbMovesAtStart = 0; 85 | var tilesColors = {length:0}; 86 | var cubeVertexIndexBuffer; 87 | var sphereVertexIndexBuffer; 88 | var coordBuffer = []; 89 | var UVWBuffer = []; 90 | 91 | var players = []; 92 | var selectedPlayer = 0; 93 | var vitesseRotation = 10; 94 | 95 | var canvas2; 96 | var canvasHUD; 97 | var GAME,camera,triggers,level; 98 | var levels; 99 | var fov = 45; 100 | var levelEnCours = 1; 101 | var levelDrawing = false; 102 | var levelExplode = false; 103 | var zoomOn = false; 104 | function drawText(posX, posY, text, scale) { 105 | var aa = ['#000','#FFF']; 106 | scale/=2; 107 | for (var j=0; j0) { 513 | p.rotation.x += degToRad(90/vitesseRotation); 514 | } else if (p.inMoveY<0) { 515 | p.rotation.x -= degToRad(90/vitesseRotation); 516 | } 517 | 518 | if (p.inMoveX>0) { 519 | p.rotation.y += degToRad(90/vitesseRotation); 520 | } else if (p.inMoveX<0) { 521 | p.rotation.y -= degToRad(90/vitesseRotation); 522 | } 523 | 524 | mat4.rotate(mvMatrix, p.rotation.x, [1, 0, 0]); 525 | switch (p.rotation.xD) { 526 | case 0: 527 | mat4.rotate(mvMatrix, p.rotation.y, [0, 1, 0]); 528 | break; 529 | case 1: 530 | mat4.rotate(mvMatrix, -p.rotation.y, [0, 0, 1]); 531 | break; 532 | case 2: 533 | mat4.rotate(mvMatrix, -p.rotation.y, [0, 1, 0]); 534 | break; 535 | case 3: 536 | mat4.rotate(mvMatrix, p.rotation.y, [0, 0, 1]); 537 | break; 538 | } 539 | } 540 | if (rotation) { 541 | mat4.rotate(mvMatrix, rotation.x, [1, 0, 0]); 542 | mat4.rotate(mvMatrix, rotation.y, [0, 1, 0]); 543 | mat4.rotate(mvMatrix, rotation.z, [0, 0, 1]); 544 | } 545 | 546 | //openGL CORE 547 | //set Shader 548 | /*switch (type) { 549 | case "ball": 550 | var shader = shaderProgramLava; 551 | break; 552 | default: 553 | var shader = shaderProgram; 554 | break; 555 | 556 | }*/ 557 | 558 | shader = type=="ball" ? shaderProgramLava : shaderProgram; 559 | 560 | if (obj.geometry) { 561 | var shader = shaderProgramLava; 562 | } 563 | gl.useProgram(shader); 564 | gl.uniform3f(shader.cp, x, y, z); 565 | 566 | //set UVW buffer 567 | var buffer = getUVWBuffer(type, height); 568 | //console.log("buffer.itemSize=",buffer.itemSize); 569 | gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 570 | gl.vertexAttribPointer(shader.textureCoordAttribute, buffer.itemSize, gl.FLOAT, false, 0, 0); 571 | 572 | //set geometry buffer 573 | buffer = getCoord(type, height, geometry); 574 | gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 575 | gl.vertexAttribPointer(shader.vertexPositionAttribute, buffer.itemSize, gl.FLOAT, false, 0, 0); 576 | 577 | //set uniforms 578 | if (lightsDisplayed.length) { 579 | gl.uniform4fv(shader.lights, lightsDisplayed); 580 | } 581 | gl.uniform1i(shader.nbLights, lightsDisplayed.length/4); 582 | gl.uniform3f(shader.ac, 0.1 ,0.1 ,0.1); 583 | gl.uniform2f(shader.res, 1920,1000); 584 | gl.uniform1i(shader.samplerUniform, 0); //Déclare la texture 0 sur uSampler 585 | gl.uniform1f(shader.it, frame); 586 | gl.uniformMatrix4fv(shader.pMatrixUniform, false, pMatrix); 587 | gl.uniformMatrix4fv(shader.mvMatrixUniform, false, mvMatrix); 588 | gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer); 589 | 590 | //draw object 591 | gl.activeTexture(gl.TEXTURE0); 592 | gl.uniform1i(shader.isPlayer, 0); 593 | gl.uniform1i(shader.cubeFace, 1); 594 | gl.uniform1i(shader.isCurrentPlayer, 0); 595 | if (type=="ball") { 596 | gl.bindTexture(gl.TEXTURE_2D, sphereTexture); 597 | gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0); 598 | } else if (type=="block" || type=="block2") { 599 | if (type=="block2") { 600 | gl.bindTexture(gl.TEXTURE_2D, tilesColors[22]); 601 | } else { 602 | gl.bindTexture(gl.TEXTURE_2D, crate); 603 | } 604 | gl.uniform1i(shader.isCurrentPlayer, type=="block2" ? 1 : 0); 605 | gl.uniform1i(shader.cubeFace, 1); 606 | gl.drawElements(gl.TRIANGLES, 36, gl.UNSIGNED_SHORT, 0); 607 | gl.uniform1i(shader.cubeFace, 5); 608 | gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 36); //Face avant 609 | gl.uniform1i(shader.cubeFace, 6); 610 | gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 36+12); //Droite 611 | gl.uniform1i(shader.isCurrentPlayer, 0); 612 | } else if (type=="player") { 613 | gl.uniform1i(shader.isPlayer, 1); 614 | gl.uniform1i(shader.isCurrentPlayer, selectedPlayer ? 1 : 0); 615 | gl.uniform1i(shader.cubeFace, 1); 616 | //gl.drawElements(gl.TRIANGLES, 24, gl.UNSIGNED_SHORT, 0); 617 | gl.drawElements(gl.TRIANGLES, 36, gl.UNSIGNED_SHORT, 0); 618 | gl.uniform1i(shader.cubeFace, 5); 619 | gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 36); //Face avant 620 | gl.uniform1i(shader.cubeFace, 6); 621 | gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 36+12); //Droite 622 | } else { 623 | if (type=="trigger") { 624 | gl.bindTexture(gl.TEXTURE_2D, trigger.color); 625 | } else { 626 | gl.bindTexture(gl.TEXTURE_2D, triggered ? tilesColors[21] : tilesColors[(x/2+(-y/2*10))%21]); 627 | } 628 | gl.uniform1i(shader.cubeFace, 0); 629 | gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0); 630 | 631 | if (type!="normal2") { 632 | gl.bindTexture(gl.TEXTURE_2D, mur); 633 | } 634 | gl.drawElements(gl.TRIANGLES, 30, gl.UNSIGNED_SHORT, 12); //Le dessous, je m'en tape 635 | gl.uniform1i(shader.cubeFace, 5); 636 | gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 36); //Face avant 637 | gl.uniform1i(shader.cubeFace, 6); 638 | gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 36+12); //Droite 639 | } 640 | } 641 | 642 | 643 | move = function(x, y, p) { 644 | if (p.inMoveX!=0 || p.inMoveY!=0 || p.inMoveZ!=0 || !p.haveControl) { 645 | return; 646 | } 647 | var oldT = level[p.tile.x][p.tile.y]; 648 | if (!level[p.tile.x + x] || !level[p.tile.x + x][p.tile.y + y]) { 649 | return false; 650 | } 651 | var t = level[p.tile.x + x][p.tile.y + y]; 652 | var t2 = false; 653 | var can = 0; 654 | var hauteur = (t.h * 2); 655 | for (var i=0; i p.z) { //C'est un mur 662 | can = 0; 663 | } else { 664 | if (oldT.p.length>1 && oldT.p[oldT.p.length-1].z>players[selectedPlayer].z) { 665 | return 0; 666 | } 667 | 668 | //En tout cas, ce n'est pas un mur qui me bloque 669 | hauteur+= t.o.length*2; 670 | if (hauteur - p.z > 2) { 671 | can = 0; 672 | } else { 673 | if (hauteur>p.z) { 674 | if (hauteur==p.z+2) { //Il y a un seul bloc 675 | if (t.o[0].type==2 && t.o.length==1) { //Ok c'est un bloc grimpable 676 | can = 1; 677 | } 678 | } 679 | if (!can) { 680 | //Il y a un object 681 | //Je regarde si je peux le pousser 682 | //Je peux le pousser si la case suivante à la même hauteur additionné des objects déjà posé ne dépasse pas la hauteur actuel 683 | if (!level[p.tile.x + x + x] || !level[p.tile.x + x + x][p.tile.y + y + y]) { 684 | return false; 685 | } 686 | var t2 = level[p.tile.x + x + x][p.tile.y + y + y]; 687 | 688 | if (t2.h*2 + t2.o.length*2 > p.z) { 689 | can = 0; 690 | } else { 691 | //Bon la caisse peut y aller 692 | can = 1; 693 | t2.o.push(t.o[t.o.length-1]); 694 | t.o.pop(); 695 | t2.o[t2.o.length-1].inMoveX = x * vitesseRotation; 696 | t2.o[t2.o.length-1].inMoveY = y * vitesseRotation; 697 | } 698 | } 699 | } else { 700 | can = 1; 701 | } 702 | } 703 | } 704 | 705 | if (can) { 706 | level[p.tile.x][p.tile.y].p.pop(); 707 | p.inMoveX = x*vitesseRotation+(x ? (x>0 ? 1 : -1) : 0); 708 | p.inMoveY = y*vitesseRotation+(y ? (y>0 ? 1 : -1) : 0); 709 | p.tile.x += x; 710 | p.tile.y += y; 711 | level[p.tile.x][p.tile.y].p.push(p); 712 | } 713 | 714 | if (can && t2 && t2.t) { 715 | actionTrigger(t2.t, true); 716 | } 717 | if (can && oldT.t && !oldT.o.length) { 718 | actionTrigger(oldT.t, false); 719 | } 720 | if (can && t.t && !t.o.length) { 721 | actionTrigger(t.t, true); 722 | } 723 | nbMoves+= can; 724 | if (can) { 725 | playSound([0,,0.047,0.5711,0.1329,0.8391,,,,,,,,,,,,,1,,,,,0.5]); 726 | } 727 | return can; 728 | } 729 | actionTrigger = function(t, state) { 730 | if (t.state==state) { return; } 731 | t.state = state; 732 | if (t.action) { t.action(); } 733 | switch (t.type) { 734 | case 1: 735 | if (!state) { 736 | return; 737 | } 738 | case 2: 739 | for (var i=0; i0) { continue ; } 743 | switchTileHeight(tl[0], tl[1], tl[2], tl[3], state); 744 | } 745 | break; 746 | case 3: 747 | for (var i=0; i0) { 788 | p.y += -(1/(vitesseRotation/2)); 789 | p.inMoveY--; 790 | } else if (p.inMoveY<0) { 791 | p.y -= -(1/(vitesseRotation/2)); 792 | p.inMoveY++; 793 | } 794 | 795 | if (p.inMoveX>0) { 796 | p.x += (1/(vitesseRotation/2)); 797 | p.inMoveX--; 798 | } else if (p.inMoveX<0) { 799 | p.x -= (1/(vitesseRotation/2)); 800 | p.inMoveX++; 801 | } 802 | } 803 | /*var target = zoomOn ? zoomOn : (p ? -p : false); 804 | if (target!==false) { 805 | camera.x-= (camera.x-(-target.x))/10; 806 | camera.y-= (camera.y-(target.y+10))/10; 807 | camera.z-= (camera.z-(target.z+20))/10; 808 | }*/ 809 | 810 | if (zoomOn) { 811 | camera.x-= (camera.x-(-zoomOn.x))/10; 812 | camera.y-= (camera.y-(zoomOn.y+10))/10; 813 | camera.z-= (camera.z-(zoomOn.z+20))/10; 814 | } else if (p) { 815 | camera.x-= (camera.x-(-p.x))/10; 816 | camera.y-= (camera.y-(-p.y+10))/10; 817 | camera.z-= (camera.z-(p.z+20))/10; 818 | } 819 | 820 | //Tmp 821 | /* camera.x-= (camera.x-(-tmpCreator.x))/10; 822 | camera.y-= (camera.y-(+tmpCreator.y+20))/10; 823 | camera.z-= (camera.z-(tmpCreator.z+40))/10;*/ 824 | 825 | 826 | //gl.depthFunc(gl.ALWAYS); 827 | 828 | /*for (var i=0; i hauteurSol) { 848 | if (p.inMoveZ==0) { 849 | p.inMoveZ = 0.1; 850 | } 851 | p.z -= p.inMoveZ; 852 | p.inMoveZ *= 1.1; 853 | 854 | if (p.z==0) { 855 | gameOver(); 856 | } 857 | if (p.z <= hauteurSol) { //Je suis descendu un peu trop 858 | p.z = hauteurSol; 859 | p.inMoveZ = 0; 860 | } 861 | } else { 862 | if (hauteurSol==-1000) { 863 | gameOver(); 864 | } 865 | if (hauteurSol>p.z) { 866 | p.z = hauteurSol + (t.inMoveZ/vitesseRotation); 867 | } else { 868 | p.inMoveZ = 0; 869 | p.z = hauteurSol; 870 | } 871 | } 872 | drawCube({ 873 | x:players[i].x, 874 | y:players[i].y, 875 | z:players[i].z, 876 | h:1, 877 | type:"player", 878 | player:p, 879 | selectedPlayer:i==selectedPlayer 880 | }); 881 | } 882 | for (var x=0; x0) { 893 | decal.x = -(--o.inMoveX)/vitesseRotation*2; 894 | } 895 | if (o.inMoveX<0) { 896 | decal.x = -(++o.inMoveX)/vitesseRotation*2; 897 | } 898 | if (o.inMoveY>0) { 899 | decal.y = (--o.inMoveY)/vitesseRotation*2; 900 | } 901 | if (o.inMoveY<0) { 902 | decal.y = (++o.inMoveY)/vitesseRotation*2; 903 | } 904 | 905 | if (h < o.z + o.inMoveZ) { //Il doit tomber 906 | if (o.speedZ==0) { 907 | o.speedZ = 0.1; 908 | o.inMoveZ = (o.z - h)*2; 909 | } 910 | if (o.speedZ>0) { 911 | o.speedZ*=1.1; 912 | } else if (o.speedZ<-0.04) { 913 | o.speedZ*=0.90; 914 | } else { 915 | o.speedZ=0.05; 916 | } 917 | 918 | o.inMoveZ -= o.speedZ; 919 | decal.z = o.inMoveZ; 920 | if (h > o.z + o.inMoveZ) { 921 | if (o.inMoveZ>-0.1) { 922 | decal.z = 0; 923 | } else { 924 | if (!t.h) { 925 | console.log(h, o.z); 926 | t.o = []; 927 | continue; 928 | } else { 929 | o.speedZ = (o.inMoveZ*0.2); 930 | o.inMoveZ = -o.inMoveZ; 931 | decal.z = o.inMoveZ; 932 | } 933 | } 934 | } 935 | o.z = t.h + i + 1; 936 | } else { 937 | if (h > o.z && t.inMoveZ<0) { 938 | decal.z = (t.inMoveZ/vitesseRotation); 939 | o.z = t.h + i; 940 | } else { 941 | o.z = t.h + i + 1; 942 | } 943 | o.inMoveZ = 0; 944 | o.speedZ = 0; 945 | 946 | } 947 | drawCube({ 948 | x:x*2, 949 | y:-y*2, 950 | z:(h-t.o.length+(i))*2, 951 | h:1, 952 | type:"block"+(t.o[i].type==2 ? "2" : ""), 953 | decal:decal 954 | }) 955 | } 956 | } 957 | var h = t.h; 958 | if (!h) { continue; } 959 | 960 | var decal = {x:0, y:0, z:0}; 961 | var rotation = {x:0, y:0, z:0}; 962 | if (levelExplode) { 963 | if (levelExplodeSince==0) { 964 | nextLevel(); 965 | return; 966 | } 967 | blocksInMove = true; 968 | t.inMoveZ += t.speedZ; 969 | decal.z = t.inMoveZ/vitesseRotation; 970 | t.speedZ-=0.2; 971 | 972 | t.decalX+=t.speedX; 973 | t.decalY+=t.speedY; 974 | 975 | decal.x = t.decalX; 976 | decal.y = t.decalY; 977 | 978 | t.speedX*=0.9999; 979 | t.speedY*=0.9999; 980 | 981 | t.rotation.x+=t.rotationSpeed.x; 982 | t.rotation.y+=t.rotationSpeed.y; 983 | t.rotation.z+=t.rotationSpeed.z; 984 | rotation = t.rotation; 985 | } else { 986 | if (t.inMoveZ) { 987 | blocksInMove = true; 988 | if (t.inMoveZ>0) { 989 | decal.z = (--t.inMoveZ)/vitesseRotation; 990 | } 991 | if (t.inMoveZ<0) { 992 | decal.z = (++t.inMoveZ)/vitesseRotation; 993 | } 994 | } 995 | } 996 | 997 | //Si il y a une tuile à gauche d'au moins la même hauteur, je n'affiche pas la gauche 998 | /*face = [1,1,1,1]; 999 | if (x>0) { 1000 | var tL = level[x-1][y]; 1001 | if (tL.h>=t.h+1) { 1002 | face[3]=0; 1003 | } 1004 | } 1005 | if (x=t.h) { 1008 | face[1]=0; 1009 | } 1010 | } 1011 | if (y=t.h) { 1014 | face[2]=0; 1015 | } 1016 | }*/ 1017 | drawCube({ 1018 | x:x*2, 1019 | y:-y*2, 1020 | z:0, 1021 | h:h-0.2, 1022 | type:"normal", 1023 | trigger:t.t, 1024 | decal:decal, 1025 | rotation:rotation, 1026 | triggered:t.triggered, 1027 | // face:face 1028 | }) 1029 | //face = [1,1,1,1]; 1030 | drawCube({ 1031 | x:x*2, 1032 | y:-y*2, 1033 | z:(h*2)-0.4, 1034 | h:0.2, 1035 | type:"normal2", 1036 | trigger:t.t, 1037 | decal:decal, 1038 | rotation:rotation, 1039 | //triggered:t.triggered, 1040 | //face:face 1041 | }) 1042 | if (t.t && !t.finish) { 1043 | drawCube({ 1044 | x:x*2, 1045 | y:-y*2, 1046 | z:h*2, 1047 | h:1, 1048 | type:"trigger", 1049 | trigger:t.t, 1050 | decal:decal 1051 | }) 1052 | } 1053 | } 1054 | } 1055 | 1056 | if (levelDrawing && !blocksInMove) { 1057 | levelDrawing = false; 1058 | startTuto(); 1059 | vitesseRotation = 10; 1060 | } 1061 | 1062 | lightsDisplayed = []; 1063 | for (i=0; i l.width/2 ? 1 : (x < l.width/2 ? -1 : 0); 1136 | level[x][y].speedX = Math.random() * f; 1137 | 1138 | f = y > l.height/2 ? -1 : (y < l.height/2 ? 1 : 0); 1139 | level[x][y].speedY = Math.random() * f; 1140 | 1141 | level[x][y].decalX = 0; 1142 | level[x][y].decalY = 0; 1143 | level[x][y].rotation = {x:0, y:0, z:0} 1144 | level[x][y].rotationSpeed = {x:Math.random()*0.1, y:Math.random()*0.1, z:Math.random()*0.1} 1145 | } 1146 | } 1147 | } 1148 | rafTick = null; 1149 | rafHUD = null; 1150 | waitingKeyStart = true; 1151 | function drawHUDEnd() { 1152 | frame++; 1153 | ctx.clearRect(0,0,window.innerWidth,window.innerHeight); 1154 | 1155 | //gl.clearColor(0.5, 0.25, 0.85, 1.0); 1156 | ctx.fillStyle = '#7F40D9'; 1157 | ctx.fillRect(0, 0, canvasHUD.width, canvasHUD.height); 1158 | t = "1024 MOVES"; drawText((window.innerWidth/2)-(12*15/2)*(t.length/2), 100, t, 15); 1159 | t = " CONGRATULATIONS !&YOU MADE IT IN "+nbMoves+" MOVES !& (BEST POSSIBLE IS 1024)"; 1160 | drawText((window.innerWidth/2)-(12*7/2)*(27/2), 500+Math.sin(frame/64)*10, t, 7); 1161 | 1162 | rafHUD = requestAnimationFrame(drawHUDEnd); 1163 | } 1164 | function drawHUDHome() { 1165 | frame++; 1166 | ctx.clearRect(0,0,window.innerWidth,window.innerHeight); 1167 | ctx.fillStyle = '#7F40D9'; 1168 | ctx.fillRect(0, 0, canvasHUD.width, canvasHUD.height); 1169 | t = "1024 MOVES"; drawText((window.innerWidth/2)-90*(t.length/2), 100, t, 15); 1170 | t = "PRESS A KEY TO START"; drawText((window.innerWidth/2)-42*(t.length/2), 500+Math.sin(frame/64)*10, t, 7); 1171 | rafHUD = requestAnimationFrame(drawHUDHome); 1172 | } 1173 | function drawHUD() { 1174 | ctx.clearRect(0,0,window.innerWidth,window.innerHeight); 1175 | if (tutoText) { 1176 | drawText((window.innerWidth/2)-(12*3/2)*(tutoText.length/2), (window.innerHeight/2) + 144, tutoText.toUpperCase(), 3); 1177 | } else { 1178 | drawText(10, 10, nbMoves+" MOVE"+(nbMoves>1 ? "S" : "" ),3); //+ " - "+tmpCreator.x+"."+tmpCreator.y, 3); 1179 | var t = "STAGE "+levelEnCours; 1180 | drawText((window.innerWidth/2)-27*(t.length/2), 20, t, 4.5); 1181 | drawText(10, 100, "M - MUTE&R - RETRY", 3); 1182 | } 1183 | } 1184 | 1185 | function tick() { 1186 | frame++; 1187 | drawScene(); 1188 | drawHUD(); 1189 | rafTick = requestAnimationFrame(tick); 1190 | } 1191 | 1192 | initGame = function() { 1193 | nbMoves = nbMovesAtStart; 1194 | 1195 | camera = { 1196 | x:-8, 1197 | y:16, 1198 | z:23, 1199 | rotation:{ 1200 | x:-1.3, 1201 | y:0, 1202 | z:63 1203 | } 1204 | }; 1205 | 1206 | var l = levels[levelEnCours]; 1207 | l.triggers.push({ 1208 | x:l.end.x, 1209 | y:l.end.y, 1210 | action:function() { 1211 | explodeLevel(); 1212 | }, 1213 | type:"finish" 1214 | }); 1215 | 1216 | selectedPlayer = 0; 1217 | level = []; 1218 | vitesseRotation = 1; 1219 | levelDrawing = true; 1220 | levelTmp = l.data.join(""); 1221 | for (var x=0; xlevelOn ? 2 : -2); 1317 | //playSound([1,,0.0922,,0.5,0.19,,0.02,-0.14,,,,,,,,,,1,,,0.2611,,0.5]); 1318 | playSound([2,0.1,0.20875772806897386,0.4,0.3995907182891785,0.6,0.20781957085118677,-0.15,0,0,0,0,0,0.8997235718602934,-0.19289283657523948,0,0,0,1,0,0,0.0583846933342502,0,0.55]); 1319 | } 1320 | } else { 1321 | if (level[x][y].h==levelOn) { 1322 | level[x][y].inMoveZ = vitesseRotation * (levelOff>levelOn ? -2 : 2); 1323 | //playSound([1,,0.0922,,0.5,0.19,,0.02,0.1599,,,,,,,,,,1,,,0.2611,,0.5]); 1324 | playSound([2,0.1,0.20875772806897386,0.4,0.3995907182891785,0.6,0.20781957085118677,0.15,0,0,0,0,0,0.8997235718602934,-0.19289283657523948,0,0,0,1,0,0,0.0583846933342502,0,0.6]); 1325 | } 1326 | } 1327 | level[x][y].h = state ? levelOn : levelOff; 1328 | } 1329 | function resize() { 1330 | var canvas = document.getElementById("game"); 1331 | canvas.width = window.innerWidth; 1332 | canvas.height = window.innerHeight; 1333 | 1334 | gl = canvas.getContext("webgl"); 1335 | gl.viewportWidth = canvas.width; 1336 | gl.viewportHeight = canvas.height; 1337 | 1338 | canvasHUD.width = canvas.width; 1339 | canvasHUD.height = canvas.height; 1340 | } 1341 | function webGLStart() { 1342 | //init HUD 1343 | canvasHUD = document.getElementById("HUD"); 1344 | ctx = canvasHUD.getContext("2d"); 1345 | 1346 | //init canvas && webgl 1347 | resize(); 1348 | 1349 | if (!gl) { 1350 | alert("Could not load WebGL sorry"); 1351 | } 1352 | initShaders(); 1353 | initTexture(); 1354 | 1355 | gl.clearColor(0.5, 0.25, 0.85, 1.0); 1356 | gl.enable(gl.DEPTH_TEST); 1357 | gl.enable(gl.BLEND); 1358 | gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); 1359 | 1360 | //Create textures 1361 | var canvas2 = document.createElement("canvas"); 1362 | canvas2.width=512; 1363 | canvas2.height=512; 1364 | var ctx2 = canvas2.getContext("2d"); 1365 | var iD = ctx2.getImageData(0, 0, canvas2.width, canvas2.height); 1366 | ctx2.clearRect(0,0,512,512); 1367 | 1368 | //Create wall texture 1369 | for (var i = 0; i < iD.data.length; i += 4) { 1370 | var c = Math.floor(Math.random()*255); 1371 | iD.data[i]=(255-((255-c)/1200)) * 193/255; 1372 | iD.data[i+1]=(255-((255-c)/1200)) * 171/255; 1373 | iD.data[i+2]=(255-((255-c)/1200)) * 146/255; 1374 | iD.data[i+3]=255; 1375 | } 1376 | ctx2.putImageData(iD, 0, 0); 1377 | handleLoadedTextureFromCanvas("mur", canvas2); 1378 | 1379 | //Create trigger texture 1380 | var tailleBordures = 50; 1381 | ctx2.clearRect(0,0,512,512); 1382 | for (var i = 0; i < iD.data.length; i += 4) { 1383 | var x = (i/4)%512; 1384 | var y = Math.floor(i/2048); 1385 | var isBordure = (y512-tailleBordures || x512-tailleBordures); 1386 | if (Math.hypot(256-x, 256-y) < 150) { 1387 | isBordure = true; 1388 | } 1389 | 1390 | iD.data[i+0]=isBordure ? 196 : 54; 1391 | iD.data[i+1]=isBordure ? 221 : 64; 1392 | iD.data[i+2]= isBordure ? 55 : 216; 1393 | iD.data[i+3]=255; 1394 | } 1395 | ctx2.putImageData(iD, 0, 0); 1396 | handleLoadedTextureFromCanvas("red", canvas2); 1397 | 1398 | //Create trigger2 texture 1399 | ctx2.clearRect(0,0,512,512); 1400 | for (var i = 0; i < iD.data.length; i += 4) { 1401 | var x = (i/4)%512; 1402 | var y = Math.floor(i/(512*4)); 1403 | var isBordure = (y512-tailleBordures || x512-tailleBordures); 1404 | if (x>=206 && x<=306 && y>=206 && y<=306) { 1405 | isBordure = true; 1406 | } 1407 | iD.data[i+0]=isBordure ? 255 : 54; 1408 | iD.data[i+1]=isBordure ? 121 : 64; 1409 | iD.data[i+2]= isBordure ? 0 : 216; 1410 | iD.data[i+3]=255; 1411 | } 1412 | ctx2.putImageData(iD, 0, 0); 1413 | handleLoadedTextureFromCanvas("blue", canvas2); 1414 | 1415 | //Create multiple texture for tiles 1416 | for (var j=0; j<23; j++) { 1417 | var taille = 10 + Math.random() * 3; 1418 | var c = Math.random(); 1419 | var color = { 1420 | r:27 - c*60, 1421 | g:165 - c*10, 1422 | b:211 - c*7.5 1423 | } 1424 | delta = {r:0, g:0, b:0}; 1425 | ctx2.clearRect(0,0,512,512); 1426 | for (var i = 0; i < iD.data.length; i += 4) { 1427 | var x = (i/4)%512; 1428 | var y = Math.floor(i/2048); 1429 | tailleBordures = j==21 ? 30 : taille; 1430 | if (j==22) { 1431 | tailleBordures = 30; 1432 | var isBordure = (y512-tailleBordures || x512-tailleBordures) ; 1433 | 1434 | x2 = Math.abs(x-256); 1435 | y2 = Math.abs(y-256); 1436 | if (Math.hypot(x2, y2) < 128 || Math.hypot(128-x2, 128-y2) < 64 || Math.hypot(192-x2, 192-y2) < 32) { 1437 | isBordure = true 1438 | } 1439 | 1440 | if (isBordure) { 1441 | delta.r = delta.g = delta.b = Math.hypot(256-x,256-y) > 32 ? Math.hypot(256-x,256-y) : 255; 1442 | } else { 1443 | delta = {r:0, g:0, b:0} 1444 | } 1445 | 1446 | } else { 1447 | var isBordure = (y512-tailleBordures || x512-tailleBordures) ; 1448 | } 1449 | 1450 | iD.data[i+0] = isBordure ? color.r / 2 + delta.r : color.r; 1451 | iD.data[i+1] = isBordure ? color.g / 2 + delta.g : color.g; 1452 | iD.data[i+2] = isBordure ? color.b / 2 + delta.b : color.b; 1453 | iD.data[i+3]=255; 1454 | } 1455 | ctx2.putImageData(iD, 0, 0); 1456 | handleLoadedTextureFromCanvasTiles(j, canvas2); 1457 | } 1458 | 1459 | //Create noise texture for the finish sphere 1460 | s = 256; 1461 | canvas2.width=s; 1462 | canvas2.height=s; 1463 | 1464 | var ctx2 = canvas2.getContext("2d"); 1465 | var iD = ctx2.getImageData(0, 0, canvas2.width, canvas2.height); 1466 | ctx2.clearRect(0,0,s,s); 1467 | 1468 | for (var i = 0; i < iD.data.length; i += 4) { 1469 | var c = Math.floor(Math.random()*255); 1470 | iD.data[i]=Math.floor(Math.random()*255); 1471 | iD.data[i+1]=Math.floor(Math.random()*255); 1472 | iD.data[i+2]=Math.floor(Math.random()*255); 1473 | iD.data[i+3]=Math.floor(Math.random()*255); 1474 | } 1475 | ctx2.putImageData(iD, 0, 0); 1476 | handleLoadedTextureFromCanvas("sphereTexture", canvas2); 1477 | 1478 | initLevels(); 1479 | initGame(); 1480 | drawHUDHome(); 1481 | } 1482 | document.onkeydown = function(e) { 1483 | if (waitingKeyStart) { 1484 | waitingKeyStart = false; 1485 | tick(); 1486 | cancelAnimationFrame(rafHUD); 1487 | } 1488 | switch(e.keyCode) { 1489 | case 90: 1490 | case 87: 1491 | case 38: // up 1492 | moveB = true; 1493 | break; 1494 | case 81: 1495 | case 65: 1496 | case 37: // left 1497 | moveL = true; 1498 | break; 1499 | case 40: // down 1500 | case 83: 1501 | moveF = true; 1502 | break; 1503 | case 68: 1504 | case 39: // right 1505 | moveR = true; 1506 | break; 1507 | case 17: 1508 | case 32: //space 1509 | break; 1510 | } 1511 | } 1512 | document.onkeyup = function(e) { 1513 | switch(e.keyCode) { 1514 | case 90: 1515 | case 87: 1516 | case 38: // up 1517 | moveB = false; 1518 | break; 1519 | case 81: 1520 | case 65: 1521 | case 37: // left 1522 | moveL = false; 1523 | break; 1524 | case 40: // down 1525 | case 83: 1526 | 1527 | moveF = false; 1528 | break; 1529 | case 68: 1530 | case 39: // right 1531 | moveR = false; 1532 | break; 1533 | case 82: 1534 | gameOver(); 1535 | break; 1536 | case 77: 1537 | sound = 1-sound; 1538 | break; 1539 | case 32: 1540 | selectedPlayer = (selectedPlayer + 1)%levels[levelEnCours].starts.length 1541 | break; 1542 | /*case 102: 1543 | tmpCreator.x++; 1544 | tmpCreator.z = level[tmpCreator.x] && level[tmpCreator.x][tmpCreator.y] ? (level[tmpCreator.x][tmpCreator.y].h)*2 : 0; 1545 | break; 1546 | case 100: 1547 | tmpCreator.x--; 1548 | tmpCreator.z = level[tmpCreator.x] && level[tmpCreator.x][tmpCreator.y] ? (level[tmpCreator.x][tmpCreator.y].h)*2 : 0; 1549 | break; 1550 | case 104: 1551 | tmpCreator.y--; 1552 | tmpCreator.z = level[tmpCreator.x] && level[tmpCreator.x][tmpCreator.y] ? (level[tmpCreator.x][tmpCreator.y].h)*2 : 0; 1553 | break; 1554 | case 98: 1555 | tmpCreator.y++; 1556 | tmpCreator.z = level[tmpCreator.x] && level[tmpCreator.x][tmpCreator.y] ? (level[tmpCreator.x][tmpCreator.y].h)*2 : 0; 1557 | break; 1558 | case 107: //+ 1559 | if (level[tmpCreator.x] && level[tmpCreator.x][tmpCreator.y]) { 1560 | level[tmpCreator.x][tmpCreator.y].h++; 1561 | } 1562 | break; 1563 | case 109: //- 1564 | if (level[tmpCreator.x] && level[tmpCreator.x][tmpCreator.y]) { 1565 | level[tmpCreator.x][tmpCreator.y].h--; 1566 | } 1567 | break; 1568 | case 13: 1569 | if (level[tmpCreator.x] && level[tmpCreator.x][tmpCreator.y]) { 1570 | var o = level[tmpCreator.x][tmpCreator.y].o; 1571 | if (o.length==0) { 1572 | o.push({ 1573 | x:tmpCreator.x, 1574 | y:tmpCreator.y, 1575 | z:level[tmpCreator.x][tmpCreator.y].h 1576 | }); 1577 | } else { 1578 | level[tmpCreator.x][tmpCreator.y].o = []; 1579 | } 1580 | } 1581 | break;*/ 1582 | default: 1583 | //console.log(e.keyCode); 1584 | break; 1585 | } 1586 | } 1587 | 1588 | var tuto = { 1589 | 1:[ 1590 | [{x:2,y:2, z:-8}, "this is you. Move with arrow keys", 4000], 1591 | [{x:14, y:2, z:-8}, "Watch out for holes", 3000], 1592 | [{x:22, y:2, z:-8}, "this is your goal, get the orb", 4000] 1593 | ], 1594 | 2:[ 1595 | [{x:12, y:2, z:0}, "You can push the crates", 3000] 1596 | ], 1597 | 5:[ 1598 | [{x:2, y:-2, z:-6}, "this is a switch, which modifies something in the stage", 3000] 1599 | ], 1600 | 6:[ 1601 | [{x:2, y:-2, z:-6}, "this is another sort of trigger, have to keep it pressed", 3000] 1602 | ], 1603 | 7:[ 1604 | [{x:8, y:6, z:0}, "this is another player. Switch between players with space key", 4000] 1605 | ], 1606 | 12:[ 1607 | [{x: 8, y: -2, z: -8}, "this block cannot be moved, but it is climbable", 4000] 1608 | ] 1609 | }; 1610 | 1611 | initLevels = function() { 1612 | levels = { 1613 | 1:{"width":14,"height":8,"starts":[{"x":1,"y":4}],"end":{"x":11,"y":4},"data":["00000000000000","33333333333300","32222222222300","32222220222300","32222200222200","32222220222300","32222222222300","33333333333300"],"objects":[],"triggers":[]}, //Simple juste un trou 1614 | 2:{"width":9,"height":6,"starts":[{"x":1,"y":1}],"end":{"x":6,"y":5},"data":["333333333","322222223","333333233","000003230","000003230","000003230"],"objects":[[6,1]],"triggers":[]}, //Juste pousser une caisse 1615 | 3:{"width":14,"height":8,"starts":[{"x":1,"y":4}],"end":{"x":11,"y":4},"data":["00000000000000","33333333333300","33333333333300","33322222333300","32223322221200","33322222333300","33333333333300","33333333333300"],"objects":[[7,4]],"triggers":[]}, 1616 | 4:{"width":14,"height":8,"starts":[{"x":1,"y":4}],"end":{"x":11,"y":4},"data":["00000000000000","33333333333300","33333333333300","33322222333300","32222222211200","33322232333300","33333333333300","33333333333300"],"objects":[[4,4],[6,4],[7,4]], triggers:[]}, 1617 | 5:{"width":14,"height":8,"starts":[{"x":1,"y":4}],"end":{"x":11,"y":4},"data":["00000000000000","33333333333300","32222233333300","33333222333300","32223222221200","32223333233300","33322222233300","33333333333300"],"objects":[],"triggers":[ 1618 | { 1619 | x:1, 1620 | y:2, 1621 | type:1, 1622 | on:[[10,4,1,2]] 1623 | }]}, 1624 | 6:{"width":14,"height":8,"starts":[{"x":1,"y":4}],"end":{"x":11,"y":4},"data":["00000000000000","33333333333300","32222222233300","33323232333300","32222232322200","32223232333300","33322233333300","33333333333300"],"objects":[[2,5],[5,5]],"triggers":[{ 1625 | x:1, 1626 | y:2, 1627 | type:2, 1628 | on:[[8,4,3,2]] 1629 | }]}, 1630 | 7:{ 1631 | width:9, 1632 | height:7, 1633 | starts:[{x:1, y:1},{x:4, y:3}], 1634 | end:{x:1, y:5}, 1635 | data:[ 1636 | "222222222", 1637 | "211111122", 1638 | "222222122", 1639 | "211112122", 1640 | "222222122", 1641 | "211111112", 1642 | "222222222" 1643 | ], 1644 | triggers:[ 1645 | { 1646 | x:1, 1647 | y:3, 1648 | type:2, 1649 | on:[[7,1,2,1]] 1650 | } 1651 | ], 1652 | objects:[ 1653 | [6,1] 1654 | ]}, 1655 | 8:{"width":14,"height":8,"starts":[{"x":1,"y":3}],"end":{"x":9,"y":4},"data":["00000000000000","55544044433300","55504043333300","55504043333300","54444133333300","54444043333300","55544043333300","55554044433300"],"objects":[[4,2],[1,6]],"triggers":[]}, 1656 | 9:{"width":14,"height":8,"starts":[{"x":1,"y":1},{"x":1,"y":3}],"end":{"x":8,"y":2},"data":["33333333333300","33333333333300","33333435533300","33333333333300","33333333333300","00000000000000","00000000000000","00000000000000"],"objects":[[1,2]],triggers:[ 1657 | { 1658 | x:4, 1659 | y:2, 1660 | type:2, 1661 | on:[[6,2,3,4]] 1662 | } 1663 | ]}, 1664 | 10:{"width":14,"height":8,"starts":[{"x":2,"y":6},{"x":10,"y":2}],"end":{"x":5,"y":4},"data":["00000000000000","33323332333000","33323332333000","33323332333000","33323532333000","33323332333000","33323332333000","33323332333000"],"objects":[[1,4],[9,4]],"triggers":[ 1665 | { 1666 | x:1, 1667 | y:6, 1668 | type:2, 1669 | on:[[3,4,2,3],[7,4,2,3]] 1670 | },{ 1671 | x:9, 1672 | y:6, 1673 | type:2, 1674 | on:[[3,4,2,3],[7,4,2,3]] 1675 | },{ 1676 | x:4, 1677 | y:6, 1678 | type:3, 1679 | on:[[5,3,1]] 1680 | },{ 1681 | x:6, 1682 | y:6, 1683 | type:3, 1684 | on:[[5,3,1]] 1685 | } 1686 | ]}, 1687 | 1688 | 11:{"width":17,"height":12,"best":204,"starts":[{"x":4,"y":6}],"end":{"x":16,"y":6},"data":["41111111111133333","33333333333332223","22222222222222323","22222333333322223","33333344444322233","00000345554332220","55555555554332225","00000055554322220","33333344444323233","32222333333322223","32322222222222223","33333333333333333"],"objects":[[9,5],[9,6],[9,7]],"triggers":[ 1689 | { 1690 | x:15, 1691 | y:10, 1692 | type:3, 1693 | on:[[16,6,-1]] 1694 | },{ 1695 | x:15, 1696 | y:9, 1697 | type:3, 1698 | on:[[16,6,-1]] 1699 | },{ 1700 | x:14, 1701 | y:9, 1702 | type:3, 1703 | on:[[16,6,-1]] 1704 | } 1705 | ]}, 1706 | 12:{"width":9,"height":7,"starts":[{"x":5,"y":3}],"end":{"x":7,"y":3},"data":["111111111","111111112","111111012","111111020","111111012","111111112","111111111"],"objects":[[4,1,2],[1,2],[1,3],[1,4],[4,5,2]],"triggers":[{ 1707 | x:5, 1708 | y:5, 1709 | type:2, 1710 | on:[[5,5,1,2]] 1711 | },{ 1712 | x:5, 1713 | y:1, 1714 | type:2, 1715 | on:[[5,1,1,2]] 1716 | }]}, 1717 | 13:{"width":8,"height":7,"starts":[{"x":3,"y":4}],"end":{"x":7,"y":2},"data":["12222200","22221100","21111102","12222101","21111101","22222122","12222222"],"objects":[[2,2],[2,4]],"triggers":[{ 1718 | x:5, 1719 | y:5, 1720 | type:2, 1721 | on:[[5,5,1,2]] 1722 | },{ 1723 | x:4, 1724 | y:1, 1725 | type:2, 1726 | on:[[4,1,1,2]] 1727 | },{ 1728 | x:1, 1729 | y:4, 1730 | type:2, 1731 | on:[[1,4,1,2]] 1732 | }]}, 1733 | 14:{"width":16,"height":7,"starts":[{"x":1,"y":3}],"end":{"x":13,"y":3},"data":["022222220000200","0021111122202220","0221222111222222","0211111111222212","0211121112222222","0221121112002220","0022222222000200"],"objects":[[2,2],[4,3],[7,3],[6,4]],"triggers":[{ 1734 | x:2, 1735 | y:5, 1736 | type:2, 1737 | on:[[9,3,2,1]] 1738 | },{ 1739 | x:3, 1740 | y:5, 1741 | type:2, 1742 | on:[[10,3,2,1]] 1743 | },{ 1744 | x:2, 1745 | y:4, 1746 | type:2, 1747 | on:[[11,3,2,1]] 1748 | },{ 1749 | x:3, 1750 | y:4, 1751 | type:2, 1752 | on:[[12,3,2,1]] 1753 | }]}, 1754 | 15:{"width":15,"height":15,"starts":[{"x":0,"y":3}],"end":{"x":7,"y":10},"data":["222222000000000","222222222022230","332333222322230","222222222022230","333333222000100","222222223000200","333332223000200","000000000002200","000000333302200","000000322333230","000000322222230","000000322333330","000000333300000","000000000000000","000000000000000"],"objects":[[2,2,2],[5,3,2],[6,3],[7,3],[12,6]],"triggers":[ 1755 | { 1756 | x:2, 1757 | y:5, 1758 | type:2, 1759 | on:[[2,2,2,1]] 1760 | },{ 1761 | x:0, 1762 | y:2, 1763 | type:2, 1764 | on:[[9,2,3,2]] 1765 | }]}, 1766 | 16:{"width":16,"height":16,"starts":[{"x":8,"y":7}],"end":{"x":7,"y":10},"data":["0000000000000000","0004444444000000","0004323334444400","0004222223333400","0004222222223400","0004222222223400","0004222333222400","0004222323323400","0004222322333400","0004222222444400","0004444344400000","0000000000000000","0000000000000000","0000000000000000","2222222222222222","2222222222222222"],"objects":[[5,3,2],[5,4],[6,4],[7,3],[8,4]],"triggers":[]}, 1767 | 17:{"width":10,"height":10,"starts":[{"x":1,"y":5},{"x":1,"y":6},{"x":1,"y":7}],"end":{"x":7,"y":8},"data":["0000000000","0000000000","0000000000","3333233300","2111111300","2111111100","2111111300","2111133330","2111113330","2222133330"],"objects":[[4,8]],"triggers":[ 1768 | { 1769 | x:6, 1770 | y:5, 1771 | type:2, 1772 | on:[[6,5,1,2]] 1773 | },{ 1774 | x:4, 1775 | y:3, 1776 | type:2, 1777 | on:[[4,3,2,3]] 1778 | }]} 1779 | } 1780 | } 1781 | /* 1782 | saveLevel = function() { 1783 | l = { 1784 | width:level.length, 1785 | height:level[0].length, 1786 | starts:[players[0].tile], 1787 | end:{x:0, y:0}, 1788 | data:[], 1789 | objects:[], 1790 | triggers:[] 1791 | } 1792 | 1793 | for (var y=0; y