diff --git a/src/font.png b/src/font.png new file mode 100644 index 00000000..5deefeda Binary files /dev/null and b/src/font.png differ diff --git a/src/licenses/assimp_license.txt b/src/licenses/assimp_license.txt new file mode 100755 index 00000000..262606af --- /dev/null +++ b/src/licenses/assimp_license.txt @@ -0,0 +1,78 @@ +Open Asset Import Library (assimp) + +Copyright (c) 2006-2016, assimp team +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +****************************************************************************** + +AN EXCEPTION applies to all files in the ./test/models-nonbsd folder. +These are 3d models for testing purposes, from various free sources +on the internet. They are - unless otherwise stated - copyright of +their respective creators, which may impose additional requirements +on the use of their work. For any of these models, see +.source.txt for more legal information. Contact us if you +are a copyright holder and believe that we credited you inproperly or +if you don't want your files to appear in the repository. + + +****************************************************************************** + +Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors +http://code.google.com/p/poly2tri/ + +All rights reserved. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +* Neither the name of Poly2Tri nor the names of its contributors may be + used to endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/licenses/dyncall_license.txt b/src/licenses/dyncall_license.txt new file mode 100755 index 00000000..6984164f --- /dev/null +++ b/src/licenses/dyncall_license.txt @@ -0,0 +1,14 @@ +Copyright (c) 2007-2015 Daniel Adler , + Tassilo Philipp + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/src/licenses/glfw_license.txt b/src/licenses/glfw_license.txt new file mode 100755 index 00000000..8a60e1d8 --- /dev/null +++ b/src/licenses/glfw_license.txt @@ -0,0 +1,21 @@ +Copyright (c) 2002-2006 Marcus Geelnard +Copyright (c) 2006-2010 Camilla Berglund + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would + be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source + distribution. diff --git a/src/licenses/khronos_license.txt b/src/licenses/khronos_license.txt new file mode 100755 index 00000000..d7e6e9dd --- /dev/null +++ b/src/licenses/khronos_license.txt @@ -0,0 +1,22 @@ +/* +** Copyright (c) 2013-2014 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ \ No newline at end of file diff --git a/src/licenses/openal_soft_license.txt b/src/licenses/openal_soft_license.txt new file mode 100755 index 00000000..5bc8fb2c --- /dev/null +++ b/src/licenses/openal_soft_license.txt @@ -0,0 +1,481 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library 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 Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey 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 library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/src/lwjglwindow/Drawer.java b/src/lwjglwindow/Drawer.java new file mode 100644 index 00000000..2442ad02 --- /dev/null +++ b/src/lwjglwindow/Drawer.java @@ -0,0 +1,9 @@ +package lwjglwindow; + +public class Drawer +{ + public void draw() + { + + } +} diff --git a/src/lwjglwindow/FontRenderer.java b/src/lwjglwindow/FontRenderer.java new file mode 100644 index 00000000..3461627e --- /dev/null +++ b/src/lwjglwindow/FontRenderer.java @@ -0,0 +1,79 @@ +package lwjglwindow; + +public class FontRenderer +{ + public LWJGLWindow home; + String chars; + int[] charSizes; + String image; + + public FontRenderer(LWJGLWindow h, String fontFile) + { + this.home = h; + this.chars = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}�"; + this.charSizes = new int[] + { + 3, 2, 4, 5, 5, 5, 5, 2, 4, 4, 4, 5, 1, 5, 1, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 5, 5, 5, 5, + 6, 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 3, 5, 5, + 2, 5, 5, 5, 5, 5, 4, 5, 5, 1, 5, 4, 2, 5, 5, 5, + 5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 5, 4, 1, 4, 6, 5 + }; + this.image = fontFile; + } + + public int drawChar(double x, double y, double sX, double sY, char c) + { + int i = this.chars.indexOf(c); + + if (i == -1) + i = 95; + + int col = i % 16; + int row = i / 16; + int width = charSizes[i]; + this.home.drawImage(x, y, sX, sY - 0.0001, col / 16f, row / 16f, (col + width / 8f) / 16f, (row + 1) / 16f, image, true); + return width; + } + + public void drawString(double x, double y, double sX, double sY, String s) + { + double curX = x; + char[] c = s.toCharArray(); + + for (int i = 0; i < c.length; i++) + { + if (c[i] == '\u00A7') + { + int r = Integer.parseInt(c[i + 1] + "" + c[i + 2] + "" + c[i + 3]); + int g = Integer.parseInt(c[i + 4] + "" + c[i + 5] + "" + c[i + 6]); + int b = Integer.parseInt(c[i + 7] + "" + c[i + 8] + "" + c[i + 9]); + int a = Integer.parseInt(c[i + 10] + "" + c[i + 11] + "" + c[i + 12]); + this.home.setColor(r, g, b, a); + + i += 13; + } + + curX += (drawChar(curX, y, sX, sY, c[i]) + 1) * sX * 4; + } + } + + public int getStringSizeX(double sX, String s) + { + int w = 0; + char[] c = s.toCharArray(); + + for (int i = 0; i < c.length; i++) + { + w += (charSizes[this.chars.indexOf(c[i])] + 1) * sX * 4; + } + + return w; + } + + public int getStringSizeY(double sY, String s) + { + return (int) (sY * 32); + } +} diff --git a/src/lwjglwindow/LWJGLWindow.java b/src/lwjglwindow/LWJGLWindow.java new file mode 100644 index 00000000..82a263b2 --- /dev/null +++ b/src/lwjglwindow/LWJGLWindow.java @@ -0,0 +1,437 @@ +package lwjglwindow; +import org.lwjgl.glfw.*; +import org.lwjgl.opengl.*; +import org.lwjgl.system.*; + +import de.matthiasmann.twl.utils.PNGDecoder; +import de.matthiasmann.twl.utils.PNGDecoder.Format; +import java.io.InputStream; +import java.nio.*; +import java.util.ArrayList; +import java.util.HashMap; + +import static org.lwjgl.glfw.Callbacks.*; +import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.system.MemoryStack.*; +import static org.lwjgl.system.MemoryUtil.*; + +public class LWJGLWindow +{ + public FontRenderer fontRenderer; + + // The window handle + protected long window; + public int absoluteWidth; + public int absoluteHeight; + public double absoluteMouseX; + public double absoluteMouseY; + + public ArrayList pressedKeys = new ArrayList(); + public ArrayList validPressedKeys = new ArrayList(); + + public ArrayList pressedButtons = new ArrayList(); + public ArrayList validPressedButtons = new ArrayList(); + + public boolean validScrollUp; + public boolean validScrollDown; + + protected ArrayList framesList = new ArrayList(); + protected ArrayList frameFrequencies = new ArrayList(); + protected long lastFrame = System.currentTimeMillis(); + public double frameFrequency = 1; + + protected HashMap textures = new HashMap(); + protected HashMap textureSX = new HashMap(); + protected HashMap textureSY = new HashMap(); + + public String name; + + public Drawer drawer; + public Updater updater; + + public LWJGLWindow(String name, int x, int y, Updater u, Drawer d) + { + this.name = name; + this.absoluteWidth = x; + this.absoluteHeight = y; + this.updater = u; + this.drawer = d; + } + + public void run() + { + init(); + loop(); + + // Free the window callbacks and destroy the window + glfwFreeCallbacks(window); + glfwDestroyWindow(window); + + // Terminate GLFW and free the error callback + glfwTerminate(); + glfwSetErrorCallback(null).free(); + } + + protected void init() + { + this.fontRenderer = new FontRenderer(this, "/font.png"); + + // Setup an error callback. The default implementation + // will print the error message in System.err. + GLFWErrorCallback.createPrint(System.err).set(); + + // Initialize GLFW. Most GLFW functions will not work before doing this. + if (!glfwInit()) + throw new IllegalStateException("Unable to initialize GLFW"); + + // Configure GLFW + glfwDefaultWindowHints(); // optional, the current window hints are + // already the default + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden + // after creation + glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be + // resizable + + // Create the window + window = glfwCreateWindow(this.absoluteWidth, this.absoluteHeight, this.name, NULL, NULL); + if (window == NULL) + throw new RuntimeException("Failed to create the GLFW window"); + + // Setup a key callback. It will be called every time a key is pressed, + // repeated or released. + glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> + { + if (action == GLFW_PRESS) + { + pressedKeys.add((Integer)key); + validPressedKeys.add((Integer)key); + } + else if (action == GLFW_RELEASE) + { + pressedKeys.remove((Integer)key); + validPressedKeys.remove((Integer)key); + } + }); + + glfwSetScrollCallback(window, (window, xoffset, yoffset) -> + { + if (yoffset > 0) + this.validScrollUp = true; + else if (yoffset < 0) + this.validScrollDown = true; + }); + + glfwSetMouseButtonCallback(window, (window, button, action, mods) -> + { + if (action == GLFW_PRESS) + { + pressedButtons.add(button); + validPressedButtons.add(button); + } + else if (action == GLFW_RELEASE) + { + pressedButtons.remove((Integer)button); + validPressedButtons.remove((Integer)button); + } + }); + + // Get the thread stack and push a new frame + try (MemoryStack stack = stackPush()) + { + IntBuffer pWidth = stack.mallocInt(1); // int* + IntBuffer pHeight = stack.mallocInt(1); // int* + + // Get the window size passed to glfwCreateWindow + glfwGetWindowSize(window, pWidth, pHeight); + + // Get the resolution of the primary monitor + GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + + // Center the window + glfwSetWindowPos(window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2); + } // the stack frame is popped automatically + + // Make the OpenGL context current + glfwMakeContextCurrent(window); + // Enable v-sync + glfwSwapInterval(1); + + // Make the window visible + glfwShowWindow(window); + } + + protected void loop() + { + // This line is critical for LWJGL's interoperation with GLFW's + // OpenGL context, or any context that is managed externally. + // LWJGL detects the context that is current in the current thread, + // creates the GLCapabilities instance and makes the OpenGL + // bindings available for use. + GL.createCapabilities(); + + // Set the clear color + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + // Run the rendering loop until the user has attempted to close + // the window. + + while (!glfwWindowShouldClose(window)) + { + long milliTime = System.currentTimeMillis(); + + framesList.add(milliTime); + + ArrayList removeList = new ArrayList(); + + for (int i = 0; i < framesList.size(); i++) + { + if (milliTime - framesList.get(i) > 1000) + removeList.add(framesList.get(i)); + } + + for (int i = 0; i < removeList.size(); i++) + { + framesList.remove(removeList.get(i)); + } + + this.updater.update(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + int[] w = new int[1]; + int[] h = new int[1]; + glfwGetWindowSize(window, w, h); + absoluteWidth = w[0]; + absoluteHeight = h[0]; + + double[] mx = new double[1]; + double[] my = new double[1]; + glfwGetCursorPos(window, mx, my); + absoluteMouseX = mx[0]; + absoluteMouseY = my[0]; + + if (System.getProperties().contains("windows")) + glViewport(0, 0, absoluteWidth, absoluteHeight); + + glOrtho(0, absoluteWidth, absoluteHeight, 0, 0, 1); + this.drawer.draw(); + + glfwSwapBuffers(window); + glfwPollEvents(); + + + long time = System.currentTimeMillis(); + long lastFrameTime = lastFrame; + lastFrame = time; + + double freq = (time - lastFrameTime) / 10.0; + frameFrequencies.add(freq); + + if (frameFrequencies.size() > 5) + { + frameFrequencies.remove(0); + } + + double totalFrequency = 0; + for (int i = 0; i < frameFrequencies.size(); i++) + { + totalFrequency += frameFrequencies.get(i); + } + + frameFrequency = totalFrequency / frameFrequencies.size(); + } + } + + public void fillOval(double x, double y, double sX, double sY) + { + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY + 5); + + glBegin(GL_TRIANGLE_FAN); + for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + { + glVertex2d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2); + } + + glEnd(); + } + + public void setColor(double r, double g, double b, double a) + { + glColor4d(r / 255, g / 255, b / 255, a / 255); + } + + public void setColor(double r, double g, double b) + { + glColor3d(r / 255, g / 255, b / 255); + } + + public void drawOval(double x, double y, double sX, double sY) + { + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY + 5); + + for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + { + glBegin(GL_LINES); + glVertex2d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2); + glVertex2d(x + Math.cos(i + Math.PI * 2 / sides) * sX / 2, y + Math.sin(i + Math.PI * 2 / sides) * sY / 2); + glEnd(); + } + + } + + public void fillRect(double x, double y, double sX, double sY) + { + glBegin(GL_TRIANGLE_FAN); + + glVertex2d(x, y); + glVertex2d(x + sX, y); + glVertex2d(x + sX, y + sY); + glVertex2d(x, y + sY); + + glEnd(); + } + + public void fillQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) + { + glBegin(GL_TRIANGLE_FAN); + + glVertex2d(x1, y1); + glVertex2d(x2, y2); + glVertex2d(x3, y3); + glVertex2d(x4, y4); + + glEnd(); + } + + public void drawRect(double x, double y, double sX, double sY) + { + glBegin(GL_LINES); + glVertex2d(x, y); + glVertex2d(x + sX, y); + glEnd(); + + glBegin(GL_LINES); + glVertex2d(x, y); + glVertex2d(x, y + sY); + glEnd(); + + glBegin(GL_LINES); + glVertex2d(x, y + sY); + glVertex2d(x + sX, y + sY); + glEnd(); + + glBegin(GL_LINES); + glVertex2d(x + sX, y); + glVertex2d(x + sX, y + sY); + glEnd(); + } + + public void drawImage(double x, double y, double sX, double sY, String image, boolean scaled) + { + drawImage(x, y, sX, sY, 0, 0, 1, 1, image, scaled); + } + + protected void createImage(String image) + { + try + { + InputStream in; + + + in = getClass().getResourceAsStream(image); + + if (in == null) + in = getClass().getResourceAsStream("/missing.png"); + + try + { + PNGDecoder decoder = new PNGDecoder(in); + + ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); + decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); + buf.flip(); + + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + int id = glGenTextures(); + + glBindTexture(GL_TEXTURE_2D, id); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); + in.close(); + + textures.put(image, id); + textureSX.put(image, decoder.getWidth()); + textureSY.put(image, decoder.getHeight()); + + } + finally + { + in.close(); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled) + { + if (!textures.containsKey(image)) + createImage(image); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, absoluteWidth, absoluteHeight, 0, 0, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glBindTexture(GL_TEXTURE_2D, textures.get(image)); + + double width = sX * (u2 - u1); + double height = sY * (v2 - v1); + + if (scaled) + { + width *= textureSX.get(image); + height *= textureSY.get(image); + } + + glBegin(GL_TRIANGLE_FAN); + glTexCoord2d(u1, v1); + glVertex2d(x, y); + glTexCoord2d(u1, v2); + glVertex2d(x, y + height); + glTexCoord2d(u2, v2); + glVertex2d(x + width, y + height); + glTexCoord2d(u2, v1); + glVertex2d(x + width, y); + + glEnd(); + + glMatrixMode(GL_PROJECTION); + glDisable(GL_TEXTURE_2D); + } +} \ No newline at end of file diff --git a/src/lwjglwindow/Updater.java b/src/lwjglwindow/Updater.java new file mode 100644 index 00000000..318b6604 --- /dev/null +++ b/src/lwjglwindow/Updater.java @@ -0,0 +1,9 @@ +package lwjglwindow; + +public class Updater +{ + public void update() + { + + } +} diff --git a/src/missing.png b/src/missing.png new file mode 100644 index 00000000..6f657ae7 Binary files /dev/null and b/src/missing.png differ diff --git a/src/tanks/AreaEffectFreeze.java b/src/tanks/AreaEffectFreeze.java index e79a37b3..30bb60b0 100755 --- a/src/tanks/AreaEffectFreeze.java +++ b/src/tanks/AreaEffectFreeze.java @@ -1,8 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - import tanks.AttributeModifier.Operation; public class AreaEffectFreeze extends AreaEffect @@ -25,7 +22,9 @@ public void imbueEffects() { Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); int var = 50; - e.col = new Color((int) Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2))); + e.colR = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)); + e.colG = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)); e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 200.0); e.maxAge *= 4; Game.effects.add(e); @@ -48,13 +47,13 @@ public void imbueEffects() } @Override - public void draw(Graphics g) + public void draw() { double size = Math.min(this.size + Game.tank_size / 2, this.age * 8); for (int i = (int) Math.max(0, size - ((int) (50 * Math.min(100, 600 - this.age) / 100.0))); i < size; i += 2) { - g.setColor(new Color(200, 255, 255, 10)); - Drawing.window.fillOval(g, this.posX, this.posY, i, i); + Drawing.drawing.setColor(200, 255, 255, 10); + Drawing.drawing.fillOval(this.posX, this.posY, i, i); } } diff --git a/src/tanks/AttributeModifier.java b/src/tanks/AttributeModifier.java index 4a4cfdea..78f4d8a6 100755 --- a/src/tanks/AttributeModifier.java +++ b/src/tanks/AttributeModifier.java @@ -45,7 +45,7 @@ public void update() { this.age += Panel.frameFrequency; - if (this.age > this.duration) + if (this.duration > 0 && this.age > this.duration) this.expired = true; } diff --git a/src/tanks/Bullet.java b/src/tanks/Bullet.java index c162a302..69172eee 100755 --- a/src/tanks/Bullet.java +++ b/src/tanks/Bullet.java @@ -1,11 +1,7 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - import tanks.tank.Tank; - public class Bullet extends Movable { public static enum BulletEffect {none, fire, darkFire, fireTrail, ice, trail}; @@ -16,8 +12,16 @@ public static enum BulletEffect {none, fire, darkFire, fireTrail, ice, trail}; public double age = 0; public double size; public int bounces; - public Color baseColor; - public Color outlineColor; + public int bouncyBounces = 100; + + public double baseColorR; + public double baseColorG; + public double baseColorB; + + public double outlineColorR; + public double outlineColorG; + public double outlineColorB; + public double destroyTimer = 0; public Tank tank; public double damage = 1; @@ -36,8 +40,15 @@ public Bullet(double x, double y, int bounces, Tank t) this.vX = 0; this.vY = 0; this.size = bullet_size; - this.baseColor = t.color; - this.outlineColor = Team.getObjectColor(t.turret.color, t); + this.baseColorR = t.colorR; + this.baseColorG = t.colorG; + this.baseColorB = t.colorB; + + double[] oc = Team.getObjectColor(t.turret.colorR, t.turret.colorG, t.turret.colorB, t); + this.outlineColorR = oc[0]; + this.outlineColorG = oc[1]; + this.outlineColorB = oc[2]; + this.bounces = bounces; this.tank = t; this.team = t.team; @@ -72,8 +83,8 @@ public void collidedWithTank(Tank t) { if (!heavy) this.destroy = true; - - if (!(Team.isAllied(this, t) && !this.team.friendlyFire)) + + if (!(Team.isAllied(this, t) && !this.team.friendlyFire) && !t.invulnerable) { t.flashAnimation = 1; if (!this.heavy) @@ -98,7 +109,7 @@ public void collidedWithTank(Tank t) public void collidedWithObject(Movable o) { if (this.playPopSound) - Drawing.playSound("resources/bullet_explode.wav"); + Drawing.drawing.playSound("resources/bullet_explode.wav"); if (!heavy) { @@ -106,6 +117,13 @@ public void collidedWithObject(Movable o) this.vX = 0; this.vY = 0; } + + if (heavy && o instanceof Bullet && ((Bullet)o).heavy) + { + this.destroy = true; + this.vX = 0; + this.vY = 0; + } o.destroy = true; @@ -119,6 +137,8 @@ public void checkCollision() if (this.destroy) return; + boolean bouncy = false; + boolean collided = false; double prevX = this.posX; @@ -131,12 +151,12 @@ public void checkCollision() if (!o.bulletCollision && !o.checkForObjects) continue; - double horizontalDist = Math.abs(this.posX - o.posX); - double verticalDist = Math.abs(this.posY - o.posY); - double dx = this.posX - o.posX; double dy = this.posY - o.posY; + double horizontalDist = Math.abs(dx); + double verticalDist = Math.abs(dy); + double s = this.size; if (useCustomWallCollision) s = this.wallCollisionSize; @@ -150,39 +170,55 @@ public void checkCollision() if (!o.bulletCollision) continue; - - if (dx <= 0 && dx > 0 - bound && horizontalDist > verticalDist) + + boolean left = o.hasLeftNeighbor(); + boolean right = o.hasRightNeighbor(); + boolean up = o.hasUpperNeighbor(); + boolean down = o.hasLowerNeighbor(); + + if (left && dx <= 0) + horizontalDist = 0; + + if (right && dx >= 0) + horizontalDist = 0; + + if (up && dy <= 0) + verticalDist = 0; + + if (down && dy >= 0) + verticalDist = 0; + + bouncy = o.bouncy; + collided = true; + + if (!left && dx <= 0 && dx > 0 - bound && horizontalDist > verticalDist) { this.posX += horizontalDist - bound; this.vX = -Math.abs(this.vX); - collided = true; } - else if (dy <= 0 && dy > 0 - bound && horizontalDist < verticalDist) + else if (!up && dy <= 0 && dy > 0 - bound && horizontalDist < verticalDist) { this.posY += verticalDist - bound; this.vY = -Math.abs(this.vY); - collided = true; } - else if (dx >= 0 && dx < bound && horizontalDist > verticalDist) + else if (!right && dx >= 0 && dx < bound && horizontalDist > verticalDist) { this.posX -= horizontalDist - bound; this.vX = Math.abs(this.vX); - collided = true; } - else if (dy >= 0 && dy < bound && horizontalDist < verticalDist) + else if (!down && dy >= 0 && dy < bound && horizontalDist < verticalDist) { this.posY -= verticalDist - bound; this.vY = Math.abs(this.vY); - collided = true; } } } - if (this.posX + this.size/2 > Drawing.sizeX) + if (this.posX + this.size/2 > Drawing.drawing.sizeX) { collided = true; - this.posX = Drawing.sizeX - this.size/2 - (this.posX + this.size/2 - Drawing.sizeX); + this.posX = Drawing.drawing.sizeX - this.size/2 - (this.posX + this.size/2 - Drawing.drawing.sizeX); this.vX = -Math.abs(this.vX); } if (this.posX - this.size/2 < 0) @@ -191,10 +227,10 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist) this.posX = this.size/2 - (this.posX - this.size / 2); this.vX = Math.abs(this.vX); } - if (this.posY + this.size/2 > Drawing.sizeY) + if (this.posY + this.size/2 > Drawing.drawing.sizeY) { collided = true; - this.posY = Drawing.sizeY - this.size/2 - (this.posY + this.size/2 - Drawing.sizeY); + this.posY = Drawing.drawing.sizeY - this.size/2 - (this.posY + this.size/2 - Drawing.drawing.sizeY); this.vY = -Math.abs(this.vY); } if (this.posY - this.size/2 < 0) @@ -255,20 +291,22 @@ else if ((o instanceof Bullet || o instanceof Mine) && o != this && !o.destroy & if (collided) { - - if (this.bounces <= 0) + if (!bouncy) + this.bounces--; + else + this.bouncyBounces--; + + if (this.bounces < 0 || this.bouncyBounces < 0) { if (this.playPopSound) - Drawing.playSound("resources/bullet_explode.wav"); + Drawing.drawing.playSound("resources/bullet_explode.wav"); this.destroy = true; this.vX = 0; this.vY = 0; } else - Drawing.playSound("resources/bounce.wav"); - - this.bounces--; + Drawing.drawing.playSound("resources/bounce.wav"); } } @@ -291,7 +329,9 @@ public void update() Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); int var = 50; e.maxAge /= 2; - e.col = new Color((int) Math.min(255, Math.max(0, this.baseColor.getRed() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.baseColor.getGreen() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.baseColor.getBlue() + Math.random() * var - var / 2))); + e.colR = Math.min(255, Math.max(0, this.baseColorR + Math.random() * var - var / 2)); + e.colG = Math.min(255, Math.max(0, this.baseColorG + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, this.baseColorB + Math.random() * var - var / 2)); e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0 * 4); Game.effects.add(e); } @@ -358,7 +398,9 @@ public void update() Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); int var = 50; e.maxAge /= 2; - e.col = new Color((int) Math.min(255, Math.max(0, 128 + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2))); + e.colR = Math.min(255, Math.max(0, 128 + Math.random() * var - var / 2)); + e.colG = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)); e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0 * 4); Game.effects.add(e); } @@ -382,14 +424,14 @@ public void update() } @Override - public void draw(Graphics p) + public void draw() { double opacity = ((60 - destroyTimer) / 60.0); double sizeModifier = destroyTimer * (size / Bullet.bullet_size); - p.setColor(new Color(this.outlineColor.getRed(), this.outlineColor.getGreen(), this.outlineColor.getBlue(), (int)(opacity * opacity * opacity * 255.0))); - Drawing.window.fillOval(p, posX, posY, size + sizeModifier, size + sizeModifier); - p.setColor(new Color(this.baseColor.getRed(), this.baseColor.getGreen(), this.baseColor.getBlue(), (int)(opacity * opacity * opacity * 255.0))); - Drawing.window.fillOval(p, posX, posY, (size + sizeModifier) * 0.6, (size + sizeModifier) * 0.6); + Drawing.drawing.setColor(this.outlineColorR, this.outlineColorG, this.outlineColorB, (int)(opacity * opacity * opacity * 255.0)); + Drawing.drawing.fillOval(posX, posY, size + sizeModifier, size + sizeModifier); + Drawing.drawing.setColor(this.baseColorR, this.baseColorG, this.baseColorB, (int)(opacity * opacity * opacity * 255.0)); + Drawing.drawing.fillOval(posX, posY, (size + sizeModifier) * 0.6, (size + sizeModifier) * 0.6); } diff --git a/src/tanks/BulletElectric.java b/src/tanks/BulletElectric.java index ed1c7fef..df6fbe0d 100755 --- a/src/tanks/BulletElectric.java +++ b/src/tanks/BulletElectric.java @@ -1,7 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; import java.util.ArrayList; import tanks.AttributeModifier.Operation; @@ -163,14 +161,16 @@ public void collided(Movable movable) { Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.stun); int var = 50; - e.col = new Color((int) Math.min(255, Math.max(0, 0 + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2))); + e.colR = Math.min(255, Math.max(0, 0 + Math.random() * var - var / 2)); + e.colG = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2)); Game.effects.add(e); } } } @Override - public void draw(Graphics g) + public void draw() { } diff --git a/src/tanks/BulletFlame.java b/src/tanks/BulletFlame.java index 824f4c6e..dcc8c9b4 100755 --- a/src/tanks/BulletFlame.java +++ b/src/tanks/BulletFlame.java @@ -1,8 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - import tanks.tank.Tank; public class BulletFlame extends Bullet @@ -49,17 +46,16 @@ public void update() } @Override - public void draw(Graphics g) + public void draw() { double rawOpacity = (1.0 - (this.age)/life); rawOpacity *= rawOpacity; int opacity = (int)(rawOpacity * 255); int green = (int)(255 - 255.0*(this.age / life)); - Color col = new Color(255, green, 0, opacity); - g.setColor(col); - Drawing.window.fillOval(g, this.posX, this.posY, size, size); + Drawing.drawing.setColor(255, green, 0, opacity); + Drawing.drawing.fillOval(this.posX, this.posY, size, size); } } diff --git a/src/tanks/BulletFreeze.java b/src/tanks/BulletFreeze.java index 607bedd9..7568ef9c 100755 --- a/src/tanks/BulletFreeze.java +++ b/src/tanks/BulletFreeze.java @@ -1,8 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - import tanks.tank.Tank; public class BulletFreeze extends Bullet @@ -10,7 +7,10 @@ public class BulletFreeze extends Bullet public BulletFreeze(double x, double y, int bounces, Tank t) { super(x, y, bounces, t); - this.outlineColor = Color.white; + this.outlineColorR = 255; + this.outlineColorG = 255; + this.outlineColorB = 255; + } public BulletFreeze(double x, double y, int bounces, Tank t, boolean affectsLiveBulletCount) @@ -35,25 +35,25 @@ public void update() if (this.destroy && this.destroyTimer == 0) { Game.movables.add(new AreaEffectFreeze(this.posX, this.posY)); - Drawing.playSound("resources/freeze.wav"); + Drawing.drawing.playSound("resources/freeze.wav"); } super.update(); } @Override - public void draw(Graphics g) + public void draw() { if (Game.fancyGraphics) { for (int i = 0; i < 30 - 10 * Math.sin(this.age / 12.0); i++) { - g.setColor(new Color(255, 255, 255, 20)); - Drawing.window.fillOval(g, this.posX, this.posY, i, i); + Drawing.drawing.setColor(255, 255, 255, 20); + Drawing.drawing.fillOval(this.posX, this.posY, i, i); } } - super.draw(g); + super.draw(); } } diff --git a/src/tanks/BulletHealing.java b/src/tanks/BulletHealing.java new file mode 100644 index 00000000..3c0dd8cc --- /dev/null +++ b/src/tanks/BulletHealing.java @@ -0,0 +1,77 @@ +package tanks; + +import tanks.AttributeModifier.Operation; +import tanks.tank.Tank; + +public class BulletHealing extends Bullet +{ + public BulletHealing(double x, double y, int bounces, Tank t) + { + super(x, y, bounces, t); + t.liveBullets--; + this.playPopSound = false; + this.baseColorR = 0; + this.baseColorG = 255; + this.baseColorB = 0; + + } + + /** Do not use, instead use the constructor with primitive data types. */ + @Deprecated + public BulletHealing(Double x, Double y, Integer bounces, Tank t, ItemBullet ib) + { + this(x, y, bounces, t); + this.item = ib; + this.item.liveBullets--; + } + + @Override + public void update() + { + this.shoot(); + Game.movables.remove(this); + } + + public void shoot() + { + while(!this.destroy) + { + if (ScreenGame.finished) + this.destroy = true; + + super.update(); + Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.healing)); + } + + if (Game.fancyGraphics) + { + for (int i = 0; i < this.size * 4; i++) + { + Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); + int var = 50; + e.maxAge /= 2; + e.colR = Math.min(255, Math.max(0, this.baseColorR + Math.random() * var - var / 2)); + e.colG = Math.min(255, Math.max(0, this.baseColorG + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, this.baseColorB + Math.random() * var - var / 2)); + e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0 * 4); + Game.effects.add(e); + } + } + } + + @Override + public void collidedWithTank(Tank t) + { + if (!heavy) + this.destroy = true; + + t.lives = Math.min(t.baseLives + 1, t.lives + 0.01 * Panel.frameFrequency); + t.attributes.add(new AttributeModifier("healray", "healray", Operation.add, 1.0)); + } + + @Override + public void collidedWithObject(Movable o) + { + + } +} diff --git a/src/tanks/BulletLaser.java b/src/tanks/BulletLaser.java index 04a94bbe..7f416791 100755 --- a/src/tanks/BulletLaser.java +++ b/src/tanks/BulletLaser.java @@ -1,7 +1,5 @@ package tanks; -import java.awt.Color; - import tanks.tank.Tank; public class BulletLaser extends Bullet @@ -11,7 +9,10 @@ public BulletLaser(double x, double y, int bounces, Tank t) super(x, y, bounces, t); t.liveBullets--; this.playPopSound = false; - this.baseColor = Color.red; + this.baseColorR = 255; + this.baseColorG = 0; + this.baseColorB = 0; + } /** Do not use, instead use the constructor with primitive data types. */ @@ -27,7 +28,7 @@ public BulletLaser(Double x, Double y, Integer bounces, Tank t, ItemBullet ib) public void update() { this.shoot(); - Drawing.pendingSounds.add("resources/laser.wav"); + Drawing.drawing.playSound("resources/laser.wav"); Game.movables.remove(this); } @@ -49,7 +50,9 @@ public void shoot() Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); int var = 50; e.maxAge /= 2; - e.col = new Color((int) Math.min(255, Math.max(0, this.baseColor.getRed() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.baseColor.getGreen() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.baseColor.getBlue() + Math.random() * var - var / 2))); + e.colR = Math.min(255, Math.max(0, this.baseColorR + Math.random() * var - var / 2)); + e.colG = Math.min(255, Math.max(0, this.baseColorG + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, this.baseColorB + Math.random() * var - var / 2)); e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0 * 4); Game.effects.add(e); } diff --git a/src/tanks/Button.java b/src/tanks/Button.java index f5f45799..4428ea9c 100755 --- a/src/tanks/Button.java +++ b/src/tanks/Button.java @@ -1,7 +1,6 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; +import org.lwjgl.glfw.GLFW; public class Button { @@ -21,9 +20,17 @@ public class Button public boolean enabled = true; - Color disabledCol = new Color(200, 200, 200); - Color unselectedCol = new Color(255, 255, 255); - Color selectedCol = new Color(240, 240, 255); + double disabledColR = 200; + double disabledColG = 200; + double disabledColB = 200; + + double unselectedColR = 255; + double unselectedColG = 255; + double unselectedColB = 255; + + double selectedColR = 240; + double selectedColG = 240; + double selectedColB = 255; public Button(double x, double y, double sX, double sY, String text, Runnable f) { @@ -62,62 +69,66 @@ public Button(double x, double y, double sX, double sY, String text, String hove this.hoverText = hoverText.split("---"); } - public void draw(Graphics g) + public void draw() { - Drawing.setInterfaceFontSize(g, 24); - Drawing drawing = Drawing.window; + Drawing drawing = Drawing.drawing; + drawing.setInterfaceFontSize(24); if (!enabled) - g.setColor(this.disabledCol); + drawing.setColor(this.disabledColR, this.disabledColG, this.disabledColB); else if (selected) - g.setColor(this.selectedCol); + drawing.setColor(this.selectedColR, this.selectedColG, this.selectedColB); else - g.setColor(this.unselectedCol); + drawing.setColor(this.unselectedColR, this.unselectedColG, this.unselectedColB); - drawing.fillInterfaceRect(g, posX, posY, sizeX, sizeY); + //drawing.fillInterfaceRect(posX, posY, sizeX, sizeY); - g.setColor(Color.black); - drawing.drawInterfaceText(g, posX, posY + 5, text); + drawing.fillInterfaceRect(posX, posY, sizeX - sizeY, sizeY); + drawing.fillInterfaceOval(posX - sizeX / 2 + sizeY / 2, posY, sizeY, sizeY); + drawing.fillInterfaceOval(posX + sizeX / 2 - sizeY / 2, posY, sizeY, sizeY); + + drawing.setColor(0, 0, 0); + drawing.drawInterfaceText(posX, posY, text); if (enableHover) { if (selected) { - g.setColor(Color.blue); - drawing.fillInterfaceOval(g, this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY, this.sizeY * 3 / 4, this.sizeY * 3 / 4); - g.setColor(Color.white); - drawing.drawInterfaceText(g, this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY + 5, "i"); - Drawing.drawTooltip(g, this.hoverText); + drawing.setColor(0, 0, 255); + drawing.fillInterfaceOval(this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY, this.sizeY * 3 / 4, this.sizeY * 3 / 4); + drawing.setColor(255, 255, 255); + drawing.drawInterfaceText(this.posX + 2 + this.sizeX / 2 - this.sizeY / 2, this.posY, "i"); + drawing.drawTooltip(this.hoverText); } else { - g.setColor(new Color(0, 150, 255)); - drawing.fillInterfaceOval(g, this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY, this.sizeY * 3 / 4, this.sizeY * 3 / 4); - g.setColor(Color.white); - drawing.drawInterfaceText(g, this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY + 5, "i"); + drawing.setColor(0, 150, 255); + drawing.fillInterfaceOval(this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY, this.sizeY * 3 / 4, this.sizeY * 3 / 4); + drawing.setColor(255, 255, 255); + drawing.drawInterfaceText(this.posX + 2 + this.sizeX / 2 - this.sizeY / 2, this.posY, "i"); } } } public void update() { - double mx = Game.window.getInterfaceMouseX(); - double my = Game.window.getInterfaceMouseY(); + double mx = Drawing.drawing.getInterfaceMouseX(); + double my = Drawing.drawing.getInterfaceMouseY(); if (mx > posX - sizeX/2 && mx < posX + sizeX/2 && my > posY - sizeY/2 && my < posY + sizeY/2) selected = true; else selected = false; - if (selected && InputMouse.lClickValid && !clicked && enabled) + if (selected && Game.game.window.validPressedButtons.contains(GLFW.GLFW_MOUSE_BUTTON_1) && !clicked && enabled) { function.run(); clicked = true; - InputMouse.lClickValid = false; + Game.game.window.validPressedButtons.remove((Integer)GLFW.GLFW_MOUSE_BUTTON_1); } - if (!(selected && InputMouse.lClick)) + if (!(selected && Game.game.window.pressedButtons.contains(GLFW.GLFW_MOUSE_BUTTON_1))) clicked = false; } } diff --git a/src/tanks/ButtonObject.java b/src/tanks/ButtonObject.java new file mode 100644 index 00000000..15df2602 --- /dev/null +++ b/src/tanks/ButtonObject.java @@ -0,0 +1,74 @@ +package tanks; + +public class ButtonObject extends Button +{ + public IDrawable object; + + public ButtonObject(IDrawable d, double x, double y, double sX, double sY, Runnable f) + { + super(x, y, sX, sY, "", f); + this.initialize(d); + } + + public ButtonObject(IDrawable d, double x, double y, double sX, double sY, Runnable f, String hoverText) + { + super(x, y, sX, sY, "", f, hoverText); + this.initialize(d); + } + + public ButtonObject(IDrawable d, double x, double y, double sX, double sY) + { + super(x, y, sX, sY, ""); + this.initialize(d); + } + + public ButtonObject(IDrawable d, double x, double y, double sX, double sY, String hoverText) + { + super(x, y, sX, sY, "", hoverText); + this.initialize(d); + } + + public void initialize(IDrawable d) + { + this.object = d; + this.disabledColR = 0; + this.disabledColG = 0; + this.disabledColB = 0; + } + + @Override + public void draw() + { + Drawing drawing = Drawing.drawing; + + this.object.drawForInterface(this.posX, this.posY); + + if (!enabled) + drawing.setColor(this.disabledColR, this.disabledColG, this.disabledColB, 127); + else if (selected) + drawing.setColor(this.selectedColR, this.selectedColG, this.selectedColB, 127); + else + drawing.setColor(0, 0, 0, 0); + + drawing.fillInterfaceRect(posX, posY, sizeX, sizeY); + + if (enableHover) + { + if (selected) + { + drawing.setColor(0, 0, 255); + drawing.fillInterfaceOval(this.posX + this.sizeX / 2, this.posY + this.sizeY / 2, this.sizeY * 1 / 4, this.sizeY * 1 / 4); + drawing.setColor(255, 255, 255); + drawing.drawInterfaceText(this.posX + 2 + this.sizeX / 2, this.posY + this.sizeY / 2, "i"); + drawing.drawTooltip(this.hoverText); + } + else + { + drawing.setColor(0, 150, 255); + drawing.fillInterfaceOval(this.posX + this.sizeX / 2, this.posY + this.sizeY / 2, this.sizeY * 1 / 4, this.sizeY * 1 / 4); + drawing.setColor(255, 255, 255); + drawing.drawInterfaceText(this.posX + 2 + this.sizeX / 2, this.posY + this.sizeY / 2, "i"); + } + } + } +} diff --git a/src/tanks/Drawing.java b/src/tanks/Drawing.java index 48965f97..5dec1e1a 100755 --- a/src/tanks/Drawing.java +++ b/src/tanks/Drawing.java @@ -1,80 +1,49 @@ package tanks; -import java.awt.Color; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.MouseInfo; -import java.awt.font.FontRenderContext; import java.util.ArrayList; -import javax.swing.*; - -@SuppressWarnings("serial") -public class Drawing extends JFrame +public class Drawing { - public static int sizeX = 1400;//1920; - public static int sizeY = 900;//1100; + protected static boolean initialized = false; + + public int sizeX = 1400;//1920; + public int sizeY = 900;//1100; - public static double playerX = sizeX / 2; - public static double playerY = sizeY / 2; + public double playerX = sizeX / 2; + public double playerY = sizeY / 2; - public static double interfaceSizeX = 1400; - public static double interfaceSizeY = 900; + public double interfaceSizeX = 1400; + public double interfaceSizeY = 900; public double scale = 1; - public static double unzoomedScale = 1; + public double unzoomedScale = 1; - public static double interfaceScale = 1; + public double interfaceScale = 1; - public static boolean enableMovingCamera = false; - public static boolean enableMovingCameraX = false; - public static boolean enableMovingCameraY = false; + public boolean enableMovingCamera = false; + public boolean enableMovingCameraX = false; + public boolean enableMovingCameraY = false; - public static int statsHeight = 40; + public int statsHeight = 40; - public static boolean movingCamera = false; - - public static Drawing window = new Drawing(); + public boolean movingCamera = false; - public static int mouseXoffset = 0; - public static int mouseYoffset = 0; + public static Drawing drawing; - public static FontRenderContext frc = new FontRenderContext(null, true, true); - public static ArrayList pendingSounds = new ArrayList(); - - private Drawing() - { - this.addMouseListener(new InputMouse()); - this.addKeyListener(new InputKeyboard()); - this.addMouseWheelListener(new InputScroll()); - this.addMouseMotionListener(new InputMouse()); + public int mouseXoffset = 0; + public int mouseYoffset = 0; - //this.setSize((int)(sizeX * scale), (int) ((sizeY + yOffset) * scale )); - - Container contentPane = this.getContentPane(); - Panel.panel.setPreferredSize(new Dimension(sizeX, sizeY + statsHeight)); - contentPane.add(Panel.panel); - contentPane.setSize(sizeX, sizeY + statsHeight); + public ArrayList pendingSounds = new ArrayList(); + + public double fontSize = 1; - this.pack(); - this.setVisible(true); - - this.setResizable(true); - this.setMinimumSize(new Dimension(350, 265)); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - } + private Drawing() {} - public void initializeMouseOffsets() + public static void initialize() { - mouseXoffset = 0 - (int) ((Drawing.window.getSize().getWidth() - Panel.panel.getSize().getWidth()) / 2); - mouseYoffset = 1 - (int) ((Drawing.window.getSize().getHeight() - Panel.panel.getSize().getHeight()) / 2); + if (!initialized) + drawing = new Drawing(); - if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) - { - mouseYoffset += 6; - } + initialized = true; } public void setScale(double scale) @@ -96,227 +65,287 @@ public void setSize(int x, int y) this.pack(); }*/ - public void fillOval(Graphics g, double x, double y, double sizeX, double sizeY) + public void setColor(double r, double g, double b) + { + Game.game.window.setColor(r, g, b); + } + + public void setColor(double r, double g, double b, double a) { - int drawX = (int) Math.round(scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.sizeX * this.scale) / 2); - int drawY = (int) Math.round(scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.sizeY * this.scale) / 2); + Game.game.window.setColor(r, g, b, a); + } + + public void fillOval(double x, double y, double sizeX, double sizeY) + { + double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * this.scale) / 2); + double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * this.scale) / 2); if (drawX - 200 * this.scale > Panel.windowWidth || drawX + 200 * this.scale < 0 || drawY - 200 * this.scale > Panel.windowHeight || drawY + 200 * this.scale < 0) return; - int drawSizeX = (int) Math.round(sizeX * scale); - int drawSizeY = (int) Math.round(sizeY * scale); + double drawSizeX = (sizeX * scale); + double drawSizeY = (sizeY * scale); - g.fillOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.fillOval(drawX, drawY, drawSizeX, drawSizeY); } - public void fillForcedOval(Graphics g, double x, double y, double sizeX, double sizeY) + public void fillForcedOval(double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.sizeX * this.scale) / 2); - int drawY = (int) Math.round(scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.sizeY * this.scale) / 2); + double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * this.scale) / 2); + double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * this.scale) / 2); - int drawSizeX = (int) Math.round(sizeX * scale); - int drawSizeY = (int) Math.round(sizeY * scale); + double drawSizeX = (sizeX * scale); + double drawSizeY = (sizeY * scale); - g.fillOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.fillOval(drawX, drawY, drawSizeX, drawSizeY); } - public void drawOval(Graphics g, double x, double y, double sizeX, double sizeY) + public void drawOval(double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.sizeX * scale) / 2); - int drawY = (int) Math.round(scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.sizeY * scale) / 2); + double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2); + double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2); if (drawX - 200 * scale > Panel.windowWidth || drawX + 200 * scale < 0 || drawY - 200 * scale > Panel.windowHeight || drawY + 200 * scale < 0) return; - int drawSizeX = (int) Math.round(sizeX * scale); - int drawSizeY = (int) Math.round(sizeY * scale); + double drawSizeX = (sizeX * scale); + double drawSizeY = (sizeY * scale); - g.drawOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.drawOval(drawX, drawY, drawSizeX, drawSizeY); } - public void fillRect(Graphics g, double x, double y, double sizeX, double sizeY) + public void fillRect(double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.sizeX * scale) / 2); - int drawY = (int) Math.round(scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.sizeY * scale) / 2); + double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2); + double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2); if (drawX - 200 * scale > Panel.windowWidth || drawX + 200 * scale < 0 || drawY - 200 * scale > Panel.windowHeight || drawY + 200 * scale < 0) return; + + double drawSizeX = (sizeX * scale); + double drawSizeY = (sizeY * scale); - int drawSizeX = (int) Math.round(sizeX * scale); - int drawSizeY = (int) Math.round(sizeY * scale); - - g.fillRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.fillRect(drawX, drawY, drawSizeX, drawSizeY); } - public void fill3DRect(Graphics g, double x, double y, double sizeX, double sizeY, boolean raised) + public void drawImage(String img, double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.sizeX * scale) / 2); - int drawY = (int) Math.round(scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.sizeY * scale) / 2); + double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2); + double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2); if (drawX - 200 * scale > Panel.windowWidth || drawX + 200 * scale < 0 || drawY - 200 * scale > Panel.windowHeight || drawY + 200 * scale < 0) return; + + double drawSizeX = (sizeX * scale); + double drawSizeY = (sizeY * scale); - int drawSizeX = (int) Math.round(sizeX * scale); - int drawSizeY = (int) Math.round(sizeY * scale); + Game.game.window.drawImage(drawX, drawY, drawSizeX, drawSizeY, img, false); + } + + public void fillQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) + { + double dX1 = getPointX(x1); + double dX2 = getPointX(x2); + double dX3 = getPointX(x3); + double dX4 = getPointX(x4); - g.fill3DRect(drawX, drawY, drawSizeX, drawSizeY, raised); + double dY1 = getPointY(y1); + double dY2 = getPointY(y2); + double dY3 = getPointY(y3); + double dY4 = getPointY(y4); + + Game.game.window.fillQuad(dX1, dY1, dX2, dY2, dX3, dY3, dX4, dY4); } + + public void fillInterfaceQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) + { + double dX1 = getInterfacePointX(x1); + double dX2 = getInterfacePointX(x2); + double dX3 = getInterfacePointX(x3); + double dX4 = getInterfacePointX(x4); - public void fillBackgroundRect(Graphics g, double x, double y, double sizeX, double sizeY) + double dY1 = getInterfacePointY(y1); + double dY2 = getInterfacePointY(y2); + double dY3 = getInterfacePointY(y3); + double dY4 = getInterfacePointY(y4); + + Game.game.window.fillQuad(dX1, dY1, dX2, dY2, dX3, dY3, dX4, dY4); + } + + public double getPointX(double x) + { + return (scale * (x + getPlayerOffsetX()) + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2); + } + + public double getPointY(double y) { - int drawX = (int) Math.round(scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.sizeX * scale) / 2); - int drawY = (int) Math.round(scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.sizeY * scale) / 2); - int drawSizeX = (int) Math.round(sizeX * scale); - int drawSizeY = (int) Math.round(sizeY * scale); + return (scale * (y + getPlayerOffsetY()) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2); + } + + public double getInterfacePointX(double x) + { + return (interfaceScale * (x) + Math.max(0, Panel.windowWidth - this.interfaceSizeX * interfaceScale) / 2); + } + + public double getInterfacePointY(double y) + { + return (interfaceScale * (y) + Math.max(0, Panel.windowHeight - statsHeight - this.interfaceSizeY * interfaceScale) / 2); + } + + public void fillBackgroundRect(double x, double y, double sizeX, double sizeY) + { + double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2); + double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2); + double drawSizeX = (sizeX * scale); + double drawSizeY = (sizeY * scale); - g.fillRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.fillRect(drawX, drawY, drawSizeX, drawSizeY); } - public void drawRect(Graphics g, double x, double y, double sizeX, double sizeY) + public void drawRect(double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.sizeX * scale) / 2); - int drawY = (int) Math.round(scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.sizeY * scale) / 2); + double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2); + double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2); if (drawX - 200 * scale > Panel.windowWidth || drawX + 200 * scale < 0 || drawY - 200 * scale > Panel.windowHeight || drawY + 200 * scale < 0) return; - int drawSizeX = (int) Math.round(sizeX * scale); - int drawSizeY = (int) Math.round(sizeY * scale); + double drawSizeX = Math.round(sizeX * scale); + double drawSizeY = Math.round(sizeY * scale); - g.drawRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.drawRect(drawX, drawY, drawSizeX, drawSizeY); } - public void fillInterfaceOval(Graphics g, double x, double y, double sizeX, double sizeY) + public void fillInterfaceOval(double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); - int drawSizeX = (int) Math.round(sizeX * interfaceScale); - int drawSizeY = (int) Math.round(sizeY * interfaceScale); + double drawX = (interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + double drawY = (interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); + double drawSizeX = (sizeX * interfaceScale); + double drawSizeY = (sizeY * interfaceScale); - g.fillOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.fillOval(drawX, drawY, drawSizeX, drawSizeY); } - public void drawInterfaceOval(Graphics g, double x, double y, double sizeX, double sizeY) + public void drawInterfaceOval(double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); - int drawSizeX = (int) Math.round(sizeX * interfaceScale); - int drawSizeY = (int) Math.round(sizeY * interfaceScale); + double drawX = (interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + double drawY = (interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); + double drawSizeX = (sizeX * interfaceScale); + double drawSizeY = (sizeY * interfaceScale); - g.drawOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.drawOval(drawX, drawY, drawSizeX, drawSizeY); } - public void fillInterfaceRect(Graphics g, double x, double y, double sizeX, double sizeY) + public void fillInterfaceRect(double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); - int drawSizeX = (int) Math.round(sizeX * interfaceScale); - int drawSizeY = (int) Math.round(sizeY * interfaceScale); - - g.fillRect(drawX, drawY, drawSizeX, drawSizeY); + double drawX = (interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + double drawY = (interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); + double drawSizeX = (sizeX * interfaceScale); + double drawSizeY = (sizeY * interfaceScale); + + Game.game.window.fillRect(drawX, drawY, drawSizeX, drawSizeY); } - public void fillInterfaceProgressRect(Graphics g, double x, double y, double sizeX, double sizeY, double progress) + public void fillInterfaceProgressRect(double x, double y, double sizeX, double sizeY, double progress) { - int drawX = (int) Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); - int drawSizeX = (int) Math.round(sizeX * interfaceScale * progress); - int drawSizeY = (int) Math.round(sizeY * interfaceScale); + double drawX = (interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + double drawY = (interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); + double drawSizeX = (sizeX * interfaceScale * progress); + double drawSizeY = (sizeY * interfaceScale); - g.fillRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.fillRect(drawX, drawY, drawSizeX, drawSizeY); } - public void drawInterfaceImage(Graphics g, Image img, double x, double y, double sizeX, double sizeY) + public void drawInterfaceImage(String img, double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); - int drawSizeX = (int) Math.round(sizeX * interfaceScale); - int drawSizeY = (int) Math.round(sizeY * interfaceScale); + double drawX = (interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + double drawY = (interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); + double drawSizeX = (sizeX * interfaceScale); + double drawSizeY = (sizeY * interfaceScale); - g.drawImage(img, drawX, drawY, drawSizeX, drawSizeY, null); + Game.game.window.drawImage(drawX, drawY, drawSizeX, drawSizeY, img, false); } - public void drawInterfaceRect(Graphics g, double x, double y, double sizeX, double sizeY) + public void drawInterfaceRect(double x, double y, double sizeX, double sizeY) { - int drawX = (int) Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); + int drawX = (int) Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + int drawY = (int) Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); int drawSizeX = (int) Math.round(sizeX * interfaceScale); int drawSizeY = (int) Math.round(sizeY * interfaceScale); - g.drawRect(drawX , drawY, drawSizeX, drawSizeY); + Game.game.window.drawRect(drawX, drawY, drawSizeX, drawSizeY); } - public void drawText(Graphics g, double x, double y, String text) + public void drawText(double x, double y, String text) { - double sizeX = Math.round(g.getFont().getStringBounds(text, frc).getWidth()); - - double sizeY = g.getFont().getSize() / 3 / scale; - //int size = text.length() * g.getFont().getSize() / 2; - int drawX = (int) (scale * x - sizeX / 2 + Math.max(0, Panel.windowWidth - Drawing.sizeX * scale) / 2); - int drawY = (int) (scale * (y + sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.sizeY * scale) / 2); - g.drawString(text, drawX, drawY); - - //g.setColor(Color.red); - //g.drawRect((int)((x - sizeX / 2) * scale), (int)((y - sizeY * 3 / 2) * scale), (int)g.getFont().getStringBounds(text, frc).getWidth(), (int)g.getFont().getStringBounds(text, frc).getHeight()); + double sizeX = Game.game.window.fontRenderer.getStringSizeX(this.fontSize, text); + double sizeY = Game.game.window.fontRenderer.getStringSizeY(this.fontSize, text); + + int drawX = (int) (scale * x - sizeX / 2 + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2); + int drawY = (int) (scale * (y + sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2); + + Game.game.window.fontRenderer.drawString(drawX, drawY, this.fontSize, this.fontSize, text); } - public void drawInterfaceText(Graphics g, double x, double y, String text) + public void drawInterfaceText(double x, double y, String text) { - double sizeX = Math.round(g.getFont().getStringBounds(text, frc).getWidth()); - - double sizeY = g.getFont().getSize() / 3 / Drawing.interfaceScale; - int drawX = (int) (interfaceScale * x - sizeX / 2 + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) (interfaceScale * (y + sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); - g.drawString(text, drawX, drawY); + double sizeX = Game.game.window.fontRenderer.getStringSizeX(this.fontSize, text); + double sizeY = Game.game.window.fontRenderer.getStringSizeY(this.fontSize, text); + + int drawX = (int) (interfaceScale * x - sizeX / 2 + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + int drawY = (int) (interfaceScale * y - sizeY / 2 + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); + + Game.game.window.fontRenderer.drawString(drawX, drawY, this.fontSize, this.fontSize, text); } - public void drawInterfaceText(Graphics g, double x, double y, String text, boolean rightAligned) + public void drawInterfaceText(double x, double y, String text, boolean rightAligned) { - double sizeX = Math.round(g.getFont().getStringBounds(text, frc).getWidth()); + double sizeX = Game.game.window.fontRenderer.getStringSizeX(this.fontSize, text); + double sizeY = Game.game.window.fontRenderer.getStringSizeY(this.fontSize, text); + //System.out.println(sizeX); + //System.out.println(sizeY); - double sizeY = g.getFont().getSize() / 3 / Drawing.interfaceScale; double offX = sizeX; if (!rightAligned) offX = 0; - int drawX = (int) (interfaceScale * x - offX + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) (interfaceScale * (y + sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); - g.drawString(text, drawX, drawY); + int drawX = (int) (interfaceScale * x - offX + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + int drawY = (int) (interfaceScale * (y + sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); + Game.game.window.fontRenderer.drawString(drawX, drawY, this.fontSize, this.fontSize, text); } - public void drawUncenteredInterfaceText(Graphics g, double x, double y, String text) + public void drawUncenteredInterfaceText(double x, double y, String text) { - int drawX = (int) (interfaceScale * x + Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2); - int drawY = (int) (interfaceScale * y + Math.max(0, Panel.windowHeight - statsHeight - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2); - g.drawString(text, drawX, drawY); + int drawX = (int) (interfaceScale * x + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); + int drawY = (int) (interfaceScale * y + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); + Game.game.window.fontRenderer.drawString(drawX, drawY, this.fontSize, this.fontSize, text); } - public static void setFontSize(Graphics g, double size) + public void setFontSize(double size) { - g.setFont(g.getFont().deriveFont(Font.BOLD, (float) (size * Drawing.window.scale))); + this.fontSize = size / 36.0 * scale; } - public static void setInterfaceFontSize(Graphics g, double size) + public void setInterfaceFontSize(double size) { - g.setFont(g.getFont().deriveFont(Font.BOLD, (float) (size * Drawing.interfaceScale))); + this.fontSize = size / 36.0 * interfaceScale; } - public static void drawTooltip(Graphics g, String[] text) + public void drawTooltip(String[] text) { - double x = Game.window.getInterfaceMouseX(); - double y = Game.window.getInterfaceMouseY(); + double x = getInterfaceMouseX(); + double y = getInterfaceMouseY(); int xPadding = (int) (16); int yPadding = (int) (8); - Drawing.setInterfaceFontSize(g, 14); + setInterfaceFontSize(14); int sizeX = 0; for (int i = 0; i < text.length; i++) { - sizeX = Math.max(sizeX, (int) Math.round(g.getFont().getStringBounds(text[i], frc).getWidth() / interfaceScale) + xPadding); + sizeX = Math.max(sizeX, (int) Math.round(Game.game.window.fontRenderer.getStringSizeX(fontSize, text[i]) / this.interfaceScale) + xPadding); } int sizeY = 14; @@ -324,21 +353,21 @@ public static void drawTooltip(Graphics g, String[] text) double drawX = x + sizeX / 2 + xPadding; double drawY = y + sizeY / 2 + yPadding * text.length; - g.setColor(new Color(0, 0, 0, 127)); - Drawing.window.fillInterfaceRect(g, drawX, drawY, sizeX + xPadding * 2, sizeY + yPadding * 2 * text.length); + setColor(0, 0, 0, 127); + fillInterfaceRect(drawX, drawY, sizeX + xPadding * 2, sizeY + yPadding * 2 * text.length); - g.setColor(Color.WHITE); + setColor(255, 255, 255); for (int i = 0; i < text.length; i++) { - Drawing.window.drawUncenteredInterfaceText(g, x + xPadding, y + yPadding * (2 * i + 1) + 14, text[i]); + drawUncenteredInterfaceText(x + xPadding, y + 2 + yPadding * (2 * i + 1), text[i]); } //return (y - (drawY / Window.scale + sizeY + yPadding / Window.scale * 2)); } - public static void playSound(String sound) + public void playSound(String sound) { - Drawing.pendingSounds.add(sound); + pendingSounds.add(sound); } public double toGameCoordsX(double x) @@ -346,11 +375,11 @@ public double toGameCoordsX(double x) double x1 = x; if (enableMovingCamera && movingCamera && enableMovingCameraX) - x1 += (Panel.panel.getSize().getWidth() - Drawing.interfaceScale * Drawing.interfaceSizeX) / 2 / Drawing.interfaceScale; + x1 += (Game.game.window.absoluteWidth - interfaceScale * interfaceSizeX) / 2 / interfaceScale; double rawX = interfaceScale * (x1); - rawX -= (1400 - Drawing.sizeX * scale / interfaceScale) / 2 * interfaceScale; + rawX -= (1400 - sizeX * scale / interfaceScale) / 2 * interfaceScale; double gameX = (rawX) / scale - getPlayerMouseOffsetX(); @@ -362,11 +391,11 @@ public double toGameCoordsY(double y) double y1 = y; if (enableMovingCamera && movingCamera && enableMovingCameraX) - y1 += (Panel.panel.getSize().getHeight() - Drawing.interfaceScale * Drawing.interfaceSizeY - Drawing.statsHeight) / 2 / Drawing.interfaceScale; + y1 += (Game.game.window.absoluteHeight - interfaceScale * interfaceSizeY - statsHeight) / 2 / interfaceScale; double rawY = interfaceScale * (y1); - rawY -= (900 - Drawing.sizeY * scale / interfaceScale) / 2 * interfaceScale; + rawY -= (900 - sizeY * scale / interfaceScale) / 2 * interfaceScale; double gameY = (rawY) / scale - getPlayerMouseOffsetY(); @@ -385,34 +414,20 @@ public double getMouseY() public double getInterfaceMouseX() { - try - { - return (MouseInfo.getPointerInfo().getLocation().getX() - this.getLocation().getX() - Math.max(0, Panel.windowWidth - Drawing.interfaceSizeX * Drawing.interfaceScale) / 2) / interfaceScale + mouseXoffset / Drawing.interfaceScale; - } - catch (Exception e) - { - return 0; - } + return (Game.game.window.absoluteMouseX - Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2) / interfaceScale + mouseXoffset / interfaceScale; } public double getInterfaceMouseY() { - try - { - return ((MouseInfo.getPointerInfo().getLocation().getY() - this.getLocation().getY() - Math.max(0, Panel.windowHeight - (1) - Drawing.interfaceSizeY * Drawing.interfaceScale) / 2)) / interfaceScale + mouseYoffset / Drawing.interfaceScale; - } - catch (Exception e) - { - return 0; - } + return (Game.game.window.absoluteMouseY - Math.max(0, Panel.windowHeight - this.statsHeight - interfaceSizeY * interfaceScale) / 2) / interfaceScale + mouseYoffset / interfaceScale; } - public void setScreenSize(int x, int y) + /*public void setScreenSize(int x, int y) { sizeX = x; sizeY = y; this.setSize((int) (x * scale), (int) ((y) * scale)); - } + }*/ public void setScreenBounds(int x, int y) { @@ -422,49 +437,49 @@ public void setScreenBounds(int x, int y) Game.currentSizeY = y / Game.tank_size; } - public static double getPlayerOffsetX() + public double getPlayerOffsetX() { - if (!enableMovingCamera || !movingCamera || !enableMovingCameraX) + if (!enableMovingCameraX) return 0; - double result = (playerX - (Panel.windowWidth) / Drawing.window.scale / 2); + double result = (playerX - (Panel.windowWidth) / scale / 2); if (result < 0) return 0; - else if (result + (Panel.windowWidth) / Drawing.window.scale > Drawing.sizeX) - return 0 - (Drawing.sizeX - (Panel.windowWidth) / Drawing.window.scale); + else if (result + (Panel.windowWidth) / scale > sizeX) + return 0 - (sizeX - (Panel.windowWidth) / scale); else return 0 - result; } - public static double getPlayerOffsetY() + public double getPlayerOffsetY() { - if (!enableMovingCamera || !movingCamera || !enableMovingCameraY) + if (!enableMovingCameraY) return 0; - double result = (playerY - Panel.windowHeight / Drawing.window.scale / 2); + double result = (playerY - Panel.windowHeight / scale / 2); if (result < 0) return 0; - else if (result + (Panel.windowHeight - statsHeight) / Drawing.window.scale > Drawing.sizeY) - return 0 - (Drawing.sizeY - (Panel.windowHeight - statsHeight) / Drawing.window.scale); + else if (result + (Panel.windowHeight - statsHeight) / scale > sizeY) + return 0 - (sizeY - (Panel.windowHeight - statsHeight) / scale); else return 0 - result; } - public static double getPlayerMouseOffsetX() + public double getPlayerMouseOffsetX() { if (!enableMovingCamera || !movingCamera || !enableMovingCameraX) return 0; - return getPlayerOffsetX() + (Game.currentSizeX / 28.0 - 1) * Drawing.interfaceSizeX / 2; + return getPlayerOffsetX() + (Game.currentSizeX / 28.0 - 1) * interfaceSizeX / 2; } - public static double getPlayerMouseOffsetY() + public double getPlayerMouseOffsetY() { if (!enableMovingCamera || !movingCamera || !enableMovingCameraY) return 0; - return getPlayerOffsetY() + (Game.currentSizeY / 18.0 - 1) * Drawing.interfaceSizeY / 2; + return getPlayerOffsetY() + (Game.currentSizeY / 18.0 - 1) * interfaceSizeY / 2; } } diff --git a/src/tanks/Effect.java b/src/tanks/Effect.java index 77e1648b..09c5f9d9 100755 --- a/src/tanks/Effect.java +++ b/src/tanks/Effect.java @@ -1,14 +1,14 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - public class Effect extends Movable { - public enum EffectType {fire, smokeTrail, trail, ray, mineExplosion, laser, piece, obstaclePiece, charge, tread, darkFire, electric, stun} + public enum EffectType {fire, smokeTrail, trail, ray, mineExplosion, laser, piece, obstaclePiece, charge, tread, darkFire, electric, healing, stun} public EffectType type; double age = 0; - public Color col; + public double colR; + public double colG; + public double colB; + public double maxAge = 100; public double size; public double ffOpacityMultiplier = Math.min(1, Panel.frameFrequency); @@ -67,7 +67,7 @@ else if (type == EffectType.smokeTrail) else if (type == EffectType.trail) this.maxAge = 50; else if (type == EffectType.ray) - this.maxAge = 1; + this.maxAge = 20; else if (type == EffectType.mineExplosion) this.maxAge = 20; else if (type == EffectType.laser) @@ -98,6 +98,8 @@ else if (type == EffectType.stun) this.size = Math.random() * 5 + 5; this.distance = Math.random() * 50 + 25; } + else if (type == EffectType.healing) + this.maxAge = 21; } protected void refurbish() @@ -108,7 +110,9 @@ protected void refurbish() this.vY = 0; this.type = null; this.age = 0; - this.col = null; + this.colR = 0; + this.colG = 0; + this.colB = 0; this.maxAge = Math.random() * 100 + 50; this.size = 0; this.ffOpacityMultiplier = Math.min(1, Panel.frameFrequency); @@ -121,7 +125,7 @@ protected void refurbish() public void checkCollision() {} @Override - public void draw(Graphics p) + public void draw() { if (this.maxAge < this.age) return; @@ -130,20 +134,18 @@ public void draw(Graphics p) Game.exitToCrash(new RuntimeException("Effect with negative age")); double opacityMultiplier = ScreenGame.finishTimer / ScreenGame.finishTimerMax; - Drawing drawing = Drawing.window; + Drawing drawing = Drawing.drawing; if (this.type == EffectType.fire) { - int size = (int) (this.age * 3 + 10); + double size = (this.age * 3 + 10); double rawOpacity = (1.0 - (this.age)/20.0); rawOpacity *= rawOpacity * rawOpacity; - int opacity = (int)(rawOpacity * 255); - - int green = Math.min(255, (int)(255 - 255.0*(this.age / 20.0))); - Color col = new Color(255, green, 0, Math.min(255, Math.max(0, (int) (opacity * opacityMultiplier * ffOpacityMultiplier)))); + double opacity = (rawOpacity * 255); - p.setColor(col); - drawing.fillOval(p, this.posX, this.posY, size, size); + double green = Math.min(255, (255 - 255.0*(this.age / 20.0))); + drawing.setColor(255, green, 0, Math.min(255, Math.max(0, (opacity * opacityMultiplier * ffOpacityMultiplier)))); + drawing.fillOval(this.posX, this.posY, size, size); } else if (this.type == EffectType.smokeTrail) @@ -152,61 +154,59 @@ else if (this.type == EffectType.smokeTrail) int size = 20; double rawOpacity = (1.0 - (this.age)/200.0); rawOpacity *= rawOpacity * rawOpacity; - int opacity = (int)(rawOpacity * 100); - - Color col = new Color(0, 0, 0, Math.min(255, Math.max(0, (int) (opacity * opacityMultiplier * opacityModifier * ffOpacityMultiplier)))); - - p.setColor(col); - drawing.fillOval(p, this.posX, this.posY, size, size); + double opacity = (rawOpacity * 100); + + drawing.setColor(0, 0, 0, Math.min(255, Math.max(0, (opacity * opacityMultiplier * opacityModifier * ffOpacityMultiplier)))); + drawing.fillOval(this.posX, this.posY, size, size); } else if (this.type == EffectType.trail) { - int size = (int)Math.min(20, this.age / 20.0 + 10); + double size = Math.min(20, this.age / 20.0 + 10); double rawOpacity = (1.0 - (this.age)/50.0); rawOpacity *= rawOpacity * rawOpacity; - int opacity = (int)(rawOpacity * 25); + double opacity = (rawOpacity * 25); - Color col = new Color(127, 127, 127, Math.min(255, Math.max(0, (int) (opacity * opacityMultiplier * ffOpacityMultiplier)))); + drawing.setColor(127, 127, 127, Math.min(255, Math.max(0, (opacity * opacityMultiplier * ffOpacityMultiplier)))); - p.setColor(col); - drawing.fillOval(p, this.posX, this.posY, size, size); + drawing.fillOval(this.posX, this.posY, size, size); } else if (this.type == EffectType.ray) { int size = 6; - p.setColor(new Color(0, 0, 0, 50)); - drawing.fillOval(p, this.posX, this.posY, size, size); + drawing.setColor(0, 0, 0, 50); + drawing.fillOval(this.posX, this.posY, size, size); + Game.removeEffects.add(this); } else if (this.type == EffectType.mineExplosion) { - int size = (int) (radius * 2); - int opacity = (int) (100 - this.age * 5); - p.setColor(new Color(255, 0, 0, opacity)); - drawing.fillForcedOval(p, this.posX, this.posY, size, size); + double size = (radius * 2); + double opacity = (100 - this.age * 5); + drawing.setColor(255, 0, 0, opacity); + drawing.fillForcedOval(this.posX, this.posY, size, size); } else if (this.type == EffectType.laser) { double size = Bullet.bullet_size - this.age / 2; - p.setColor(new Color(255, 0, 0)); - drawing.fillOval(p, this.posX, this.posY, size, size); + drawing.setColor(255, 0, 0); + drawing.fillOval(this.posX, this.posY, size, size); } else if (this.type == EffectType.piece) { - int size = 1 + (int) (Bullet.bullet_size * (1 - this.age / this.maxAge)); - p.setColor(col); - drawing.fillOval(p, this.posX, this.posY, size, size); + double size = 1 + (Bullet.bullet_size * (1 - this.age / this.maxAge)); + drawing.setColor(this.colR, this.colG, this.colB); + drawing.fillOval(this.posX, this.posY, size, size); } else if (this.type == EffectType.obstaclePiece) { - int size = 1 + (int) (Bullet.bullet_size * (1 - this.age / this.maxAge)); - p.setColor(col); - drawing.fillRect(p, this.posX, this.posY, size, size); + double size = 1 + (Bullet.bullet_size * (1 - this.age / this.maxAge)); + drawing.setColor(this.colR, this.colG, this.colB); + drawing.fillRect(this.posX, this.posY, size, size); } else if (this.type == EffectType.charge) { - int size = 1 + (int) (Bullet.bullet_size * (this.age / this.maxAge)); - p.setColor(col); - drawing.fillOval(p, this.posX, this.posY, size, size); + double size = 1 + (Bullet.bullet_size * (this.age / this.maxAge)); + drawing.setColor(this.colR, this.colG, this.colB); + drawing.fillOval(this.posX, this.posY, size, size); } else if (this.type == EffectType.tread) { @@ -217,39 +217,44 @@ else if (this.type == EffectType.tread) opacityFactor = 4; } - int opacity = (int) (255 - this.age / opacityFactor) / 4; - p.setColor(new Color(0, 0, 0, opacity)); - drawing.fillRect(p, this.posX, this.posY, size * Obstacle.draw_size / Obstacle.obstacle_size, size * Obstacle.draw_size / Obstacle.obstacle_size); + double opacity = (255 - this.age / opacityFactor) / 4; + drawing.setColor(0, 0, 0, opacity); + drawing.fillRect(this.posX, this.posY, size * Obstacle.draw_size / Obstacle.obstacle_size, size * Obstacle.draw_size / Obstacle.obstacle_size); } else if (this.type == EffectType.darkFire) { - int size = (int) (this.age * 3 + 10); + double size = (this.age * 3 + 10); double rawOpacity = (1.0 - (this.age)/20.0); rawOpacity *= rawOpacity * rawOpacity; - int opacity = (int)(rawOpacity * 255); + double opacity = (rawOpacity * 255); - int red = Math.min(255, (int)(128 - 128.0 * (this.age / 20.0))); - Color col = new Color(red / 2, 0, red, Math.min(255, Math.max(0, (int) (opacity * opacityMultiplier * ffOpacityMultiplier)))); + double red = Math.min(255, (128 - 128.0 * (this.age / 20.0))); + drawing.setColor(red / 2, 0, red, Math.min(255, Math.max(0, (opacity * opacityMultiplier * ffOpacityMultiplier)))); - p.setColor(col); - drawing.fillOval(p, this.posX, this.posY, size, size); + drawing.fillOval(this.posX, this.posY, size, size); } else if (this.type == EffectType.stun) { - int size = 1 + (int) (this.size * Math.min(Math.min(1, (this.maxAge - this.age) * 3 / this.maxAge), Math.min(1, this.age * 3 / this.maxAge))); + double size = 1 + (this.size * Math.min(Math.min(1, (this.maxAge - this.age) * 3 / this.maxAge), Math.min(1, this.age * 3 / this.maxAge))); double angle = this.angle + this.age / 20; - int distance = 1 + (int) (this.distance * Math.min(Math.min(1, (this.maxAge - this.age) * 3 / this.maxAge), Math.min(1, this.age * 3 / this.maxAge))); + double distance = 1 + (this.distance * Math.min(Math.min(1, (this.maxAge - this.age) * 3 / this.maxAge), Math.min(1, this.age * 3 / this.maxAge))); - p.setColor(col); + drawing.setColor(this.colR, this.colG, this.colB); double[] o = Movable.getLocationInDirection(angle, distance); - drawing.fillOval(p, this.posX + o[0], this.posY + o[1], size, size); + drawing.fillOval(this.posX + o[0], this.posY + o[1], size, size); } else if (this.type == EffectType.electric) + { + double size = Math.max(0, Bullet.bullet_size - this.age / 2); + drawing.setColor(0, 255, 255); + drawing.fillOval(this.posX, this.posY, size, size); + } + else if (this.type == EffectType.healing) { double size = Bullet.bullet_size - this.age / 2; - p.setColor(new Color(0, 255, 255)); - drawing.fillOval(p, this.posX, this.posY, size, size); + drawing.setColor(0, 255, 0); + drawing.fillOval(this.posX, this.posY, size, size); } else { diff --git a/src/tanks/Firework.java b/src/tanks/Firework.java index ef690889..4b66cb8c 100755 --- a/src/tanks/Firework.java +++ b/src/tanks/Firework.java @@ -1,7 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; import java.util.ArrayList; public class Firework extends Movable @@ -17,8 +15,10 @@ enum FireworkType {rocket, particle, trail} public ArrayList list; public ArrayList removeList; - public Color color; - + public double colorR; + public double colorG; + public double colorB; + public Firework(FireworkType t, double x, double y, ArrayList list, ArrayList removeList) { super(x, y); @@ -75,27 +75,32 @@ else if (col < 256 * 6) b = 256 * 6 - col - 1; } - this.color = new Color(r, g, b); + this.colorR = r; + this.colorG = g; + this.colorB = b; } - public void drawUpdate(Graphics g) + public void drawUpdate() { if (type == FireworkType.rocket) { this.vY += 0.0625 * Panel.frameFrequency; - g.setColor(this.color); - Drawing.window.fillOval(g, posX, posY, this.size, this.size); + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB); + Drawing.drawing.fillOval(posX, posY, this.size, this.size); Firework f = new Firework(FireworkType.trail, this.posX, this.posY, this.list, this.removeList); f.maxAge = 30; - f.color = this.color; + f.colorR = this.colorR; + f.colorG = this.colorG; + f.colorB = this.colorB; + f.size = this.size; this.list.add(f); if (this.age >= this.maxAge) { - Drawing.playSound("resources/destroy.wav"); + Drawing.drawing.playSound("resources/destroy.wav"); removeList.add(this); @@ -104,7 +109,9 @@ public void drawUpdate(Graphics g) Firework e = new Firework(FireworkType.particle, this.posX, this.posY, this.list, this.removeList); e.size = 4; int var = 50; - e.color = new Color((int) Math.min(255, Math.max(0, this.color.getRed() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.color.getGreen() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.color.getBlue() + Math.random() * var - var / 2))); + e.colorR = Math.min(255, Math.max(0, this.colorR + Math.random() * var - var / 2)); + e.colorG = Math.min(255, Math.max(0, this.colorG + Math.random() * var - var / 2)); + e.colorB = Math.min(255, Math.max(0, this.colorB + Math.random() * var - var / 2)); double power = Math.random() * 1 + 2; e.vX = this.vX; e.vY = this.vY; @@ -116,9 +123,9 @@ public void drawUpdate(Graphics g) } else if (type == FireworkType.trail) { - g.setColor(new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), Math.max(0, Math.min(255, 255 - (int) (this.age * 255.0 / this.maxAge))))); + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, Math.max(0, Math.min(255, 255 - (int) (this.age * 255.0 / this.maxAge)))); double s = this.size - (int) (this.age * this.size / this.maxAge); - Drawing.window.fillOval(g, posX, posY, s, s); + Drawing.drawing.fillOval(posX, posY, s, s); if (this.age >= this.maxAge) { @@ -130,13 +137,15 @@ else if (type == FireworkType.particle) this.vY += 0.0625 * Panel.frameFrequency; int opacity = Math.min(255, Math.max(0, (int) (255 - this.age * 255.0 / this.maxAge))); - g.setColor(new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), opacity)); + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, opacity); double s = this.size - (int) (this.age * this.size / this.maxAge); - Drawing.window.fillOval(g, posX, posY, s, s); + Drawing.drawing.fillOval(posX, posY, s, s); /*Firework f = new Firework(FireworkType.trail, this.posX, this.posY, this.list, this.removeList); f.maxAge = opacity / 50; - f.color = this.color; + f.colorR = this.colorR; + f.colorG = this.colorG; + f.colorB = this.colorB; f.size = this.size; this.list.add(f);*/ @@ -155,5 +164,5 @@ else if (type == FireworkType.particle) public void checkCollision() { } @Override - public void draw(Graphics p) { } + public void draw() { } } diff --git a/src/tanks/Game.java b/src/tanks/Game.java index c9cc1ef5..e0efdf8b 100755 --- a/src/tanks/Game.java +++ b/src/tanks/Game.java @@ -1,7 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Toolkit; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -13,8 +11,7 @@ import java.util.Date; import java.util.Scanner; -import javax.swing.SwingUtilities; - +import lwjglwindow.LWJGLWindow; import tanks.tank.*; public class Game @@ -42,8 +39,10 @@ public class Game public static int currentSizeX = 28; public static int currentSizeY = 18; public static double bgResMultiplier = 1; - public static Color[][] tiles = new Color[28][18]; - + public static double[][] tilesR = new double[28][18]; + public static double[][] tilesG = new double[28][18]; + public static double[][] tilesB = new double[28][18]; + public static double levelSize = 1; public static TankPlayer player; @@ -52,7 +51,7 @@ public class Game public static String crashMessage = "Yay! The game hasn't crashed yet!"; - public static Screen screen = new ScreenTitle(); + public static Screen screen; public static boolean fancyGraphics = true; @@ -67,7 +66,7 @@ public class Game public static RegistryTank registryTank = new RegistryTank(); public static RegistryObstacle registryObstacle = new RegistryObstacle(); - public static Drawing window; + public LWJGLWindow window; public static String currentLevel = ""; @@ -90,10 +89,16 @@ private Game() {} public static void initScript() { + Drawing.initialize(); + Panel.initialize(); + Game.exitToTitle(); + defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(Obstacle.class, "normal")); defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleIndestructible.class, "hard")); defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleHole.class, "hole")); + defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleBouncy.class, "bouncy")); defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleShrubbery.class, "shrub")); + defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleTeleporter.class, "teleporter")); defaultTanks.add(new RegistryTank.DefaultTankEntry(TankBrown.class, "brown", 1)); defaultTanks.add(new RegistryTank.DefaultTankEntry(TankGray.class, "gray", 1)); @@ -108,9 +113,13 @@ public static void initScript() defaultTanks.add(new RegistryTank.DefaultTankEntry(TankCyan.class, "cyan", 1.0 / 5)); defaultTanks.add(new RegistryTank.DefaultTankEntry(TankOrange.class, "orange", 1.0 / 6)); defaultTanks.add(new RegistryTank.DefaultTankEntry(TankMaroon.class, "maroon", 1.0 / 7)); + defaultTanks.add(new RegistryTank.DefaultTankEntry(TankMedic.class, "medic", 1.0 / 8)); defaultTanks.add(new RegistryTank.DefaultTankEntry(TankDarkGreen.class, "darkgreen", 1.0 / 9)); defaultTanks.add(new RegistryTank.DefaultTankEntry(TankBlack.class, "black", 1.0 / 10)); defaultTanks.add(new RegistryTank.DefaultTankEntry(TankPink.class, "pink", 1.0 / 15)); + defaultTanks.add(new RegistryTank.DefaultTankEntry(TankBoss.class, "boss", 1.0 / 25)); + + //defaultTanks.add(new RegistryTank.DefaultTankEntry(TankCustom.class, "custom", 1)); homedir = System.getProperty("user.home"); @@ -177,40 +186,9 @@ public static void initScript() public static void main(String[] args) { - initScript(); - - SwingUtilities.invokeLater - ( - new Runnable() - { - @Override - public void run() - { - Drawing.window.initializeMouseOffsets(); - - for (int i = 0; i < currentSizeX; i++) - { - for (int j = 0; j < currentSizeY; j++) - { - Game.tiles[i][j] = new Color((int)(255 - Math.random() * 20), (int)(227 - Math.random() * 20), (int)(186 - Math.random() * 20)); - } - } - - window = Drawing.window; - window.setTitle("Tanks"); - window.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("resources/icon64.png"))); - - - //movables.add(new EnemyTankStationary(120, 600, tank_size)); - //movables.add(new EnemyTankStationary(900, 700, tank_size)); - - //add things to movables - Panel screen = Panel.panel; - window.add(screen); - screen.startTimer(); - } - } - ); + Game.initScript(); + Game.game.window = new LWJGLWindow("Tanks", 1400, 940, new GameUpdater(), new GameDrawer()); + Game.game.window.run(); } public static void reset() @@ -276,20 +254,32 @@ public static void exitToCrash(Exception e) System.gc(); } - public static void exitToTitle() + public static void resetTiles() { - Game.tiles = new Color[28][18]; + Game.tilesR = new double[28][18]; + Game.tilesG = new double[28][18]; + Game.tilesB = new double[28][18]; + for (int i = 0; i < 28; i++) { for (int j = 0; j < 18; j++) { - Game.tiles[i][j] = new Color((int)(255 - Math.random() * 20), (int)(227 - Math.random() * 20), (int)(186 - Math.random() * 20)); + Game.tilesR[i][j] = (255 - Math.random() * 20); + Game.tilesG[i][j] = (227 - Math.random() * 20); + Game.tilesB[i][j] = (186 - Math.random() * 20); } } - Level.currentColor = new Color(235, 207, 166); + Level.currentColorR = 235; + Level.currentColorG = 207; + Level.currentColorB = 166; + } + + public static void exitToTitle() + { + resetTiles(); - Game.window.setScreenBounds(Game.tank_size * 28, Game.tank_size * 18); + Drawing.drawing.setScreenBounds(Game.tank_size * 28, Game.tank_size * 18); obstacles.clear(); belowEffects.clear(); movables.clear(); diff --git a/src/tanks/GameDrawer.java b/src/tanks/GameDrawer.java new file mode 100644 index 00000000..e41f5c8d --- /dev/null +++ b/src/tanks/GameDrawer.java @@ -0,0 +1,19 @@ +package tanks; + +import lwjglwindow.Drawer; + +public class GameDrawer extends Drawer +{ + @Override + public void draw() + { + try + { + Panel.panel.draw(); + } + catch(Exception e) + { + Game.exitToCrash(e); + } + } +} diff --git a/src/tanks/GameUpdater.java b/src/tanks/GameUpdater.java new file mode 100644 index 00000000..a4c49dc6 --- /dev/null +++ b/src/tanks/GameUpdater.java @@ -0,0 +1,19 @@ +package tanks; + +import lwjglwindow.Updater; + +public class GameUpdater extends Updater +{ + @Override + public void update() + { + try + { + Panel.panel.update(); + } + catch(Exception e) + { + Game.exitToCrash(e); + } + } +} diff --git a/src/tanks/Hotbar.java b/src/tanks/Hotbar.java index 035f1333..870b9c1f 100755 --- a/src/tanks/Hotbar.java +++ b/src/tanks/Hotbar.java @@ -1,8 +1,6 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.event.KeyEvent; +import org.lwjgl.glfw.GLFW; public class Hotbar { @@ -38,9 +36,10 @@ public void update() else this.bottomOffset = Math.max(0, this.bottomOffset - 4 * Panel.frameFrequency); - if (InputKeyboard.validKeys.contains(KeyEvent.VK_SHIFT)) + if (Game.game.window.validPressedKeys.contains(GLFW.GLFW_KEY_RIGHT_SHIFT) || Game.game.window.validPressedKeys.contains(GLFW.GLFW_KEY_LEFT_SHIFT)) { - InputKeyboard.validKeys.remove((Integer)KeyEvent.VK_SHIFT); + Game.game.window.validPressedKeys.remove((Integer)GLFW.GLFW_KEY_RIGHT_SHIFT); + Game.game.window.validPressedKeys.remove((Integer)GLFW.GLFW_KEY_LEFT_SHIFT); this.persistent = !this.persistent; } @@ -48,18 +47,18 @@ public void update() this.currentItemBar.update(); } - public void draw(Graphics g) + public void draw() { if (this.enabledItemBar) - this.currentItemBar.draw(g); + this.currentItemBar.draw(); if (this.enabledHealthBar) { - int x = (int) ((Drawing.interfaceSizeX / 2)); - int y = (int) (Drawing.interfaceSizeY - 15 + bottomOffset); - g.setColor(new Color(0, 0, 0, 128)); - Drawing.window.fillInterfaceRect(g, x, y, 350, 5); - g.setColor(new Color(255, 128, 0)); + int x = (int) ((Drawing.drawing.interfaceSizeX / 2)); + int y = (int) (Drawing.drawing.interfaceSizeY - 15 + bottomOffset); + Drawing.drawing.setColor(0, 0, 0, 128); + Drawing.drawing.fillInterfaceRect(x, y, 350, 5); + Drawing.drawing.setColor(255, 128, 0); double lives = Game.player.lives % 1.0; if (lives == 0 && Game.player.lives > 0) @@ -70,23 +69,23 @@ public void draw(Graphics g) int shields = (int) (Game.player.lives - lives); - Drawing.window.fillInterfaceProgressRect(g, x, y, 350, 5, lives); + Drawing.drawing.fillInterfaceProgressRect(x, y, 350, 5, lives); if (shields > 0) { - g.setColor(new Color(255, 0 , 0)); - Drawing.window.fillInterfaceOval(g, x - 175, y, 18, 18); - Drawing.setFontSize(g, 15); - g.setColor(Color.white); - Drawing.window.drawInterfaceText(g, x - 174, y + 3, shields + ""); + Drawing.drawing.setColor(255, 0 , 0); + Drawing.drawing.fillInterfaceOval(x - 175, y, 18, 18); + Drawing.drawing.setFontSize(15); + Drawing.drawing.setColor(255, 255, 255); + Drawing.drawing.drawInterfaceText(x - 174, y + 3, shields + ""); } } if (this.enabledCoins) { - Drawing.setFontSize(g, 18); - g.setColor(Color.black); - Drawing.window.drawInterfaceText(g, Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY - 85 + bottomOffset, "Coins: " + currentCoins.coins); + Drawing.drawing.setFontSize(18); + Drawing.drawing.setColor(0, 0, 0); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY - 85 + bottomOffset, "Coins: " + currentCoins.coins); } } } diff --git a/src/tanks/IDrawable.java b/src/tanks/IDrawable.java new file mode 100644 index 00000000..129b1caa --- /dev/null +++ b/src/tanks/IDrawable.java @@ -0,0 +1,11 @@ +package tanks; + +public interface IDrawable +{ + public void draw(); + + public void drawAt(double x, double y); + + public void drawForInterface(double x, double y); + +} diff --git a/src/tanks/InputKeyboard.java b/src/tanks/InputKeyboard.java deleted file mode 100755 index 8fb2e421..00000000 --- a/src/tanks/InputKeyboard.java +++ /dev/null @@ -1,39 +0,0 @@ -package tanks; - -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.util.ArrayList; - -public class InputKeyboard implements KeyListener -{ - public static ArrayList keys = new ArrayList(); - public static ArrayList validKeys = new ArrayList(); - //public static ArrayList validChars = new ArrayList(); - - @Override - public void keyTyped(KeyEvent e) - { - - } - - @Override - public void keyPressed(KeyEvent e) - { - if (!keys.contains(e.getKeyCode())) - { - keys.add(e.getKeyCode()); - validKeys.add(e.getKeyCode()); - } - } - - @Override - public void keyReleased(KeyEvent e) - { - if (keys.contains(e.getKeyCode())) - { - keys.remove((Integer)e.getKeyCode()); - validKeys.remove((Integer)e.getKeyCode()); - } - } - -} diff --git a/src/tanks/InputMouse.java b/src/tanks/InputMouse.java deleted file mode 100755 index 7f4f3db8..00000000 --- a/src/tanks/InputMouse.java +++ /dev/null @@ -1,120 +0,0 @@ -package tanks; - -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; - -public class InputMouse implements MouseListener, MouseMotionListener -{ - public static boolean lClick = false; - public static boolean rClick = false; - public static boolean mClick = false; - public static boolean b4Click = false; - public static boolean b5Click = false; - - public static boolean lClickValid = false; - public static boolean rClickValid = false; - public static boolean mClickValid = false; - public static boolean b4ClickValid = false; - public static boolean b5ClickValid = false; - - public static long clickTime = 0; - - @Override - public void mouseClicked(MouseEvent e) - { - - } - - @Override - public void mousePressed(MouseEvent e) - { - if (e.getButton() == 1) - { - clickTime = System.currentTimeMillis(); - - lClick = true; - lClickValid = true; - } - else if (e.getButton() == 3) - { - rClick = true; - rClickValid = true; - } - else if (e.getButton() == 2) - { - mClick = true; - mClickValid = true; - } - else if (e.getButton() == 4) - { - b4Click = true; - b4ClickValid = true; - } - else if (e.getButton() == 5) - { - b5Click = true; - b5ClickValid = true; - } - } - - @Override - public void mouseReleased(MouseEvent e) - { - if (e.getButton() == 1) - { - lClick = false; - lClickValid = false; - } - else if (e.getButton() == 3) - { - rClick = false; - rClickValid = false; - } - else if (e.getButton() == 2) - { - mClick = false; - mClickValid = false; - } - else if (e.getButton() == 4) - { - b4Click = false; - b4ClickValid = false; - } - else if (e.getButton() == 5) - { - b5Click = false; - b5ClickValid = false; - } - } - - @Override - public void mouseEntered(MouseEvent e) - { - - } - - @Override - public void mouseExited(MouseEvent e) - { - - } - - @Override - public void mouseDragged(MouseEvent e) - { - if (System.currentTimeMillis() - clickTime > 100) - { - lClickValid = false; - } - } - - @Override - public void mouseMoved(MouseEvent e) - { - if (System.currentTimeMillis() - clickTime > 100) - { - lClickValid = false; - } - } -} diff --git a/src/tanks/InputScroll.java b/src/tanks/InputScroll.java deleted file mode 100755 index 78cc1c30..00000000 --- a/src/tanks/InputScroll.java +++ /dev/null @@ -1,20 +0,0 @@ -package tanks; - -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; - -public class InputScroll implements MouseWheelListener -{ - static boolean validScrollUp = false; - static boolean validScrollDown = false; - - @Override - public void mouseWheelMoved(MouseWheelEvent e) - { - if (e.getPreciseWheelRotation() > 0) - validScrollDown = true; - else if (e.getPreciseWheelRotation() < 0) - validScrollUp = true; - } - -} diff --git a/src/tanks/ItemBar.java b/src/tanks/ItemBar.java index 03143684..445eecbc 100755 --- a/src/tanks/ItemBar.java +++ b/src/tanks/ItemBar.java @@ -1,22 +1,28 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Toolkit; -import java.awt.event.KeyEvent; +import org.lwjgl.glfw.GLFW; public final class ItemBar { - public static final int size = 50; // The slot size. - public static final int count_margin_right = 27; // Item number's distance from right. - public static final int count_margin_bottom = 30; // Item number's distance from bottom. - public static final int gap = 75; // Gap between slots. - public static final int bar_margin = 50; // Bar's distance from bottom. + public static int size = 50; // The slot size. + public static int count_margin_right = 27; // Item number's distance from right. + public static int count_margin_bottom = 40; // Item number's distance from bottom. + public static int gap = 75; // Gap between slots. + public static int bar_margin = 50; // Bar's distance from bottom. - public static final Color slot_bg = new Color(0, 0, 0, 128); // BG color of slots. - public static final Color slot_selected = new Color(255, 128, 0); // Border color of selected slot. - public static final Color item_count = new Color(255, 255, 255); // Text color of item count. + public static double slotBgR = 0; + public static double slotBgG = 0; + public static double slotBgB = 0; + public static double slotBgA = 127; + public static double slotSelectedR = 255; + public static double slotSelectedG = 128; + public static double slotSelectedB = 0; + + public static double itemCountR = 255; + public static double itemCountG = 255; + public static double itemCountB = 255; + public Item[] slots = new Item[5]; public int selected = -1; @@ -109,40 +115,58 @@ public boolean useItem(boolean rightClick) public void update() { - checkKey(KeyEvent.VK_1, 0); - checkKey(KeyEvent.VK_2, 1); - checkKey(KeyEvent.VK_3, 2); - checkKey(KeyEvent.VK_4, 3); - checkKey(KeyEvent.VK_5, 4); + checkKey(GLFW.GLFW_KEY_1, 0); + checkKey(GLFW.GLFW_KEY_2, 1); + checkKey(GLFW.GLFW_KEY_3, 2); + checkKey(GLFW.GLFW_KEY_4, 3); + checkKey(GLFW.GLFW_KEY_5, 4); + + if (Game.game.window.validScrollUp) + { + this.setItem(((this.selected - 1) + this.slots.length) % this.slots.length); + Game.game.window.validScrollUp = false; + } + + if (Game.game.window.validScrollDown) + { + this.setItem(((this.selected + 1) + this.slots.length) % this.slots.length); + Game.game.window.validScrollDown = false; + } } public void checkKey(int key, int index) { - if (InputKeyboard.validKeys.contains(key)) + if (Game.game.window.validPressedKeys.contains(key)) { - this.hotbar.hidden = false; - this.hotbar.hideTimer = 500; - selected = (selected == index ? -1 : index); - InputKeyboard.validKeys.remove((Object) key); + this.setItem(index); + Game.game.window.validPressedKeys.remove((Integer) key); + } } - - public void draw(Graphics g) + + public void setItem(int index) { - g.setColor(slot_bg); + this.hotbar.hidden = false; + this.hotbar.hideTimer = 500; + selected = (selected == index ? -1 : index); + } + public void draw() + { for (int i = -2; i <= 2; i++) { - int x = (int) ((i * gap) + (Drawing.interfaceSizeX / 2)); - int y = (int) (Drawing.interfaceSizeY - bar_margin + this.hotbar.bottomOffset); + Drawing.drawing.setColor(slotBgR, slotBgG, slotBgB, slotBgA); + + int x = (int) ((i * gap) + (Drawing.drawing.interfaceSizeX / 2)); + int y = (int) (Drawing.drawing.interfaceSizeY - bar_margin + this.hotbar.bottomOffset); - Drawing.window.fillInterfaceRect(g, x, y, size, size); + Drawing.drawing.fillInterfaceRect(x, y, size, size); if (i + 2 == selected) { - g.setColor(slot_selected); - Drawing.window.fillInterfaceRect(g, x, y, size, size); - g.setColor(slot_bg); // Unless you want the rest of the slots to be orange... + Drawing.drawing.setColor(slotSelectedR, slotSelectedG, slotSelectedB); + Drawing.drawing.fillInterfaceRect(x, y, size, size); + Drawing.drawing.setColor(slotBgR, slotBgG, slotBgB, slotBgA); } if (slots[i + 2] != null) @@ -150,15 +174,16 @@ public void draw(Graphics g) Item item = slots[i + 2]; if (item.stackSize > 1) { - g.setColor(item_count); - Drawing.setFontSize(g, 12); - Drawing.window.drawInterfaceText(g, x + size - count_margin_right, y + size - count_margin_bottom, Integer.toString(item.stackSize), true); - g.setColor(slot_bg); // You saw nothing... + Drawing.drawing.setColor(itemCountR, itemCountG, itemCountB); + Drawing.drawing.setFontSize(12); + Drawing.drawing.drawInterfaceText(x + size - count_margin_right, y + size - count_margin_bottom, Integer.toString(item.stackSize), true); + Drawing.drawing.setColor(slotBgR, slotBgG, slotBgB, slotBgA); } } + Drawing.drawing.setColor(255, 255, 255); if (slots[i + 2].icon != null) - Drawing.window.drawInterfaceImage(g, Toolkit.getDefaultToolkit().getImage(getClass().getResource("resources/" + slots[i + 2].icon)), x, y, size, size); + Drawing.drawing.drawInterfaceImage("/tanks/resources/" + slots[i + 2].icon, x, y, size, size); } } } diff --git a/src/tanks/Level.java b/src/tanks/Level.java index 1342210c..9e46ab91 100755 --- a/src/tanks/Level.java +++ b/src/tanks/Level.java @@ -1,6 +1,5 @@ package tanks; -import java.awt.Color; import java.util.ArrayList; import java.util.HashMap; @@ -20,7 +19,10 @@ public class Level Team[] tankTeams; boolean enableTeams = false; - public static Color currentColor = new Color(235, 207, 166); + public static double currentColorR = 235; + public static double currentColorG = 207; + public static double currentColorB = 166; + public boolean editable = true; public HashMap teamsMap = new HashMap(); @@ -32,7 +34,6 @@ public class Level * Asterisks indicate that the parameter can be repeated, separated by commas * Do not include these in the level string.) * {(SizeX),(SizeY),[(Red),(Green),(Blue)],[(RedNoise),(GreenNoise),(BlueNoise)]|[(ObstacleX)-(ObstacleY)]*|[(TankX)-(TankY)-(TankType)-[TankAngle]-[TeamName]]*|[(TeamName)-[FriendlyFire]-[(Red)-(Green)-(Blue)]]*} - * */ public Level(String level) { @@ -94,7 +95,7 @@ public void loadLevel(ScreenLevelBuilder s) String[] t = teams[i].split("-"); if (t.length >= 5) - tankTeams[i] = new Team(t[0], Boolean.parseBoolean(t[1]), new Color(Integer.parseInt(t[2]), Integer.parseInt(t[3]), Integer.parseInt(t[4]))); + tankTeams[i] = new Team(t[0], Boolean.parseBoolean(t[1]), Double.parseDouble(t[2]), Double.parseDouble(t[3]), Double.parseDouble(t[4])); else if (t.length >= 2) tankTeams[i] = new Team(t[0], Boolean.parseBoolean(t[1])); else @@ -180,7 +181,20 @@ public void run() } } ); - s.teamButtons.add(buttonToAdd); + s.teamEditButtons.add(buttonToAdd); + + Button buttonToAdd2 = new Button(0, 0, 350, 40, t.name, new Runnable() + { + @Override + public void run() + { + s.setEditorTeam(j); + } + } + ); + + s.teamSelectButtons.add(buttonToAdd2); + } @@ -192,18 +206,25 @@ public void run() Game.currentSizeX = (int) (sX * Game.bgResMultiplier); Game.currentSizeY = (int) (sY * Game.bgResMultiplier); - currentColor = new Color(r, g, b); + currentColorR = r; + currentColorG = g; + currentColorB = b; + + Game.tilesR = new double[Game.currentSizeX][Game.currentSizeY]; + Game.tilesG = new double[Game.currentSizeX][Game.currentSizeY]; + Game.tilesB = new double[Game.currentSizeX][Game.currentSizeY]; - Game.tiles = new Color[Game.currentSizeX][Game.currentSizeY]; for (int i = 0; i < Game.currentSizeX; i++) { for (int j = 0; j < Game.currentSizeY; j++) { - Game.tiles[i][j] = new Color((int)(r + Math.random() * dr), (int)(g + Math.random() * dg), (int)(b + Math.random() * db)); + Game.tilesR[i][j] = (r + Math.random() * dr); + Game.tilesG[i][j] = (g + Math.random() * dg); + Game.tilesB[i][j] = (b + Math.random() * db); } } - Game.window.setScreenBounds(Game.tank_size * sX, Game.tank_size * sY); + Drawing.drawing.setScreenBounds(Game.tank_size * sX, Game.tank_size * sY); if (!((obstaclesPos.length == 1 && obstaclesPos[0].equals("")) || obstaclesPos.length == 0)) { diff --git a/src/tanks/LevelGenerator.java b/src/tanks/LevelGenerator.java index 139262c3..87bc793b 100755 --- a/src/tanks/LevelGenerator.java +++ b/src/tanks/LevelGenerator.java @@ -7,6 +7,7 @@ public static String generateLevelString() { //int type = (int) (Math.random() * 13); //test ^ + //String name = Game.registryTank.getRandomTank().name; double size = Game.levelSize; int height = (int)(18 * size); diff --git a/src/tanks/Mine.java b/src/tanks/Mine.java index 7b36f272..288c97cd 100755 --- a/src/tanks/Mine.java +++ b/src/tanks/Mine.java @@ -1,8 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - import tanks.tank.Tank; public class Mine extends Movable @@ -10,8 +7,10 @@ public class Mine extends Movable public static int mine_size = 30; public double timer = 1000; public int size = mine_size; - public Color outlineColor; - + public double outlineColorR; + public double outlineColorG; + public double outlineColorB; + public double radius = Game.tank_size * 2.5; public Tank tank; @@ -24,24 +23,28 @@ public Mine(double x, double y, Tank t) tank = t; t.liveMines++; this.team = t.team; - this.outlineColor = Team.getObjectColor(t.color, t); + double[] outlineCol = Team.getObjectColor(t.colorR, t.colorG, t.colorB, t); + this.outlineColorR = outlineCol[0]; + this.outlineColorG = outlineCol[1]; + this.outlineColorB = outlineCol[2]; + } @Override public void checkCollision() { } @Override - public void draw(Graphics p) + public void draw() { - p.setColor(this.outlineColor); - Drawing.window.fillOval(p, this.posX, this.posY, this.size, this.size); + Drawing.drawing.setColor(this.outlineColorR, this.outlineColorG, this.outlineColorB); + Drawing.drawing.fillOval(this.posX, this.posY, this.size, this.size); - p.setColor(new Color(255, (int) ((this.timer) / 1000.0 * 255), 0)); + Drawing.drawing.setColor(255, (this.timer) / 1000.0 * 255, 0); if (timer < 150 && ((int) timer % 16) / 8 == 1) - p.setColor(Color.yellow); + Drawing.drawing.setColor(255, 255, 0); - Drawing.window.fillOval(p, this.posX, this.posY, this.size * 0.8, this.size * 0.8); + Drawing.drawing.fillOval(this.posX, this.posY, this.size * 0.8, this.size * 0.8); } @Override @@ -71,7 +74,7 @@ public void update() public void explode() { - Drawing.playSound("resources/explosion.wav"); + Drawing.drawing.playSound("resources/explosion.wav"); if (Game.fancyGraphics) { @@ -80,21 +83,23 @@ public void explode() double random = Math.random(); Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); e.maxAge /= 2; - e.col = new Color(255, (int) ((1 - random) * 155 + Math.random() * 100), 0); + e.colR = 255; + e.colG = (1 - random) * 155 + Math.random() * 100; + e.colB = 0; e.setPolarMotion(Math.random() * 2 * Math.PI, random * (this.radius - Game.tank_size / 2) / Game.tank_size * 2); Game.effects.add(e); } } + this.destroy = true; + for (int i = 0; i < Game.movables.size(); i++) { Movable o = Game.movables.get(i); if (Math.pow(Math.abs(o.posX - this.posX), 2) + Math.pow(Math.abs(o.posY - this.posY), 2) < Math.pow(radius, 2)) { - if (o instanceof Tank && !o.destroy) + if (o instanceof Tank && !o.destroy && !((Tank) o).invulnerable) { - this.destroy = true; - if (!(Team.isAllied(this, o) && !this.team.friendlyFire)) { ((Tank) o).lives -= 2; @@ -134,7 +139,9 @@ else if (o instanceof Mine && !o.destroy) int oY = 0; Effect e = Effect.createNewEffect(o.posX + j + oX + 2 - Obstacle.obstacle_size / 2, o.posY + k + oY + 2 - Obstacle.obstacle_size / 2, Effect.EffectType.obstaclePiece); - e.col = o.color; + e.colR = o.colorR; + e.colG = o.colorG; + e.colB = o.colorB; double dist = Movable.distanceBetween(this, e); double angle = this.getAngleInDirection(e.posX, e.posY); diff --git a/src/tanks/Movable.java b/src/tanks/Movable.java index 0f0cec7d..75dc04f2 100755 --- a/src/tanks/Movable.java +++ b/src/tanks/Movable.java @@ -1,9 +1,8 @@ package tanks; -import java.awt.Graphics; import java.util.ArrayList; -public abstract class Movable +public abstract class Movable implements IDrawable { public double posX; public double posY; @@ -200,11 +199,25 @@ public void moveInDirection(double x, double y, double amount) this.posY += amount * y; } - public void drawTeam(Graphics g) + public void drawTeam() { - Drawing.setFontSize(g, 20); + Drawing.drawing.setFontSize(20); if (this.team != null) - Drawing.window.drawText(g, this.posX, this.posY + 40, this.team.name); + Drawing.drawing.drawText(this.posX, this.posY + 25, this.team.name); + } + + public void addUnduplicateAttribute(AttributeModifier m) + { + for (int i = 0; i < this.attributes.size(); i++) + { + if (this.attributes.get(i).name.equals(m.name)) + { + this.attributes.remove(i); + i--; + } + } + + this.attributes.add(m); } public static double[] getLocationInDirection(double angle, double distance) @@ -214,12 +227,33 @@ public static double[] getLocationInDirection(double angle, double distance) public abstract void checkCollision(); - public abstract void draw(Graphics p); + public abstract void draw(); + + public void drawAt(double x, double y) + { + double x1 = this.posX; + double y1 = this.posY; + this.posX = x; + this.posY = y; + this.draw(); + this.posX = x1; + this.posY = y1; + } + + public void drawForInterface(double x, double y) + { + this.drawAt(x, y); + } public static double distanceBetween(final Movable a, final Movable b) { return Math.sqrt((a.posX-b.posX)*(a.posX-b.posX) + (a.posY-b.posY)*(a.posY-b.posY)); } + + public static double distanceBetween(final Obstacle a, final Movable b) + { + return Math.sqrt((a.posX-b.posX)*(a.posX-b.posX) + (a.posY-b.posY)*(a.posY-b.posY)); + } public static double angleBetween(double a, double b) { diff --git a/src/tanks/Obstacle.java b/src/tanks/Obstacle.java index 8eee92f2..f7a227f5 100755 --- a/src/tanks/Obstacle.java +++ b/src/tanks/Obstacle.java @@ -1,19 +1,22 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - -public class Obstacle +public class Obstacle implements IDrawable { public boolean destructible = true; public boolean tankCollision = true; public boolean bulletCollision = true; - public boolean drawBelow = false; + public boolean drawBelow = true; public boolean checkForObjects = false; + public boolean update = false; + public boolean draggable = true; + public boolean bouncy = false; public double posX; public double posY; - public Color color; + public double colorR; + public double colorG; + public double colorB; + public double colorA = 255; public static double draw_size = 0; public static int obstacle_size = Game.tank_size; @@ -24,56 +27,128 @@ public Obstacle(String name, double posX, double posY) this.name = name; this.posX = (int) ((posX + 0.5) * obstacle_size); this.posY = (int) ((posY + 0.5) * obstacle_size); - this.color = Obstacle.getRandomColor(); + double[] col = Obstacle.getRandomColor(); + this.colorR = col[0]; + this.colorG = col[1]; + this.colorB = col[2]; } - public void draw(Graphics g) + @Override + public void draw() { - Drawing drawing = Drawing.window; + Drawing drawing = Drawing.drawing; - g.setColor(this.color); - drawing.fillRect(g, this.posX, this.posY, draw_size, draw_size); + drawing.setColor(this.colorR, this.colorG, this.colorB, this.colorA); + drawing.fillRect(this.posX, this.posY, draw_size, draw_size); + } + + @Override + public void drawAt(double x, double y) + { + double x1 = this.posX; + double y1 = this.posY; + this.posX = x; + this.posY = y; + this.draw(); + this.posX = x1; + this.posY = y1; + } + + @Override + public void drawForInterface(double x, double y) + { + Drawing drawing = Drawing.drawing; + + drawing.setColor(this.colorR, this.colorG, this.colorB, this.colorA); + drawing.fillInterfaceRect(x, y, draw_size, draw_size); + } + + public void drawOutline() + { + Drawing drawing = Drawing.drawing; + drawing.setColor(this.colorR, this.colorG, this.colorB, this.colorA); + drawing.fillRect(this.posX - Obstacle.obstacle_size * 0.4, this.posY, Obstacle.obstacle_size * 0.2, Obstacle.obstacle_size); + drawing.fillRect(this.posX + Obstacle.obstacle_size * 0.4, this.posY, Obstacle.obstacle_size * 0.2, Obstacle.obstacle_size); + drawing.fillRect(this.posX, this.posY - Obstacle.obstacle_size * 0.4, Obstacle.obstacle_size, Obstacle.obstacle_size * 0.2); + drawing.fillRect(this.posX, this.posY + Obstacle.obstacle_size * 0.4, Obstacle.obstacle_size, Obstacle.obstacle_size * 0.2); + } + + public void onObjectEntry(Movable m) + { + + } + + public void update() + { - /*for (int i = 0; i < 10; i++) + } + + public boolean hasLeftNeighbor() + { + for (int i = 0; i < Game.obstacles.size(); i++) { - int col = i * 25; - g.setColor(new Color(col, col, col)); - drawing.fillRect(g, this.posX, this.posY, draw_size - i * 5, draw_size - i * 5); - }*/ + Obstacle o = Game.obstacles.get(i); + + if (o.bulletCollision && o.posY == this.posY && this.posX - o.posX <= obstacle_size && this.posX - o.posX > 0) + return true; + } - /*for (int i = 0; i < Math.max(1, draw_size * 2 - obstacle_size); i++) + return false; + } + + public boolean hasRightNeighbor() + { + for (int i = 0; i < Game.obstacles.size(); i++) { - g.setColor(new Color((int) (color.getRed() - 0.5 * color.getRed() * (obstacle_size - i) / obstacle_size), - (int) (color.getGreen() - 0.5 * color.getGreen() * (obstacle_size - i) / obstacle_size), - (int) (color.getBlue() - 0.5 * color.getBlue() * (obstacle_size - i) / obstacle_size))); - drawing.fillRect(g, this.posX - 0.5 * i, this.posY - 0.5 * i, Math.min(draw_size * 2, obstacle_size), Math.min(draw_size * 2, obstacle_size)); - }*/ + Obstacle o = Game.obstacles.get(i); + + if (o.bulletCollision && o.posY == this.posY && o.posX - this.posX <= obstacle_size && o.posX - this.posX > 0) + return true; + } + + return false; } - - public void drawOutline(Graphics g) + + public boolean hasUpperNeighbor() { - g.setColor(this.color); - Drawing drawing = Drawing.window; - drawing.fillRect(g, this.posX - Obstacle.obstacle_size * 0.4, this.posY, Obstacle.obstacle_size * 0.2, Obstacle.obstacle_size); - drawing.fillRect(g, this.posX + Obstacle.obstacle_size * 0.4, this.posY, Obstacle.obstacle_size * 0.2, Obstacle.obstacle_size); - drawing.fillRect(g, this.posX, this.posY - Obstacle.obstacle_size * 0.4, Obstacle.obstacle_size, Obstacle.obstacle_size * 0.2); - drawing.fillRect(g, this.posX, this.posY + Obstacle.obstacle_size * 0.4, Obstacle.obstacle_size, Obstacle.obstacle_size * 0.2); + for (int i = 0; i < Game.obstacles.size(); i++) + { + Obstacle o = Game.obstacles.get(i); + + if (o.bulletCollision && o.posX == this.posX && this.posY - o.posY <= obstacle_size && this.posY - o.posY > 0) + return true; + } + + return false; } - public void onObjectEntry(Movable m) + public boolean hasLowerNeighbor() { + for (int i = 0; i < Game.obstacles.size(); i++) + { + Obstacle o = Game.obstacles.get(i); + + if (o.bulletCollision && o.posX == this.posX && o.posY - this.posY <= obstacle_size && o.posY - this.posY > 0) + return true; + } + return false; } - public static Color getRandomColor() + public static double[] getRandomColor() { double colorMul = Math.random() * 0.5 + 0.5; - Color col; + double[] col = new double[3]; if (Game.fancyGraphics) - col = new Color((int) (colorMul * (176 - Math.random() * 70)), (int) (colorMul * (111 - Math.random() * 34)), (int) (colorMul * 14)); + { + col[0] = (colorMul * (176 - Math.random() * 70)); + col[1] = (colorMul * (111 - Math.random() * 34)); + col[2] = (colorMul * 14); + + } else - col = new Color(87, 46, 8); + col = new double[]{87, 46, 8}; return col; } diff --git a/src/tanks/ObstacleBouncy.java b/src/tanks/ObstacleBouncy.java new file mode 100644 index 00000000..aaaa05eb --- /dev/null +++ b/src/tanks/ObstacleBouncy.java @@ -0,0 +1,14 @@ +package tanks; + +public class ObstacleBouncy extends Obstacle +{ + public ObstacleBouncy(String name, double posX, double posY) + { + super(name, posX, posY); + + this.bouncy = true; + this.colorR = Math.random() * 127 + 128; + this.colorG = 0; + this.colorB = 255; + } +} diff --git a/src/tanks/ObstacleHole.java b/src/tanks/ObstacleHole.java index 8a75d503..d5aed089 100755 --- a/src/tanks/ObstacleHole.java +++ b/src/tanks/ObstacleHole.java @@ -1,11 +1,7 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - public class ObstacleHole extends Obstacle { - public ObstacleHole(String name, double posX, double posY) { super(name, posX, posY); @@ -13,13 +9,24 @@ public ObstacleHole(String name, double posX, double posY) this.drawBelow = true; this.destructible = false; this.bulletCollision = false; - this.color = new Color(0, 0, 0, 128); + this.colorR = 0; + this.colorG = 0; + this.colorB = 0; + this.colorA = 128; + } + + @Override + public void draw() + { + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, this.colorA); + Drawing.drawing.fillRect(this.posX, this.posY, draw_size / 2, draw_size / 2); } - public void draw(Graphics g) + @Override + public void drawForInterface(double x, double y) { - g.setColor(this.color); - Drawing.window.fillRect(g, this.posX, this.posY, draw_size / 2, draw_size / 2); + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, this.colorA); + Drawing.drawing.fillInterfaceRect(x, y, draw_size / 2, draw_size / 2); } } diff --git a/src/tanks/ObstacleIndestructible.java b/src/tanks/ObstacleIndestructible.java index dbd11c84..a61d593b 100755 --- a/src/tanks/ObstacleIndestructible.java +++ b/src/tanks/ObstacleIndestructible.java @@ -1,8 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - public class ObstacleIndestructible extends Obstacle { @@ -11,14 +8,17 @@ public ObstacleIndestructible(String name, double posX, double posY) super(name, posX, posY); this.destructible = false; - int col = (this.color.getRed() + this.color.getGreen() + this.color.getBlue()) / 3; - this.color = new Color(col, col, col); + double col = (this.colorR + this.colorG + this.colorB) / 3; + this.colorR = col; + this.colorG = col; + this.colorB = col; } - public void draw(Graphics g) + @Override + public void draw() { - g.setColor(this.color); - Drawing.window.fillRect(g, this.posX, this.posY, draw_size, draw_size); + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, this.colorA); + Drawing.drawing.fillRect(this.posX, this.posY, draw_size, draw_size); } } diff --git a/src/tanks/ObstacleShrubbery.java b/src/tanks/ObstacleShrubbery.java index 40f4006f..17066fa5 100644 --- a/src/tanks/ObstacleShrubbery.java +++ b/src/tanks/ObstacleShrubbery.java @@ -1,29 +1,51 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - public class ObstacleShrubbery extends Obstacle { public double opacity = 255; + public ObstacleShrubbery(String name, double posX, double posY) { super(name, posX, posY); this.destructible = true; + this.drawBelow = false; this.tankCollision = false; this.bulletCollision = false; this.checkForObjects = true; - this.color = new Color((int) (Math.random() * 20), (int) (Math.random() * 50) + 150, (int) (Math.random() * 20)); + this.colorR = (Math.random() * 20); + this.colorG = (Math.random() * 50) + 150; + this.colorB = (Math.random() * 20); + if (!Game.fancyGraphics) + { + this.colorR = 10; + this.colorG = 175; + this.colorB = 10; + } } - public void draw(Graphics g) + @Override + public void draw() { this.opacity = Math.min(this.opacity + Panel.frameFrequency, 255); - this.color = new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), (int) opacity); - g.setColor(this.color); - Drawing.window.fillRect(g, this.posX, this.posY, draw_size, draw_size); + if (Game.screen instanceof ScreenLevelBuilder || Game.screen instanceof ScreenGame && (!((ScreenGame) Game.screen).playing)) + { + this.opacity = 127; + } + + if (Game.player.destroy) + this.opacity = Math.max(127, this.opacity - Panel.frameFrequency * 2); + + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, this.opacity); + Drawing.drawing.fillRect(this.posX, this.posY, draw_size, draw_size); + } + + @Override + public void drawForInterface(double x, double y) + { + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 127); + Drawing.drawing.fillInterfaceRect(x, y, draw_size, draw_size); } @Override @@ -32,6 +54,9 @@ public void onObjectEntry(Movable m) this.opacity = Math.max(this.opacity - Panel.frameFrequency * Math.pow(Math.abs(m.vX) + Math.abs(m.vY), 2), 127); m.hiddenTimer = Math.min(100, m.hiddenTimer + (this.opacity - 127) / 255); m.canHide = true; + + if (m instanceof BulletFlame) + Game.removeObstacles.add(this); } } diff --git a/src/tanks/ObstacleTeleporter.java b/src/tanks/ObstacleTeleporter.java new file mode 100644 index 00000000..5a910691 --- /dev/null +++ b/src/tanks/ObstacleTeleporter.java @@ -0,0 +1,99 @@ +package tanks; + +import java.util.ArrayList; + +import tanks.tank.Tank; + +public class ObstacleTeleporter extends Obstacle +{ + double cooldown; + double green = 255; + + public ObstacleTeleporter(String name, double posX, double posY) + { + super(name, posX, posY); + + this.destructible = false; + this.tankCollision = false; + this.bulletCollision = false; + this.checkForObjects = true; + this.drawBelow = true; + this.update = true; + this.colorR = 0; + this.colorG = 255; + this.colorB = 255; + this.draggable = false; + } + + @Override + public void draw() + { + Drawing.drawing.setColor(127, 127, 127); + Drawing.drawing.fillOval(this.posX, this.posY, draw_size, draw_size); + + if (this.cooldown > 0) + this.green = Math.min(255, this.green - 2.55 * Panel.frameFrequency); + else + this.green = Math.max(0, this.green + 2.55 * Panel.frameFrequency); + + Drawing.drawing.setColor(0, this.green, 255); + + Drawing.drawing.fillOval(this.posX, this.posY, draw_size / 2, draw_size / 2); + } + + @Override + public void drawForInterface(double x, double y) + { + Drawing.drawing.setColor(127, 127, 127); + Drawing.drawing.fillInterfaceOval(x, y, draw_size, draw_size); + + Drawing.drawing.setColor(0, 255, 255); + + Drawing.drawing.fillInterfaceOval(x, y, draw_size / 2, draw_size / 2); + } + + @Override + public void update() + { + ArrayList teleporters = new ArrayList(); + Tank t = null; + + for (int i = 0; i < Game.movables.size(); i++) + { + Movable m = Game.movables.get(i); + + if (m instanceof Tank && !((Tank) m).invulnerable && Movable.distanceBetween(this, m) < ((Tank)m).size) + { + t = (Tank) m; + + if (this.cooldown > 0) + { + this.cooldown = Math.max(100, this.cooldown); + continue; + } + + for (int j = 0; j < Game.obstacles.size(); j++) + { + Obstacle o = Game.obstacles.get(j); + if (o instanceof ObstacleTeleporter && o != this) + { + teleporters.add((ObstacleTeleporter) o); + } + } + + } + } + + this.cooldown = Math.max(0, this.cooldown - Panel.frameFrequency); + + if (t != null && teleporters.size() > 0 && this.cooldown <= 0) + { + int i = (int) (Math.random() * teleporters.size()); + + ObstacleTeleporter o = teleporters.get(i); + o.cooldown = 500; + this.cooldown = 500; + Game.movables.add(new TeleporterOrb(t.posX, t.posY, this.posX, this.posY, o.posX, o.posY, t)); + } + } +} diff --git a/src/tanks/ObstacleUnknown.java b/src/tanks/ObstacleUnknown.java index f7670b42..ac460cc9 100755 --- a/src/tanks/ObstacleUnknown.java +++ b/src/tanks/ObstacleUnknown.java @@ -1,9 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics; - public class ObstacleUnknown extends Obstacle { @@ -11,19 +7,21 @@ public ObstacleUnknown(String name, double posX, double posY) { super(name, posX, posY); - this.color = Color.red; + this.colorR = 255; + this.colorG = 0; + this.colorB = 0; this.destructible = false; this.tankCollision = false; this.bulletCollision = false; } @Override - public void draw(Graphics g) + public void draw() { - g.setFont(g.getFont().deriveFont(Font.BOLD, (float) (12 * Drawing.window.getScale()))); - Drawing.window.drawText(g, this.posX, this.posY + 32, this.name); + Drawing.drawing.setFontSize(12); + Drawing.drawing.drawText(this.posX, this.posY + 32, this.name); - super.draw(g); + super.draw(); } } diff --git a/src/tanks/Panel.java b/src/tanks/Panel.java index d398a0d4..87e74852 100755 --- a/src/tanks/Panel.java +++ b/src/tanks/Panel.java @@ -1,22 +1,16 @@ package tanks; -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Toolkit; -import java.awt.event.*; import java.util.ArrayList; -import javax.swing.JPanel; import javax.swing.Timer; -@SuppressWarnings("serial") -public class Panel extends JPanel +public class Panel { Timer timer; - int height = Drawing.sizeY; - int width = Drawing.sizeX; + int height = Drawing.drawing.sizeY; + int width = Drawing.drawing.sizeX; boolean resize = true; + double zoomTimer = 0; public static double windowWidth = 1400; public static double windowHeight = 900; @@ -29,7 +23,7 @@ public class Panel extends JPanel ArrayList framesList = new ArrayList(); - public static Panel panel = new Panel(); + public static Panel panel; public static String winlose = ""; public static boolean win = false; @@ -38,10 +32,10 @@ public class Panel extends JPanel /** Important value used in calculating game speed. Larger values are set when the frames are lower, and game speed is increased to compensate.*/ public static double frameFrequency = 1; - + public Hotbar hotbar = new Hotbar(); - - ArrayList frameFrequencies = new ArrayList(); + + //ArrayList frameFrequencies = new ArrayList(); int frames = 0; @@ -57,253 +51,187 @@ public class Panel extends JPanel int lastFPS = 0; public static boolean pausePressed = false; - - private Panel() + protected static boolean initialized = false; + + public static void initialize() { - Panel.panel = this; + if (!initialized) + panel = new Panel(); + initialized = true; + } + + private Panel() + { this.hotbar.enabledItemBar = false; this.hotbar.currentCoins = new Coins(); + } - timer = new Timer(0, new ActionListener() - { + public void update() + { + Panel.frameFrequency = Game.game.window.frameFrequency; + + if (Panel.panel.hotbar.currentCoins.coins < 0) + Panel.panel.hotbar.currentCoins.coins = 0; - @Override - public void actionPerformed(ActionEvent e) - { - //long start = System.nanoTime(); - - try - { - long milliTime = System.currentTimeMillis(); - - framesList.add(milliTime); - - ArrayList removeList = new ArrayList(); - - for (int i = 0; i < framesList.size(); i++) - { - if (milliTime - framesList.get(i) > 1000) - removeList.add(framesList.get(i)); - } - - for (int i = 0; i < removeList.size(); i++) - { - framesList.remove(removeList.get(i)); - } - - if (Panel.panel.hotbar.currentCoins.coins < 0) - Panel.panel.hotbar.currentCoins.coins = 0; - - Panel.windowWidth = Panel.panel.getSize().getWidth(); - Panel.windowHeight = Panel.panel.getSize().getHeight(); - - Drawing.window.scale = Math.min(Panel.windowWidth * 1.0 / Game.currentSizeX, (Panel.windowHeight * 1.0 - 40) / Game.currentSizeY) / 50.0; - Drawing.interfaceScale = Math.min(Panel.windowWidth * 1.0 / 28, (Panel.windowHeight * 1.0 - 40) / 18) / 50.0; - - Drawing.unzoomedScale = Drawing.window.scale; - - if (Game.player != null && Game.screen instanceof ScreenGame && !ScreenGame.finished) - { - Drawing.enableMovingCamera = true; - - if (Drawing.movingCamera) - { - Drawing.playerX = Game.player.posX; - Drawing.playerY = Game.player.posY; - - if (Drawing.window.scale < Drawing.interfaceScale) - { - Drawing.enableMovingCamera = true; - Drawing.window.scale = Drawing.interfaceScale; - } - else - { - Drawing.enableMovingCamera = false; - } - } - } - else - { - Drawing.enableMovingCamera = false; - } - - if (Panel.windowWidth > Game.currentSizeX * Game.tank_size * Drawing.window.scale) - Drawing.enableMovingCameraX = false; - else - { - Drawing.enableMovingCameraX = true; - Panel.restrictedWindowMouseOffsetX = 0; - } - - if (Panel.windowHeight - 40 > Game.currentSizeY * Game.tank_size * Drawing.window.scale) - Drawing.enableMovingCameraY = false; - else - { - Drawing.enableMovingCameraY = true; - Panel.restrictedWindowMouseOffsetY = 0; - } - - Game.screen.update(); - - //long end = System.nanoTime(); - //System.out.println("Updating took: " + (end - start)); - //System.out.println(Game.effects.size()); - //System.out.println(Game.recycleEffects.size()); - - repaint(); - - //frameFrequency = 100.0 / lastFPS; - //timer.setDelay((int) (frameFrequency * 10)); - - //long end = System.nanoTime(); - //System.out.println(end - start); - - //int wait = (int) ((end - start)/1000); - //timer.setDelay(wait); - - long time = System.currentTimeMillis(); - long lastFrameTime = lastFrame; - lastFrame = time; - - double freq = (time - lastFrameTime) / 10.0; - frameFrequencies.add(freq); - - if (frameFrequencies.size() > 5) - { - frameFrequencies.remove(0); - } - - double totalFrequency = 0; - for (int i = 0; i < frameFrequencies.size(); i++) - { - totalFrequency += frameFrequencies.get(i); - } - - frameFrequency = totalFrequency / frameFrequencies.size(); - - //System.out.println(frameFrequency); - //frameFrequency = 100.0 / framesList.size(); - } - catch (Exception exception) - { - Game.exitToCrash(exception); - } + Panel.windowWidth = Game.game.window.absoluteWidth; + Panel.windowHeight = Game.game.window.absoluteHeight; - } + Drawing.drawing.scale = Math.min(Panel.windowWidth * 1.0 / Game.currentSizeX, (Panel.windowHeight * 1.0 - 40) / Game.currentSizeY) / 50.0; + Drawing.drawing.interfaceScale = Math.min(Panel.windowWidth * 1.0 / 28, (Panel.windowHeight * 1.0 - 40) / 18) / 50.0; - }); - } + Drawing.drawing.unzoomedScale = Drawing.drawing.scale; - public void startTimer() - { - timer.start(); - new SoundThread().execute(); - } + this.zoomTimer -= 0.02 * Panel.frameFrequency; - @Override - public void paint(Graphics g) - { - //long start = System.nanoTime(); - try + if (Game.player != null && Game.screen instanceof ScreenGame && !ScreenGame.finished) { - if (System.currentTimeMillis() - startTime < 1000) + Drawing.drawing.enableMovingCamera = true; + + if (Drawing.drawing.movingCamera) { - for (int i = 0; i < Game.currentSizeX; i++) + Drawing.drawing.playerX = Game.player.posX; + Drawing.drawing.playerY = Game.player.posY; + this.zoomTimer += 0.04 * Panel.frameFrequency; + + if (Drawing.drawing.scale < Drawing.drawing.interfaceScale) { - g.setColor(Level.currentColor); - Drawing.window.fillInterfaceRect(g, Drawing.sizeX / 2, Drawing.sizeY / 2, Drawing.sizeX * 1.2, Drawing.sizeY * 1.2); - g.drawImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("resources/loading.png")), 0, 0, null); - + Drawing.drawing.enableMovingCamera = true; + //Drawing.drawing.scale = Drawing.drawing.interfaceScale; + } + else + { + Drawing.drawing.enableMovingCamera = false; } - return; } + } + else + { + Drawing.drawing.enableMovingCamera = false; + } + + this.zoomTimer = Math.min(Math.max(this.zoomTimer, 0), 1); + + Drawing.drawing.scale = Drawing.drawing.scale * (1 - zoomTimer) + Drawing.drawing.interfaceScale * zoomTimer; + if (Panel.windowWidth > Game.currentSizeX * Game.tank_size * Drawing.drawing.scale) + Drawing.drawing.enableMovingCameraX = false; + else + { + Drawing.drawing.enableMovingCameraX = true; + Panel.restrictedWindowMouseOffsetX = 0; + } - g.setColor(new Color(174, 92, 16)); - g.fillRect(0, 0, 1 + (int)(Panel.windowWidth), 1+(int)(Panel.windowHeight)); - - long time = (long) (System.currentTimeMillis() * frameSampling / 1000 ); - if (lastFrameSec < time && lastFrameSec != firstFrameSec) - { - lastFPS = (int) (frames * 1.0 * frameSampling); - frames = 0; - } - + if (Panel.windowHeight - 40 > Game.currentSizeY * Game.tank_size * Drawing.drawing.scale) + Drawing.drawing.enableMovingCameraY = false; + else + { + Drawing.drawing.enableMovingCameraY = true; + Panel.restrictedWindowMouseOffsetY = 0; + } - lastFrameSec = time; - frames++; + Game.screen.update(); - //g.setColor(new Color(255, 227, 186)); - //g.fillRect(0, 0, (int) (Screen.sizeX * Screen.scale), (int) (Screen.sizeY * Screen.scale)); + //long end = System.nanoTime(); + //System.out.println("Updating took: " + (end - start)); + //System.out.println(Game.effects.size()); + //System.out.println(Game.recycleEffects.size()); - Game.screen.draw(g); + //repaint(); + } - g.setColor(new Color(87, 46, 8)); - g.fillRect(0, (int) (Panel.windowHeight - 40), (int) (Panel.windowWidth), 40); + public void draw() + { + double introTime = 1000; + double introAnimationTime = 500; + if (System.currentTimeMillis() - startTime < introTime + introAnimationTime) + { + Drawing.drawing.setColor(Level.currentColorR, Level.currentColorG, Level.currentColorB); + Drawing.drawing.fillInterfaceRect(Drawing.drawing.sizeX / 2, Drawing.drawing.sizeY / 2, Drawing.drawing.sizeX * 1.2, Drawing.drawing.sizeY * 1.2); + Drawing.drawing.setColor(255, 255, 255); + Drawing.drawing.drawInterfaceImage("/tanks/resources/loading.png", Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2, Drawing.drawing.interfaceSizeX, Drawing.drawing.interfaceSizeY); + + if (System.currentTimeMillis() - startTime > introTime) + { + Game.screen.drawDefaultBackground((System.currentTimeMillis() - startTime - introTime) / introAnimationTime); + drawBar(120 -((System.currentTimeMillis() - startTime) / introAnimationTime) * 40); + } + + return; + } - g.setColor(new Color(255, 227, 186)); + Drawing.drawing.setColor(174, 92, 16); + Drawing.drawing.fillInterfaceRect(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2, Drawing.drawing.interfaceSizeX * 2, Drawing.drawing.interfaceSizeY * 2); - g.setFont(g.getFont().deriveFont(Font.BOLD, 12)); + long time = (long) (System.currentTimeMillis() * frameSampling / 1000); + if (lastFrameSec < time && lastFrameSec != firstFrameSec) + { + lastFPS = (int) (frames * 1.0 * frameSampling); + frames = 0; + } - g.drawString("Tanks v0.5.1", 2, (int) (Panel.windowHeight - 40 + 12)); - g.drawString("FPS: " + lastFPS, 2, (int) (Panel.windowHeight - 40 + 24)); + + lastFrameSec = time; + frames++; - //g.drawString("Coins: " + Game.coins, 2, (int) (Panel.windowHeight - 40 + 36 - Window.yOffset)); + //g.setColor(new Color(255, 227, 186)); + //g.fillRect(0, 0, (int) (Screen.sizeX * Screen.scale), (int) (Screen.sizeY * Screen.scale)); - /*int obstacles = Game.obstacles.size(); - int movables = Game.movables.size(); - int effects = Game.effects.size(); + Game.screen.draw(); - int drawHeight = 23; - int drawSize = 10;*/ + drawBar(); + + double mx = Drawing.drawing.getInterfaceMouseX(); + double my = Drawing.drawing.getInterfaceMouseY(); - /*g.setColor(Color.red); - g.fillRect(0, drawHeight, obstacles, drawSize); - g.setColor(Color.green); - g.fillRect(obstacles, drawHeight, movables, drawSize); - g.setColor(Color.blue); - g.fillRect(obstacles + movables, drawHeight, effects, drawSize);*/ + //double mx2 = Drawing.drawing.getMouseX(); + //double my2 = Drawing.drawing.getMouseY(); - /*for (int i = 0; i < Game.obstacles.size(); i++) + if (showMouseTarget) { - Game.obstacles.get(i).posX += (Game.obstacles.get(i).posX - Game.player.posX) / 1000; - Game.obstacles.get(i).posY += (Game.obstacles.get(i).posY - Game.player.posY) / 1000; + Drawing.drawing.setColor(0, 0, 0); + Drawing.drawing.drawInterfaceOval(mx, my, 8, 8); + Drawing.drawing.drawInterfaceOval(mx, my, 4, 4); - //Game.obstacles.get(i).posX += Math.random() * 4 - 2; - //Game.obstacles.get(i).posY += Math.random() * 4 - 2; + //Drawing.drawing.setColor(255, 0, 0); + //Drawing.drawing.drawOval(mx2, my2, 8, 8); + //Drawing.drawing.drawOval(mx2, my2, 4, 4); } - for (int i = 0; i < Game.movables.size(); i++) - { - //Game.movables.get(i).posX += Math.random() * 4 - 2; - //Game.movables.get(i).posY += Math.random() * 4 - 2; - } - for (int i = 0; i < Game.effects.size(); i++) - { - //Game.effects.get(i).posX += Math.random() * 4 - 2; - //Game.effects.get(i).posY += Math.random() * 4 - 2; - }*/ + } + + public void drawBar() + { + drawBar(0); + } + + public void drawBar(double offset) + { + Drawing.drawing.setColor(87, 46, 8); + Game.game.window.fillRect(0, offset + (int) (Panel.windowHeight - 40), (int) (Panel.windowWidth), 40); - //g.setColor(Color.red); - //g.fillRect(Game.gamescreen.getWidth() - 250, (int)(Game.gamescreen.getSize().getHeight() - 40 + 15 - Screen.offset), (int) (200 * (Runtime.getRuntime().totalMemory() * 1.0 / Runtime.getRuntime().maxMemory())), 10); - //g.drawRect(Game.gamescreen.getWidth() - 250, (int)(Game.gamescreen.getSize().getHeight() - 40 + 15 - Screen.offset), 200, 10); + Drawing.drawing.setColor(255, 227, 186); - double mx = Game.window.getInterfaceMouseX(); - double my = Game.window.getInterfaceMouseY(); + Drawing.drawing.setFontSize(12); - double mx2 = Game.window.getMouseX(); - double my2 = Game.window.getMouseY(); - if (showMouseTarget) - { - g.setColor(Color.black); - Drawing.window.drawInterfaceOval(g, mx, my, 8, 8); - Drawing.window.drawInterfaceOval(g, mx, my, 4, 4); + Game.game.window.fontRenderer.drawString(2, offset + (int) (Panel.windowHeight - 40 + 6), 0.4, 0.4, "Tanks v0.6.0"); + Game.game.window.fontRenderer.drawString(2, offset + (int) (Panel.windowHeight - 40 + 22), 0.4, 0.4, "FPS: " + lastFPS); + + Game.game.window.fontRenderer.drawString(600, offset + (int) (Panel.windowHeight - 40 + 10), 0.6, 0.6, Game.screen.screenHint); + } - g.setColor(Color.red); - Drawing.window.drawOval(g, mx2, my2, 8, 8); - Drawing.window.drawOval(g, mx2, my2, 4, 4); + /*public void startTimer() + { + //timer.start(); + //new SoundThread().execute(); + }*/ - } + /*@Override + public void paint(Graphics g) + { + //long start = System.nanoTime(); + try + { + draw(); } catch (Exception e) { @@ -312,7 +240,7 @@ public void paint(Graphics g) //long end = System.nanoTime(); //System.out.println("Drawing took: " + (end - start)); - - - } + + + }*/ } \ No newline at end of file diff --git a/src/tanks/Ray.java b/src/tanks/Ray.java index d2bbbebe..56c319da 100755 --- a/src/tanks/Ray.java +++ b/src/tanks/Ray.java @@ -8,6 +8,7 @@ public class Ray { public int size = 10; public int bounces; + public int bouncyBounces = 100; public double posX; public double posY; public double vX; @@ -70,11 +71,13 @@ public Movable getTarget() while (true) { age++; + //Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.ray)); this.posX += this.vX; this.posY += this.vY; boolean collided = false; + boolean bouncy = false; for (int i = 0; i < Game.obstacles.size(); i++) { @@ -97,6 +100,7 @@ public Movable getTarget() { this.posX += horizontalDist - bound; this.vX = -Math.abs(this.vX); + bouncy = o.bouncy; collided = true; bounceX.add(this.posX); bounceY.add(this.posY); @@ -105,6 +109,7 @@ else if (dy <= 0 && dy > 0 - bound && horizontalDist < verticalDist) { this.posY += verticalDist - bound; this.vY = -Math.abs(this.vY); + bouncy = o.bouncy; collided = true; bounceX.add(this.posX); bounceY.add(this.posY); @@ -113,6 +118,7 @@ else if (dx >= 0 && dx < bound && horizontalDist > verticalDist) { this.posX -= horizontalDist - bound; this.vX = Math.abs(this.vX); + bouncy = o.bouncy; collided = true; bounceX.add(this.posX); bounceY.add(this.posY); @@ -121,6 +127,7 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist) { this.posY -= verticalDist - bound; this.vY = Math.abs(this.vY); + bouncy = o.bouncy; collided = true; bounceX.add(this.posX); bounceY.add(this.posY); @@ -129,10 +136,10 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist) } - if (this.posX + this.size/2 > Drawing.sizeX) + if (this.posX + this.size/2 > Drawing.drawing.sizeX) { collided = true; - this.posX = Drawing.sizeX - this.size/2 - (this.posX + this.size/2 - Drawing.sizeX); + this.posX = Drawing.drawing.sizeX - this.size/2 - (this.posX + this.size/2 - Drawing.drawing.sizeX); this.vX = -Math.abs(this.vX); } if (this.posX - this.size/2 < 0) @@ -141,10 +148,10 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist) this.posX = this.size/2 - (this.posX - this.size / 2); this.vX = Math.abs(this.vX); } - if (this.posY + this.size/2 > Drawing.sizeY) + if (this.posY + this.size/2 > Drawing.drawing.sizeY) { collided = true; - this.posY = Drawing.sizeY - this.size/2 - (this.posY + this.size/2 - Drawing.sizeY); + this.posY = Drawing.drawing.sizeY - this.size/2 - (this.posY + this.size/2 - Drawing.drawing.sizeY); this.vY = -Math.abs(this.vY); } if (this.posY - this.size/2 < 0) @@ -153,14 +160,20 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist) this.posY = this.size/2 - (this.posY - this.size / 2); this.vY = Math.abs(this.vY); } + if (collided) { - if (this.bounces <= 0 || this.age <= 1) + if (this.bounces <= 0 || this.bouncyBounces <= 0 || this.age <= 1) { return null; } - this.bounces--; + + if (!bouncy) + this.bounces--; + else + this.bouncyBounces--; } + for (int i = 0; i < Game.movables.size(); i++) { if (Game.movables.get(i) instanceof Tank) @@ -186,7 +199,6 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist) } if (!Game.movables.get(i).equals(tank) || age * speed > Math.sqrt(2) * tank.size / 2 + 10 || skipSelfCheck) { - //Game.effects.add(new Effect(this.posX, this.posY, Effect.EffectType.laser)); this.targetX = this.posX; this.targetY = this.posY; return Game.movables.get(i); @@ -202,7 +214,6 @@ else if (Game.movables.get(i) instanceof Bullet && enableBullet) { if (age * speed > Math.sqrt(2) * tank.size / 2 + 10 || skipSelfCheck) { - //Game.effects.add(new Effect(this.posX, this.posY, Effect.EffectType.laser)); this.targetX = this.posX; this.targetY = this.posY; System.out.println("hi"); @@ -263,7 +274,7 @@ public int getDist() } - if (this.posX + this.size/2 > Drawing.sizeX) + if (this.posX + this.size/2 > Drawing.drawing.sizeX) { return this.age; } @@ -271,7 +282,7 @@ else if (this.posX - this.size/2 < 0) { return this.age; } - else if (this.posY + this.size/2 > Drawing.sizeY) + else if (this.posY + this.size/2 > Drawing.drawing.sizeY) { return this.age; } diff --git a/src/tanks/RegistryTank.java b/src/tanks/RegistryTank.java index ab926535..ef8e4bf6 100755 --- a/src/tanks/RegistryTank.java +++ b/src/tanks/RegistryTank.java @@ -139,7 +139,7 @@ public static void initRegistry(String homedir) } - static class TankEntry + public static class TankEntry { public final Class tank; public final String name; diff --git a/src/tanks/Screen.java b/src/tanks/Screen.java index 39d00ef1..1fd5ec15 100755 --- a/src/tanks/Screen.java +++ b/src/tanks/Screen.java @@ -1,39 +1,43 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; - public abstract class Screen { + public String screenHint = ""; + public abstract void update(); - public abstract void draw(Graphics g); + public abstract void draw(); + + public void drawDefaultBackground() + { + this.drawDefaultBackground(1); + } - public void drawDefaultBackground(Graphics g) + public void drawDefaultBackground(double size) { if (!(Game.screen instanceof ScreenInterlevel)) Panel.darkness = Math.max(Panel.darkness - Panel.frameFrequency * 3, 0); - g.setColor(Level.currentColor); - Drawing.window.fillRect(g, Drawing.sizeX / 2, Drawing.sizeY / 2, Drawing.sizeX, Drawing.sizeY); + Drawing.drawing.setColor(Level.currentColorR, Level.currentColorG, Level.currentColorB, 255.0 * size); + Drawing.drawing.fillRect(Drawing.drawing.sizeX / 2, Drawing.drawing.sizeY / 2, Drawing.drawing.sizeX, Drawing.drawing.sizeY); if (Game.fancyGraphics) { for (int i = 0; i < Game.currentSizeX; i++) { for (int j = 0; j < Game.currentSizeY; j++) - { - g.setColor(Game.tiles[i][j]); - Drawing.window.fillRect(g, + { + Drawing.drawing.setColor(Game.tilesR[i][j], Game.tilesG[i][j], Game.tilesB[i][j]); + Drawing.drawing.fillRect( (i + 0.5) / Game.bgResMultiplier * Obstacle.obstacle_size, (j + 0.5) / Game.bgResMultiplier * Obstacle.obstacle_size, - Obstacle.obstacle_size / Game.bgResMultiplier, - Obstacle.obstacle_size / Game.bgResMultiplier); + Obstacle.obstacle_size * size / Game.bgResMultiplier, + Obstacle.obstacle_size * size / Game.bgResMultiplier); } } - g.setColor(new Color(0, 0, 0, Math.max(0, (int) Panel.darkness))); - Drawing.window.fillBackgroundRect(g, Drawing.sizeX / 2, Drawing.sizeY / 2, Drawing.sizeX, Drawing.sizeY); + Drawing.drawing.setColor(0, 0, 0, Math.max(0, (int) Panel.darkness)); + Drawing.drawing.fillBackgroundRect(Drawing.drawing.sizeX / 2, Drawing.drawing.sizeY / 2, Drawing.drawing.sizeX, Drawing.drawing.sizeY); } } } diff --git a/src/tanks/ScreenCrashed.java b/src/tanks/ScreenCrashed.java index 6fec21d9..ec05eb08 100755 --- a/src/tanks/ScreenCrashed.java +++ b/src/tanks/ScreenCrashed.java @@ -1,12 +1,8 @@ package tanks; -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics; - public class ScreenCrashed extends Screen { - Button exit = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY - 100, 350, 40, "Exit the game", new Runnable() + Button exit = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY - 100, 350, 40, "Exit the game", new Runnable() { @Override public void run() @@ -16,7 +12,7 @@ public void run() } ); - Button quit = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY - 160, 350, 40, "Return to title", new Runnable() + Button quit = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY - 160, 350, 40, "Return to title", new Runnable() { @Override public void run() @@ -34,31 +30,31 @@ public void update() } @Override - public void draw(Graphics g) + public void draw() { - g.setColor(Color.blue); - Drawing drawing = Drawing.window; - drawing.fillInterfaceRect(g, Drawing.sizeX / 2, Drawing.sizeY / 2, Drawing.sizeX * 1.2, Drawing.sizeY * 1.2); + Drawing drawing = Drawing.drawing; + drawing.setColor(0, 0, 255); + drawing.fillInterfaceRect(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2, Drawing.drawing.interfaceSizeX * 1.2, Drawing.drawing.interfaceSizeY * 1.2); - g.setColor(Color.white); - Drawing.setInterfaceFontSize(g, 100); - drawing.drawInterfaceText(g, 100, 100, ":("); + drawing.setColor(255, 255, 255); + drawing.setInterfaceFontSize(100); + drawing.drawInterfaceText(100, 100, ":("); - Drawing.setInterfaceFontSize(g, 48); - drawing.drawInterfaceText(g, Drawing.interfaceSizeX / 2, 100, "Oh noes! Tanks ran into a problem!"); + drawing.setInterfaceFontSize(48); + drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, 100, "Oh noes! Tanks ran into a problem!"); - g.setFont(g.getFont().deriveFont(Font.BOLD, (float) (24 * Drawing.window.getScale()))); - drawing.drawInterfaceText(g, Drawing.interfaceSizeX / 2, 200, Game.crashMessage); - drawing.drawInterfaceText(g, Drawing.interfaceSizeX / 2, 290, "Check the log file for more information: "); - drawing.drawInterfaceText(g, Drawing.interfaceSizeX / 2, 320, Game.homedir.replace("\\", "/") + Game.logPath); + drawing.setInterfaceFontSize(24); + drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, 200, Game.crashMessage); + drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, 290, "Check the log file for more information: "); + drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, 320, Game.homedir.replace("\\", "/") + Game.logPath); - drawing.drawInterfaceText(g, Drawing.interfaceSizeX / 2, 420, "You may return to the game if you wish,"); - drawing.drawInterfaceText(g, Drawing.interfaceSizeX / 2, 450, "but be warned that things may become unstable."); - drawing.drawInterfaceText(g, Drawing.interfaceSizeX / 2, 480, "If you see this screen again, restart the game."); - drawing.drawInterfaceText(g, Drawing.interfaceSizeX / 2, 510, "Also, you may want to report this crash!"); + drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, 420, "You may return to the game if you wish,"); + drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, 450, "but be warned that things may become unstable."); + drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, 480, "If you see this screen again, restart the game."); + drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, 510, "Also, you may want to report this crash!"); - this.quit.draw(g); - this.exit.draw(g); + this.quit.draw(); + this.exit.draw(); return; } diff --git a/src/tanks/ScreenCrusades.java b/src/tanks/ScreenCrusades.java index 9215c63a..b301850a 100755 --- a/src/tanks/ScreenCrusades.java +++ b/src/tanks/ScreenCrusades.java @@ -1,6 +1,5 @@ package tanks; -import java.awt.Graphics; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; @@ -20,7 +19,7 @@ public class ScreenCrusades extends Screen int yoffset = -150; int page = 0; - Button quit = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 + 300, 350, 40, "Back", new Runnable() + Button quit = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 300, 350, 40, "Back", new Runnable() { @Override public void run() @@ -30,7 +29,7 @@ public void run() } ); - Button newLevel = new Button(Drawing.interfaceSizeX / 2 + 190, Drawing.interfaceSizeY / 2 + 300, 350, 40, "New level", new Runnable() + Button newLevel = new Button(Drawing.drawing.interfaceSizeX / 2 + 190, Drawing.drawing.interfaceSizeY / 2 + 300, 350, 40, "New level", new Runnable() { @Override public void run() @@ -45,7 +44,7 @@ public void run() } ); - Button next = new Button(Drawing.interfaceSizeX / 2 + 190, Drawing.interfaceSizeY / 2 + 240, 350, 40, "Next page", new Runnable() + Button next = new Button(Drawing.drawing.interfaceSizeX / 2 + 190, Drawing.drawing.interfaceSizeY / 2 + 240, 350, 40, "Next page", new Runnable() { @Override public void run() @@ -55,7 +54,7 @@ public void run() } ); - Button previous = new Button(Drawing.interfaceSizeX / 2 - 190, Drawing.interfaceSizeY / 2 + 240, 350, 40, "Previous page", new Runnable() + Button previous = new Button(Drawing.drawing.interfaceSizeX / 2 - 190, Drawing.drawing.interfaceSizeY / 2 + 240, 350, 40, "Previous page", new Runnable() { @Override public void run() @@ -172,14 +171,14 @@ public void run() if (page * rows * 3 + rows * 2 < buttons.size()) offset = -380; - buttons.get(i).posY = Drawing.interfaceSizeY / 2 + yoffset + (i % rows) * 60; + buttons.get(i).posY = Drawing.drawing.interfaceSizeY / 2 + yoffset + (i % rows) * 60; if (i / rows % 3 == 0) - buttons.get(i).posX = Drawing.interfaceSizeX / 2 + offset; + buttons.get(i).posX = Drawing.drawing.interfaceSizeX / 2 + offset; else if (i / rows % 3 == 1) - buttons.get(i).posX = Drawing.interfaceSizeX / 2 + offset + 380; + buttons.get(i).posX = Drawing.drawing.interfaceSizeX / 2 + offset + 380; else - buttons.get(i).posX = Drawing.interfaceSizeX / 2 + offset + 380 * 2; + buttons.get(i).posX = Drawing.drawing.interfaceSizeX / 2 + offset + 380 * 2; } @@ -204,25 +203,25 @@ public void update() } @Override - public void draw(Graphics g) + public void draw() { - this.drawDefaultBackground(g); + this.drawDefaultBackground(); for (int i = page * rows * 3; i < Math.min(page * rows * 3 + rows * 3, buttons.size()); i++) { - buttons.get(i).draw(g); + buttons.get(i).draw(); } - quit.draw(g); + quit.draw(); //newLevel.draw(g); - Drawing.window.drawInterfaceText(g, Drawing.sizeX / 2, Drawing.sizeY / 2 - 210, "Crusades"); + Drawing.drawing.drawInterfaceText(Drawing.drawing.sizeX / 2, Drawing.drawing.sizeY / 2 - 210, "Crusades"); if (page > 0) - previous.draw(g); + previous.draw(); if (buttons.size() > (1 + page) * rows * 3) - next.draw(g); + next.draw(); } diff --git a/src/tanks/ScreenFailedToLoadLevel.java b/src/tanks/ScreenFailedToLoadLevel.java new file mode 100755 index 00000000..2ff62c8d --- /dev/null +++ b/src/tanks/ScreenFailedToLoadLevel.java @@ -0,0 +1,46 @@ +package tanks; + +public class ScreenFailedToLoadLevel extends Screen +{ + String lvl; + public ScreenFailedToLoadLevel(String lvl) + { + this.lvl = lvl; + Game.currentSizeX = 28; + Game.currentSizeY = 18; + Game.resetTiles(); + } + + Button quit = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 300, 350, 40, "Back", new Runnable() + { + @Override + public void run() + { + Game.screen = new ScreenSavedLevels(); + } + } + ); + + @Override + public void update() + { + quit.update(); + } + + @Override + public void draw() + { + this.drawDefaultBackground(); + quit.draw(); + + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 150, "Tanks failed to load the level!"); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 90, "This could be caused by a glitch in the editor,"); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 60, "or by corruption of the level file."); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2, "If you manually modified the level file, please undo your changes."); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 30, "If this is not the case, please report the error!"); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 90, "Check the log file for more information: "); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 120, Game.homedir.replace("\\", "/") + Game.logPath); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 150, "Please include the level file if reporting; it can be found at:"); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 180, lvl); + } +} diff --git a/src/tanks/ScreenGame.java b/src/tanks/ScreenGame.java index 5026006b..b8acab83 100755 --- a/src/tanks/ScreenGame.java +++ b/src/tanks/ScreenGame.java @@ -1,11 +1,10 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.event.KeyEvent; import java.io.File; import java.util.ArrayList; +import org.lwjgl.glfw.GLFW; + import tanks.tank.Tank; public class ScreenGame extends Screen @@ -28,7 +27,7 @@ public class ScreenGame extends Screen public ArrayList shop = new ArrayList(); public boolean screenshotMode = false; - Button play = new Button(Drawing.interfaceSizeX-200, Drawing.interfaceSizeY-50, 350, 40, "Play", new Runnable() + Button play = new Button(Drawing.drawing.interfaceSizeX-200, Drawing.drawing.interfaceSizeY-50, 350, 40, "Play", new Runnable() { @Override public void run() @@ -39,7 +38,7 @@ public void run() } ); - Button enterShop = new Button(Drawing.interfaceSizeX-200, Drawing.interfaceSizeY-110, 350, 40, "Shop", new Runnable() + Button enterShop = new Button(Drawing.drawing.interfaceSizeX-200, Drawing.drawing.interfaceSizeY-110, 350, 40, "Shop", new Runnable() { @Override public void run() @@ -50,7 +49,7 @@ public void run() } ); - Button resume = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 60, 350, 40, "Continue playing", new Runnable() + Button resume = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 60, 350, 40, "Continue playing", new Runnable() { @Override public void run() @@ -61,7 +60,7 @@ public void run() } ); - Button resumeCrusade = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 30, 350, 40, "Continue playing", new Runnable() + Button resumeCrusade = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 30, 350, 40, "Continue playing", new Runnable() { @Override public void run() @@ -73,7 +72,7 @@ public void run() ); - Button newLevel = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2, 350, 40, "Generate a new level", new Runnable() + Button newLevel = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2, 350, 40, "Generate a new level", new Runnable() { @Override public void run() @@ -86,7 +85,7 @@ public void run() } ); - Button edit = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2, 350, 40, "Edit the level", new Runnable() + Button edit = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2, 350, 40, "Edit the level", new Runnable() { @Override public void run() @@ -99,7 +98,7 @@ public void run() } ); - Button quit = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 + 60, 350, 40, "Quit to title", new Runnable() + Button quit = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 60, 350, 40, "Quit to title", new Runnable() { @Override public void run() @@ -109,7 +108,7 @@ public void run() } ); - Button quitCrusade = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 + 30, 350, 40, "Quit to title", new Runnable() + Button quitCrusade = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 30, 350, 40, "Quit to title", new Runnable() { @Override public void run() @@ -121,7 +120,7 @@ public void run() } , "Note! You will lose a life for quitting---in the middle of a level------You will be able to return to the crusade---through the crusade button on---the play screen."); - Button quitCrusadeFinalLife = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 + 30, 350, 40, "Quit to title", new Runnable() + Button quitCrusadeFinalLife = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 30, 350, 40, "Quit to title", new Runnable() { @Override public void run() @@ -133,7 +132,7 @@ public void run() } , "Note! You will lose a life for quitting---in the middle of a level------Since you do not have any other lives left,---your progress will be lost!"); - Button exitShop = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 + 300, 350, 40, "Exit shop", new Runnable() + Button exitShop = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 300, 350, 40, "Exit shop", new Runnable() { @Override public void run() @@ -143,7 +142,7 @@ public void run() } ); - Button next = new Button(Drawing.interfaceSizeX / 2 + 190, Drawing.interfaceSizeY / 2 + 240, 350, 40, "Next page", new Runnable() + Button next = new Button(Drawing.drawing.interfaceSizeX / 2 + 190, Drawing.drawing.interfaceSizeY / 2 + 240, 350, 40, "Next page", new Runnable() { @Override public void run() @@ -153,7 +152,7 @@ public void run() } ); - Button previous = new Button(Drawing.interfaceSizeX / 2 - 190, Drawing.interfaceSizeY / 2 + 240, 350, 40, "Previous page", new Runnable() + Button previous = new Button(Drawing.drawing.interfaceSizeX / 2 - 190, Drawing.drawing.interfaceSizeY / 2 + 240, 350, 40, "Previous page", new Runnable() { @Override public void run() @@ -221,14 +220,14 @@ public void run() if (page * rows * 3 + rows * 2 < shopItemButtons.size()) offset = -380; - shopItemButtons.get(i).posY = Drawing.interfaceSizeY / 2 + yoffset + (i % rows) * 60; + shopItemButtons.get(i).posY = Drawing.drawing.interfaceSizeY / 2 + yoffset + (i % rows) * 60; if (i / rows % 3 == 0) - shopItemButtons.get(i).posX = Drawing.interfaceSizeX / 2 + offset; + shopItemButtons.get(i).posX = Drawing.drawing.interfaceSizeX / 2 + offset; else if (i / rows % 3 == 1) - shopItemButtons.get(i).posX = Drawing.interfaceSizeX / 2 + offset + 380; + shopItemButtons.get(i).posX = Drawing.drawing.interfaceSizeX / 2 + offset + 380; else - shopItemButtons.get(i).posX = Drawing.interfaceSizeX / 2 + offset + 380 * 2; + shopItemButtons.get(i).posX = Drawing.drawing.interfaceSizeX / 2 + offset + 380 * 2; } } @@ -237,7 +236,7 @@ public void update() { Panel.panel.hotbar.update(); - if (InputKeyboard.keys.contains(KeyEvent.VK_ESCAPE)) + if (Game.game.window.validPressedKeys.contains(GLFW.GLFW_KEY_ESCAPE)) { if (!Panel.pausePressed) { @@ -252,16 +251,16 @@ public void update() else Panel.pausePressed = false; - if (InputKeyboard.validKeys.contains(KeyEvent.VK_F1)) + if (Game.game.window.validPressedKeys.contains(GLFW.GLFW_KEY_F1)) { this.screenshotMode = !this.screenshotMode; - InputKeyboard.validKeys.remove((Integer)KeyEvent.VK_F1); + Game.game.window.validPressedKeys.remove((Integer)GLFW.GLFW_KEY_F1); } - if (InputKeyboard.validKeys.contains(KeyEvent.VK_I)) + if (Game.game.window.validPressedKeys.contains(GLFW.GLFW_KEY_I)) { - Drawing.movingCamera = !Drawing.movingCamera ; - InputKeyboard.validKeys.remove((Integer)KeyEvent.VK_I); + Drawing.drawing.movingCamera = !Drawing.drawing.movingCamera; + Game.game.window.validPressedKeys.remove((Integer)GLFW.GLFW_KEY_I); } if (paused) @@ -349,6 +348,14 @@ else if (!aliveTeams.contains(m.team)) } } + for (int i = 0; i < Game.obstacles.size(); i++) + { + Obstacle o = Game.obstacles.get(i); + if (o.update) + o.update(); + } + + for (int i = 0; i < Game.effects.size(); i++) { Game.effects.get(i).update(); @@ -447,64 +454,63 @@ else if (!aliveTeams.contains(m.team)) } @Override - public void draw(Graphics g) + public void draw() { - this.drawDefaultBackground(g); + this.drawDefaultBackground(); for (int i = 0; i < Game.obstacles.size(); i++) { Obstacle o = Game.obstacles.get(i); if (o.drawBelow) - o.draw(g); + o.draw(); } for (int i = 0; i < Game.belowEffects.size(); i++) - Game.belowEffects.get(i).draw(g); + Game.belowEffects.get(i).draw(); for (int i = 0; i < Game.movables.size(); i++) { Movable m = Game.movables.get(i); if (m.drawBelow) - m.draw(g); + m.draw(); } for (int i = 0; i < Game.movables.size(); i++) { Movable m = Game.movables.get(i); - if (!m.drawBelow && ! m.drawAbove) - m.draw(g); - } - - for (int i = 0; i < Game.obstacles.size(); i++) - { - Obstacle o = Game.obstacles.get(i); - if (!o.drawBelow) - o.draw(g); + if (!m.drawBelow && !m.drawAbove) + m.draw(); } for (int i = 0; i < Game.movables.size(); i++) { Movable m = Game.movables.get(i); if (m.drawAbove) - m.draw(g); + m.draw(); } for (int i = 0; i < Game.effects.size(); i++) - ((Effect)Game.effects.get(i)).draw(g); + ((Effect)Game.effects.get(i)).draw(); + for (int i = 0; i < Game.obstacles.size(); i++) + { + Obstacle o = Game.obstacles.get(i); + if (!o.drawBelow) + o.draw(); + } if (!playing) { if (Crusade.crusadeMode) { - g.setColor(new Color(0, 0, 0, 127)); - Drawing.setFontSize(g, 100); - Drawing.window.drawInterfaceText(g, Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2, "Battle " + (Crusade.currentCrusade.currentLevel + 1)); + Drawing.drawing.setColor(0, 0, 0, 127); + Drawing.drawing.setFontSize(100); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2, "Battle " + (Crusade.currentCrusade.currentLevel + 1)); } if (shopScreen) { - this.exitShop.draw(g); + this.exitShop.draw(); if (shopItemButtons.size() > (1 + shopPage) * rows * 3) next.update(); @@ -513,57 +519,57 @@ public void draw(Graphics g) this.previous.update(); for (int i = 0; i < this.shopItemButtons.size(); i++) - this.shopItemButtons.get(i).draw(g); + this.shopItemButtons.get(i).draw(); } else { if (!this.shop.isEmpty()) - enterShop.draw(g); + enterShop.draw(); - play.draw(g); + play.draw(); if (Game.autostart && !cancelCountdown) { - g.setColor(Color.gray); - Drawing.window.fillInterfaceRect(g, Drawing.interfaceSizeX-200, Drawing.interfaceSizeY-27.5, 350, 5); - g.setColor(Color.orange); - Drawing.window.fillInterfaceProgressRect(g, Drawing.interfaceSizeX-200, Drawing.interfaceSizeY-27.5, 350, 5, Game.startTime / 400); + Drawing.drawing.setColor(127, 127, 127); + Drawing.drawing.fillInterfaceRect(Drawing.drawing.interfaceSizeX - 200, Drawing.drawing.interfaceSizeY - 35, 320, 3); + Drawing.drawing.setColor(255, 127, 0); + Drawing.drawing.fillInterfaceProgressRect(Drawing.drawing.interfaceSizeX - 200, Drawing.drawing.interfaceSizeY - 35, 320, 3, Game.startTime / 400); } } } - Panel.panel.hotbar.draw(g); + Panel.panel.hotbar.draw(); if (paused && !screenshotMode) { - g.setColor(new Color(127, 178, 228, 64)); - g.fillRect(0, 0, (int) (Game.window.getSize().getWidth()) + 1, (int) (Game.window.getSize().getHeight()) + 1); + Drawing.drawing.setColor(127, 178, 228, 64); + Game.game.window.fillRect(0, 0, (int) (Game.game.window.absoluteWidth) + 1, (int) (Game.game.window.absoluteHeight) + 1); if (name == null) { if (!Crusade.crusadeMode) - newLevel.draw(g); + newLevel.draw(); } else - edit.draw(g); + edit.draw(); if (!Crusade.crusadeMode) - quit.draw(g); + quit.draw(); else { if (Crusade.currentCrusade.remainingLives > 1) - quitCrusade.draw(g); + quitCrusade.draw(); else - quitCrusadeFinalLife.draw(g); + quitCrusadeFinalLife.draw(); } if (!Crusade.crusadeMode) - resume.draw(g); + resume.draw(); else - resumeCrusade.draw(g); + resumeCrusade.draw(); - g.setColor(Color.black); - Drawing.window.drawInterfaceText(g, Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 150, "Game paused"); + Drawing.drawing.setColor(0, 0, 0); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 150, "Game paused"); } } diff --git a/src/tanks/ScreenInterlevel.java b/src/tanks/ScreenInterlevel.java index 2a7b21e1..614653c6 100755 --- a/src/tanks/ScreenInterlevel.java +++ b/src/tanks/ScreenInterlevel.java @@ -1,7 +1,5 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; import java.util.ArrayList; public class ScreenInterlevel extends Screen @@ -9,7 +7,7 @@ public class ScreenInterlevel extends Screen ArrayList fireworks = new ArrayList(); ArrayList removeFireworks = new ArrayList(); - Button replay = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 30, 350, 40, "Replay the level", new Runnable() + Button replay = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 30, 350, 40, "Replay the level", new Runnable() { @Override public void run() @@ -21,14 +19,26 @@ public void run() } ); - Button replayCrusadeWin = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 30, 350, 40, "Replay the level", new Runnable() + Button replayCrusade = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 30, 350, 40, "Try again", new Runnable() { @Override public void run() { Level level = new Level(Game.currentLevel); level.loadLevel(); - Game.screen = new ScreenGame(); + Game.screen = new ScreenGame(Crusade.currentCrusade.getShop()); + } + } + ); + + Button replayCrusadeWin = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 30, 350, 40, "Replay the level", new Runnable() + { + @Override + public void run() + { + Level level = new Level(Game.currentLevel); + level.loadLevel(); + Game.screen = new ScreenGame(Crusade.currentCrusade.getShop()); Crusade.currentCrusade.replay = true; } } @@ -37,7 +47,7 @@ public void run() + "However, you can still earn coins!---" + "You will still lose a life if you die."); - Button save = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 + 30, 350, 40, "Save this level", new Runnable() + Button save = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 30, 350, 40, "Save this level", new Runnable() { @Override public void run() @@ -58,7 +68,7 @@ public void run() } ); - Button newLevel = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 90, 350, 40, "Generate a new level", new Runnable() + Button newLevel = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 90, 350, 40, "Generate a new level", new Runnable() { @Override public void run() @@ -69,7 +79,7 @@ public void run() } ); - Button nextLevel = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 90, 350, 40, "Next level", new Runnable() + Button nextLevel = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 90, 350, 40, "Next level", new Runnable() { @Override public void run() @@ -82,7 +92,7 @@ public void run() } ); - Button quit = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 + 90, 350, 40, "Quit to title", new Runnable() + Button quit = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 90, 350, 40, "Quit to title", new Runnable() { @Override public void run() @@ -94,7 +104,7 @@ public void run() } ); - Button quitCrusade = new Button(Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 + 90, 350, 40, "Quit to title", new Runnable() + Button quitCrusade = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 90, 350, 40, "Quit to title", new Runnable() { @Override public void run() @@ -123,7 +133,7 @@ public void update() replayCrusadeWin.update(); } else - replay.update(); + replayCrusade.update(); quitCrusade.update(); } @@ -150,10 +160,10 @@ public ScreenInterlevel() if (Panel.win) { - Drawing.playSound("resources/win.wav"); + Drawing.drawing.playSound("resources/win.wav"); for (int i = 0; i < 5; i++) { - Firework f = new Firework(Firework.FireworkType.rocket, (Math.random() * 0.6 + 0.2) * Drawing.sizeX, Drawing.sizeY, fireworks, removeFireworks); + Firework f = new Firework(Firework.FireworkType.rocket, (Math.random() * 0.6 + 0.2) * Drawing.drawing.sizeX, Drawing.drawing.sizeY, fireworks, removeFireworks); f.setRandomColor(); f.vY = - Math.random() * 3 - 6; f.vX = Math.random() * 5 - 2.5; @@ -161,20 +171,20 @@ public ScreenInterlevel() } } else - Drawing.playSound("resources/lose.wav"); + Drawing.drawing.playSound("resources/lose.wav"); } @Override - public void draw(Graphics g) + public void draw() { - this.drawDefaultBackground(g); + this.drawDefaultBackground(); if (Panel.win && Game.fancyGraphics) { if (Math.random() < 0.01) { - Firework f = new Firework(Firework.FireworkType.rocket, (Math.random() * 0.6 + 0.2) * Drawing.sizeX, Drawing.sizeY, fireworks, removeFireworks); + Firework f = new Firework(Firework.FireworkType.rocket, (Math.random() * 0.6 + 0.2) * Drawing.drawing.sizeX, Drawing.drawing.sizeY, fireworks, removeFireworks); f.setRandomColor(); f.vY = - Math.random() * 3 - 6; f.vX = Math.random() * 5 - 2.5; @@ -183,7 +193,7 @@ public void draw(Graphics g) for (int i = 0; i < fireworks.size(); i++) { - fireworks.get(i).drawUpdate(g); + fireworks.get(i).drawUpdate(); } for (int i = 0; i < removeFireworks.size(); i++) @@ -197,10 +207,10 @@ public void draw(Graphics g) if (Crusade.currentCrusade.lose || Crusade.currentCrusade.win) skip = true; - save.draw(g); + save.draw(); if (!Crusade.crusadeMode || skip) - quit.draw(g); + quit.draw(); if (!skip) { @@ -208,46 +218,44 @@ public void draw(Graphics g) { if (Panel.win) { - nextLevel.draw(g); - replayCrusadeWin.draw(g); + nextLevel.draw(); + replayCrusadeWin.draw(); } else - { - replay.draw(g); - } + replayCrusade.draw(); - quitCrusade.draw(g); + quitCrusade.draw(); } else { - replay.draw(g); - newLevel.draw(g); + replay.draw(); + newLevel.draw(); } } if (Panel.win && Game.fancyGraphics) - g.setColor(Color.white); + Drawing.drawing.setColor(255, 255, 255); else - g.setColor(Color.black); + Drawing.drawing.setColor(0, 0, 0); - Drawing.setFontSize(g, 24); + Drawing.drawing.setFontSize(24); if (Crusade.crusadeMode) { if (Crusade.currentCrusade.win) - Drawing.window.drawInterfaceText(g, Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 190, "You finished the crusade!"); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 190, "You finished the crusade!"); else if (Crusade.currentCrusade.lose) - Drawing.window.drawInterfaceText(g, Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 190, "Game over!"); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 190, "Game over!"); else - Drawing.window.drawInterfaceText(g, Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 190, Panel.winlose); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 190, Panel.winlose); } else - Drawing.window.drawInterfaceText(g, Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 150, Panel.winlose); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 150, Panel.winlose); if (Crusade.crusadeMode) - Drawing.window.drawInterfaceText(g, Drawing.interfaceSizeX / 2, Drawing.interfaceSizeY / 2 - 150, "Lives remaining: " + Crusade.currentCrusade.remainingLives); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 150, "Lives remaining: " + Crusade.currentCrusade.remainingLives); if (Panel.win && Game.fancyGraphics) Panel.darkness = Math.min(Panel.darkness + Panel.frameFrequency * 1.5, 191); diff --git a/src/tanks/ScreenLevelBuilder.java b/src/tanks/ScreenLevelBuilder.java index b3597be9..329565b8 100755 --- a/src/tanks/ScreenLevelBuilder.java +++ b/src/tanks/ScreenLevelBuilder.java @@ -1,14 +1,13 @@ package tanks; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayList; +import org.lwjgl.glfw.GLFW; + import tanks.tank.Tank; import tanks.tank.TankPlayer; @@ -24,8 +23,8 @@ enum Placeable {enemyTank, playerTank, obstacle} boolean reloadNewLevel = true; - Tank mouseTank = Game.registryTank.getEntry(tankNum).getTank(0, 0, 0); + int mouseTankOrientation = 0; Obstacle mouseObstacle = Game.registryObstacle.getEntry(obstacleNum).getObstacle(0, 0); boolean paused = true; boolean optionsMenu = false; @@ -34,15 +33,37 @@ enum Placeable {enemyTank, playerTank, obstacle} boolean teamsMenu = false; boolean editTeamMenu = false; boolean teamColorMenu = false; + + boolean objectMenu; + boolean obstacleMenu; + boolean tankMenu; + boolean selectTeamMenu; + boolean rotateTankMenu; + + double clickCooldown = 0; + Team selectedTeam; - int rows = 6; - int page = 0; + int teamPageRows = 6; + int teamPage = 0; + + String teamSelectTitle = ""; + + int tankButtonPage = 0; + int obstacleButtonPage = 0; public boolean editable = true; ArrayList teams = new ArrayList(); - ArrayList